Skip to content

Commit 055daaf

Browse files
authored
Merge pull request kubernetes#85139 from ahg-g/ahg-snapshot2
Updated NewSnapshot interface to accept a NodeInfoMap
2 parents 9d84bd6 + 902cf48 commit 055daaf

35 files changed

+150
-162
lines changed

pkg/scheduler/algorithm/predicates/metadata_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ func TestPredicateMetadata_AddRemovePod(t *testing.T) {
355355
allPodLister := fakelisters.PodLister(append(test.existingPods, test.addedPod))
356356
// getMeta creates predicate meta data given the list of pods.
357357
getMeta := func(pods []*v1.Pod) (*predicateMetadata, map[string]*schedulernodeinfo.NodeInfo) {
358-
s := nodeinfosnapshot.NewSnapshot(pods, test.nodes)
358+
s := nodeinfosnapshot.NewSnapshot(nodeinfosnapshot.CreateNodeInfoMap(pods, test.nodes))
359359
_, precompute := NewServiceAffinityPredicate(s.NodeInfos(), s.Pods(), fakelisters.ServiceLister(test.services), nil)
360360
RegisterPredicateMetadataProducer("ServiceAffinityMetaProducer", precompute)
361361
factory := &MetadataProducerFactory{}
@@ -786,7 +786,7 @@ func TestGetTPMapMatchingIncomingAffinityAntiAffinity(t *testing.T) {
786786
}
787787
for _, tt := range tests {
788788
t.Run(tt.name, func(t *testing.T) {
789-
s := nodeinfosnapshot.NewSnapshot(tt.existingPods, tt.nodes)
789+
s := nodeinfosnapshot.NewSnapshot(nodeinfosnapshot.CreateNodeInfoMap(tt.existingPods, tt.nodes))
790790
l, _ := s.NodeInfos().List()
791791
gotAffinityPodsMaps, gotAntiAffinityPodsMaps, err := getTPMapMatchingIncomingAffinityAntiAffinity(tt.pod, l)
792792
if (err != nil) != tt.wantErr {
@@ -1182,7 +1182,7 @@ func TestGetTPMapMatchingSpreadConstraints(t *testing.T) {
11821182
}
11831183
for _, tt := range tests {
11841184
t.Run(tt.name, func(t *testing.T) {
1185-
s := nodeinfosnapshot.NewSnapshot(tt.existingPods, tt.nodes)
1185+
s := nodeinfosnapshot.NewSnapshot(nodeinfosnapshot.CreateNodeInfoMap(tt.existingPods, tt.nodes))
11861186
l, _ := s.NodeInfos().List()
11871187
got, _ := getEvenPodsSpreadMetadata(tt.pod, l)
11881188
got.sortCriticalPaths()
@@ -1450,7 +1450,7 @@ func TestPodSpreadCache_addPod(t *testing.T) {
14501450
}
14511451
for _, tt := range tests {
14521452
t.Run(tt.name, func(t *testing.T) {
1453-
s := nodeinfosnapshot.NewSnapshot(tt.existingPods, tt.nodes)
1453+
s := nodeinfosnapshot.NewSnapshot(nodeinfosnapshot.CreateNodeInfoMap(tt.existingPods, tt.nodes))
14541454
l, _ := s.NodeInfos().List()
14551455
evenPodsSpreadMetadata, _ := getEvenPodsSpreadMetadata(tt.preemptor, l)
14561456
evenPodsSpreadMetadata.addPod(tt.addedPod, tt.preemptor, tt.nodes[tt.nodeIdx])
@@ -1628,7 +1628,7 @@ func TestPodSpreadCache_removePod(t *testing.T) {
16281628
}
16291629
for _, tt := range tests {
16301630
t.Run(tt.name, func(t *testing.T) {
1631-
s := nodeinfosnapshot.NewSnapshot(tt.existingPods, tt.nodes)
1631+
s := nodeinfosnapshot.NewSnapshot(nodeinfosnapshot.CreateNodeInfoMap(tt.existingPods, tt.nodes))
16321632
l, _ := s.NodeInfos().List()
16331633
evenPodsSpreadMetadata, _ := getEvenPodsSpreadMetadata(tt.preemptor, l)
16341634

@@ -1687,7 +1687,7 @@ func BenchmarkTestGetTPMapMatchingSpreadConstraints(b *testing.B) {
16871687
for _, tt := range tests {
16881688
b.Run(tt.name, func(b *testing.B) {
16891689
existingPods, allNodes, _ := st.MakeNodesAndPodsForEvenPodsSpread(tt.pod.Labels, tt.existingPodsNum, tt.allNodesNum, tt.filteredNodesNum)
1690-
s := nodeinfosnapshot.NewSnapshot(existingPods, allNodes)
1690+
s := nodeinfosnapshot.NewSnapshot(nodeinfosnapshot.CreateNodeInfoMap(existingPods, allNodes))
16911691
l, _ := s.NodeInfos().List()
16921692
b.ResetTimer()
16931693
for i := 0; i < b.N; i++ {

pkg/scheduler/algorithm/predicates/predicates_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,7 +1860,7 @@ func TestServiceAffinity(t *testing.T) {
18601860
testIt := func(skipPrecompute bool) {
18611861
t.Run(fmt.Sprintf("%v/skipPrecompute/%v", test.name, skipPrecompute), func(t *testing.T) {
18621862
nodes := []*v1.Node{&node1, &node2, &node3, &node4, &node5}
1863-
s := nodeinfosnapshot.NewSnapshot(test.pods, nodes)
1863+
s := nodeinfosnapshot.NewSnapshot(nodeinfosnapshot.CreateNodeInfoMap(test.pods, nodes))
18641864

18651865
// Reimplementing the logic that the scheduler implements: Any time it makes a predicate, it registers any precomputations.
18661866
predicate, precompute := NewServiceAffinityPredicate(s.NodeInfos(), s.Pods(), fakelisters.ServiceLister(test.services), test.labels)
@@ -2929,7 +2929,7 @@ func TestInterPodAffinity(t *testing.T) {
29292929

29302930
for _, test := range tests {
29312931
t.Run(test.name, func(t *testing.T) {
2932-
s := nodeinfosnapshot.NewSnapshot(test.pods, []*v1.Node{test.node})
2932+
s := nodeinfosnapshot.NewSnapshot(nodeinfosnapshot.CreateNodeInfoMap(test.pods, []*v1.Node{test.node}))
29332933

29342934
fit := PodAffinityChecker{
29352935
nodeInfoLister: s.NodeInfos(),
@@ -4025,7 +4025,7 @@ func TestInterPodAffinityWithMultipleNodes(t *testing.T) {
40254025

40264026
for indexTest, test := range tests {
40274027
t.Run(test.name, func(t *testing.T) {
4028-
snapshot := nodeinfosnapshot.NewSnapshot(test.pods, test.nodes)
4028+
snapshot := nodeinfosnapshot.NewSnapshot(nodeinfosnapshot.CreateNodeInfoMap(test.pods, test.nodes))
40294029
for indexNode, node := range test.nodes {
40304030
testFit := PodAffinityChecker{
40314031
nodeInfoLister: snapshot.NodeInfos(),
@@ -4044,7 +4044,7 @@ func TestInterPodAffinityWithMultipleNodes(t *testing.T) {
40444044
}
40454045
affinity := test.pod.Spec.Affinity
40464046
if affinity != nil && affinity.NodeAffinity != nil {
4047-
s := nodeinfosnapshot.NewSnapshot(nil, []*v1.Node{node})
4047+
s := nodeinfosnapshot.NewSnapshot(nodeinfosnapshot.CreateNodeInfoMap(nil, []*v1.Node{node}))
40484048
factory := &MetadataProducerFactory{}
40494049
fits2, reasons, err := PodMatchNodeSelector(test.pod, factory.GetPredicateMetadata(test.pod, s), s.NodeInfoMap[node.Name])
40504050
if err != nil {
@@ -4967,7 +4967,7 @@ func TestEvenPodsSpreadPredicate_SingleConstraint(t *testing.T) {
49674967
}
49684968
for _, tt := range tests {
49694969
t.Run(tt.name, func(t *testing.T) {
4970-
s := nodeinfosnapshot.NewSnapshot(tt.existingPods, tt.nodes)
4970+
s := nodeinfosnapshot.NewSnapshot(nodeinfosnapshot.CreateNodeInfoMap(tt.existingPods, tt.nodes))
49714971
factory := &MetadataProducerFactory{}
49724972
meta := factory.GetPredicateMetadata(tt.pod, s)
49734973
for _, node := range tt.nodes {
@@ -5161,7 +5161,7 @@ func TestEvenPodsSpreadPredicate_MultipleConstraints(t *testing.T) {
51615161
}
51625162
for _, tt := range tests {
51635163
t.Run(tt.name, func(t *testing.T) {
5164-
s := nodeinfosnapshot.NewSnapshot(tt.existingPods, tt.nodes)
5164+
s := nodeinfosnapshot.NewSnapshot(nodeinfosnapshot.CreateNodeInfoMap(tt.existingPods, tt.nodes))
51655165
factory := &MetadataProducerFactory{}
51665166
meta := factory.GetPredicateMetadata(tt.pod, s)
51675167
for _, node := range tt.nodes {

pkg/scheduler/algorithm/priorities/balanced_resource_allocation_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ func TestBalancedResourceAllocation(t *testing.T) {
401401

402402
for _, test := range tests {
403403
t.Run(test.name, func(t *testing.T) {
404-
snapshot := nodeinfosnapshot.NewSnapshot(test.pods, test.nodes)
404+
snapshot := nodeinfosnapshot.NewSnapshot(nodeinfosnapshot.CreateNodeInfoMap(test.pods, test.nodes))
405405
if len(test.pod.Spec.Volumes) > 0 {
406406
maxVolumes := 5
407407
for _, info := range snapshot.NodeInfoMap {

pkg/scheduler/algorithm/priorities/even_pods_spread_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ func TestCalculateEvenPodsSpreadPriority(t *testing.T) {
434434
t.Run(tt.name, func(t *testing.T) {
435435
allNodes := append([]*v1.Node{}, tt.nodes...)
436436
allNodes = append(allNodes, tt.failedNodes...)
437-
snapshot := nodeinfosnapshot.NewSnapshot(tt.existingPods, allNodes)
437+
snapshot := nodeinfosnapshot.NewSnapshot(nodeinfosnapshot.CreateNodeInfoMap(tt.existingPods, allNodes))
438438

439439
meta := &priorityMetadata{
440440
podTopologySpreadMap: buildPodTopologySpreadMap(tt.pod, tt.nodes, snapshot.NodeInfoList),
@@ -497,7 +497,7 @@ func BenchmarkTestCalculateEvenPodsSpreadPriority(b *testing.B) {
497497
for _, tt := range tests {
498498
b.Run(tt.name, func(b *testing.B) {
499499
existingPods, allNodes, filteredNodes := st.MakeNodesAndPodsForEvenPodsSpread(tt.pod.Labels, tt.existingPodsNum, tt.allNodesNum, tt.filteredNodesNum)
500-
snapshot := nodeinfosnapshot.NewSnapshot(existingPods, allNodes)
500+
snapshot := nodeinfosnapshot.NewSnapshot(nodeinfosnapshot.CreateNodeInfoMap(existingPods, allNodes))
501501
meta := &priorityMetadata{
502502
podTopologySpreadMap: buildPodTopologySpreadMap(tt.pod, filteredNodes, snapshot.NodeInfoList),
503503
}

pkg/scheduler/algorithm/priorities/image_locality_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func TestImageLocalityPriority(t *testing.T) {
184184

185185
for _, test := range tests {
186186
t.Run(test.name, func(t *testing.T) {
187-
snapshot := nodeinfosnapshot.NewSnapshot(test.pods, test.nodes)
187+
snapshot := nodeinfosnapshot.NewSnapshot(nodeinfosnapshot.CreateNodeInfoMap(test.pods, test.nodes))
188188
list, err := runMapReducePriority(ImageLocalityPriorityMap, nil, &priorityMetadata{totalNumNodes: len(test.nodes)}, test.pod, snapshot, test.nodes)
189189
if err != nil {
190190
t.Errorf("unexpected error: %v", err)

pkg/scheduler/algorithm/priorities/interpod_affinity_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ func TestInterPodAffinityPriority(t *testing.T) {
515515
for _, test := range tests {
516516
t.Run(test.name, func(t *testing.T) {
517517
allNodes := append([]*v1.Node{}, test.nodes...)
518-
snapshot := nodeinfosnapshot.NewSnapshot(test.pods, test.nodes)
518+
snapshot := nodeinfosnapshot.NewSnapshot(nodeinfosnapshot.CreateNodeInfoMap(test.pods, test.nodes))
519519

520520
meta := &priorityMetadata{
521521
topologyScore: buildTopologyPairToScore(test.pod, snapshot, allNodes, v1.DefaultHardPodAffinitySymmetricWeight),
@@ -611,7 +611,7 @@ func TestHardPodAffinitySymmetricWeight(t *testing.T) {
611611
for _, test := range tests {
612612
t.Run(test.name, func(t *testing.T) {
613613
allNodes := append([]*v1.Node{}, test.nodes...)
614-
snapshot := nodeinfosnapshot.NewSnapshot(test.pods, test.nodes)
614+
snapshot := nodeinfosnapshot.NewSnapshot(nodeinfosnapshot.CreateNodeInfoMap(test.pods, test.nodes))
615615

616616
meta := &priorityMetadata{
617617
topologyScore: buildTopologyPairToScore(test.pod, snapshot, allNodes, test.hardPodAffinityWeight),
@@ -675,7 +675,7 @@ func BenchmarkInterPodAffinityPriority(b *testing.B) {
675675
for _, test := range tests {
676676
b.Run(test.name, func(b *testing.B) {
677677
existingPods, allNodes := test.prepFunc(test.existingPodsNum, test.allNodesNum)
678-
snapshot := nodeinfosnapshot.NewSnapshot(existingPods, allNodes)
678+
snapshot := nodeinfosnapshot.NewSnapshot(nodeinfosnapshot.CreateNodeInfoMap(existingPods, allNodes))
679679

680680
meta := &priorityMetadata{
681681
topologyScore: buildTopologyPairToScore(test.pod, snapshot, allNodes, v1.DefaultHardPodAffinitySymmetricWeight),

pkg/scheduler/algorithm/priorities/least_requested_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ func TestLeastRequested(t *testing.T) {
253253

254254
for _, test := range tests {
255255
t.Run(test.name, func(t *testing.T) {
256-
snapshot := nodeinfosnapshot.NewSnapshot(test.pods, test.nodes)
256+
snapshot := nodeinfosnapshot.NewSnapshot(nodeinfosnapshot.CreateNodeInfoMap(test.pods, test.nodes))
257257
list, err := runMapReducePriority(LeastRequestedPriorityMap, nil, nil, test.pod, snapshot, test.nodes)
258258
if err != nil {
259259
t.Errorf("unexpected error: %v", err)

pkg/scheduler/algorithm/priorities/most_requested_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func TestMostRequested(t *testing.T) {
210210

211211
for _, test := range tests {
212212
t.Run(test.name, func(t *testing.T) {
213-
snapshot := nodeinfosnapshot.NewSnapshot(test.pods, test.nodes)
213+
snapshot := nodeinfosnapshot.NewSnapshot(nodeinfosnapshot.CreateNodeInfoMap(test.pods, test.nodes))
214214
list, err := runMapReducePriority(MostRequestedPriorityMap, nil, nil, test.pod, snapshot, test.nodes)
215215
if err != nil {
216216
t.Errorf("unexpected error: %v", err)

pkg/scheduler/algorithm/priorities/node_affinity_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func TestNodeAffinityPriority(t *testing.T) {
167167

168168
for _, test := range tests {
169169
t.Run(test.name, func(t *testing.T) {
170-
snapshot := nodeinfosnapshot.NewSnapshot(nil, test.nodes)
170+
snapshot := nodeinfosnapshot.NewSnapshot(nodeinfosnapshot.CreateNodeInfoMap(nil, test.nodes))
171171
list, err := runMapReducePriority(CalculateNodeAffinityPriorityMap, CalculateNodeAffinityPriorityReduce, nil, test.pod, snapshot, test.nodes)
172172
if err != nil {
173173
t.Errorf("unexpected error: %v", err)

pkg/scheduler/algorithm/priorities/node_prefer_avoid_pods_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func TestNodePreferAvoidPriority(t *testing.T) {
141141

142142
for _, test := range tests {
143143
t.Run(test.name, func(t *testing.T) {
144-
snapshot := nodeinfosnapshot.NewSnapshot(nil, test.nodes)
144+
snapshot := nodeinfosnapshot.NewSnapshot(nodeinfosnapshot.CreateNodeInfoMap(nil, test.nodes))
145145
list, err := runMapReducePriority(CalculateNodePreferAvoidPodsPriorityMap, nil, nil, test.pod, snapshot, test.nodes)
146146
if err != nil {
147147
t.Errorf("unexpected error: %v", err)

0 commit comments

Comments
 (0)