@@ -70,16 +70,7 @@ func predicateMetadataEquivalent(meta1, meta2 *predicateMetadata) error {
70
70
for ! reflect .DeepEqual (meta1 .podFitsHostPortsMetadata .podPorts , meta2 .podFitsHostPortsMetadata .podPorts ) {
71
71
return fmt .Errorf ("podPorts are not equal" )
72
72
}
73
- if ! reflect .DeepEqual (meta1 .podAffinityMetadata .topologyToMatchedAffinityTerms , meta2 .podAffinityMetadata .topologyToMatchedAffinityTerms ) {
74
- return fmt .Errorf ("topologyToMatchedAffinityTerms are not equal" )
75
- }
76
- if ! reflect .DeepEqual (meta1 .podAffinityMetadata .topologyToMatchedAntiAffinityTerms , meta2 .podAffinityMetadata .topologyToMatchedAntiAffinityTerms ) {
77
- return fmt .Errorf ("topologyToMatchedAntiAffinityTerms are not equal" )
78
- }
79
- if ! reflect .DeepEqual (meta1 .podAffinityMetadata .topologyToMatchedExistingAntiAffinityTerms ,
80
- meta2 .podAffinityMetadata .topologyToMatchedExistingAntiAffinityTerms ) {
81
- return fmt .Errorf ("topologyToMatchedExistingAntiAffinityTerms are not equal, got: %v, want: %v" , meta1 .podAffinityMetadata .topologyToMatchedExistingAntiAffinityTerms , meta2 .podAffinityMetadata .topologyToMatchedExistingAntiAffinityTerms )
82
- }
73
+
83
74
if meta1 .serviceAffinityMetadata != nil {
84
75
sortablePods1 := sortablePods (meta1 .serviceAffinityMetadata .matchingPodList )
85
76
sort .Sort (sortablePods1 )
@@ -114,78 +105,6 @@ func TestPredicateMetadata_AddRemovePod(t *testing.T) {
114
105
"zone" : "z21" ,
115
106
}
116
107
selector1 := map [string ]string {"foo" : "bar" }
117
- antiAffinityFooBar := & v1.PodAntiAffinity {
118
- RequiredDuringSchedulingIgnoredDuringExecution : []v1.PodAffinityTerm {
119
- {
120
- LabelSelector : & metav1.LabelSelector {
121
- MatchExpressions : []metav1.LabelSelectorRequirement {
122
- {
123
- Key : "foo" ,
124
- Operator : metav1 .LabelSelectorOpIn ,
125
- Values : []string {"bar" },
126
- },
127
- },
128
- },
129
- TopologyKey : "region" ,
130
- },
131
- },
132
- }
133
- antiAffinityComplex := & v1.PodAntiAffinity {
134
- RequiredDuringSchedulingIgnoredDuringExecution : []v1.PodAffinityTerm {
135
- {
136
- LabelSelector : & metav1.LabelSelector {
137
- MatchExpressions : []metav1.LabelSelectorRequirement {
138
- {
139
- Key : "foo" ,
140
- Operator : metav1 .LabelSelectorOpIn ,
141
- Values : []string {"bar" , "buzz" },
142
- },
143
- },
144
- },
145
- TopologyKey : "region" ,
146
- },
147
- {
148
- LabelSelector : & metav1.LabelSelector {
149
- MatchExpressions : []metav1.LabelSelectorRequirement {
150
- {
151
- Key : "service" ,
152
- Operator : metav1 .LabelSelectorOpNotIn ,
153
- Values : []string {"bar" , "security" , "test" },
154
- },
155
- },
156
- },
157
- TopologyKey : "zone" ,
158
- },
159
- },
160
- }
161
- affinityComplex := & v1.PodAffinity {
162
- RequiredDuringSchedulingIgnoredDuringExecution : []v1.PodAffinityTerm {
163
- {
164
- LabelSelector : & metav1.LabelSelector {
165
- MatchExpressions : []metav1.LabelSelectorRequirement {
166
- {
167
- Key : "foo" ,
168
- Operator : metav1 .LabelSelectorOpIn ,
169
- Values : []string {"bar" , "buzz" },
170
- },
171
- },
172
- },
173
- TopologyKey : "region" ,
174
- },
175
- {
176
- LabelSelector : & metav1.LabelSelector {
177
- MatchExpressions : []metav1.LabelSelectorRequirement {
178
- {
179
- Key : "service" ,
180
- Operator : metav1 .LabelSelectorOpNotIn ,
181
- Values : []string {"bar" , "security" , "test" },
182
- },
183
- },
184
- },
185
- TopologyKey : "zone" ,
186
- },
187
- },
188
- }
189
108
190
109
tests := []struct {
191
110
name string
@@ -218,39 +137,6 @@ func TestPredicateMetadata_AddRemovePod(t *testing.T) {
218
137
{ObjectMeta : metav1.ObjectMeta {Name : "nodeC" , Labels : label3 }},
219
138
},
220
139
},
221
- {
222
- name : "metadata anti-affinity terms are updated correctly after adding and removing a pod" ,
223
- pendingPod : & v1.Pod {
224
- ObjectMeta : metav1.ObjectMeta {Name : "pending" , Labels : selector1 },
225
- },
226
- existingPods : []* v1.Pod {
227
- {ObjectMeta : metav1.ObjectMeta {Name : "p1" , Labels : selector1 },
228
- Spec : v1.PodSpec {NodeName : "nodeA" },
229
- },
230
- {ObjectMeta : metav1.ObjectMeta {Name : "p2" },
231
- Spec : v1.PodSpec {
232
- NodeName : "nodeC" ,
233
- Affinity : & v1.Affinity {
234
- PodAntiAffinity : antiAffinityFooBar ,
235
- },
236
- },
237
- },
238
- },
239
- addedPod : & v1.Pod {
240
- ObjectMeta : metav1.ObjectMeta {Name : "addedPod" , Labels : selector1 },
241
- Spec : v1.PodSpec {
242
- NodeName : "nodeB" ,
243
- Affinity : & v1.Affinity {
244
- PodAntiAffinity : antiAffinityFooBar ,
245
- },
246
- },
247
- },
248
- nodes : []* v1.Node {
249
- {ObjectMeta : metav1.ObjectMeta {Name : "nodeA" , Labels : label1 }},
250
- {ObjectMeta : metav1.ObjectMeta {Name : "nodeB" , Labels : label2 }},
251
- {ObjectMeta : metav1.ObjectMeta {Name : "nodeC" , Labels : label3 }},
252
- },
253
- },
254
140
{
255
141
name : "metadata service-affinity data are updated correctly after adding and removing a pod" ,
256
142
pendingPod : & v1.Pod {
@@ -275,75 +161,6 @@ func TestPredicateMetadata_AddRemovePod(t *testing.T) {
275
161
{ObjectMeta : metav1.ObjectMeta {Name : "nodeC" , Labels : label3 }},
276
162
},
277
163
},
278
- {
279
- name : "metadata anti-affinity terms and service affinity data are updated correctly after adding and removing a pod" ,
280
- pendingPod : & v1.Pod {
281
- ObjectMeta : metav1.ObjectMeta {Name : "pending" , Labels : selector1 },
282
- },
283
- existingPods : []* v1.Pod {
284
- {ObjectMeta : metav1.ObjectMeta {Name : "p1" , Labels : selector1 },
285
- Spec : v1.PodSpec {NodeName : "nodeA" },
286
- },
287
- {ObjectMeta : metav1.ObjectMeta {Name : "p2" },
288
- Spec : v1.PodSpec {
289
- NodeName : "nodeC" ,
290
- Affinity : & v1.Affinity {
291
- PodAntiAffinity : antiAffinityFooBar ,
292
- },
293
- },
294
- },
295
- },
296
- addedPod : & v1.Pod {
297
- ObjectMeta : metav1.ObjectMeta {Name : "addedPod" , Labels : selector1 },
298
- Spec : v1.PodSpec {
299
- NodeName : "nodeA" ,
300
- Affinity : & v1.Affinity {
301
- PodAntiAffinity : antiAffinityComplex ,
302
- },
303
- },
304
- },
305
- services : []* v1.Service {{Spec : v1.ServiceSpec {Selector : selector1 }}},
306
- nodes : []* v1.Node {
307
- {ObjectMeta : metav1.ObjectMeta {Name : "nodeA" , Labels : label1 }},
308
- {ObjectMeta : metav1.ObjectMeta {Name : "nodeB" , Labels : label2 }},
309
- {ObjectMeta : metav1.ObjectMeta {Name : "nodeC" , Labels : label3 }},
310
- },
311
- },
312
- {
313
- name : "metadata matching pod affinity and anti-affinity are updated correctly after adding and removing a pod" ,
314
- pendingPod : & v1.Pod {
315
- ObjectMeta : metav1.ObjectMeta {Name : "pending" , Labels : selector1 },
316
- },
317
- existingPods : []* v1.Pod {
318
- {ObjectMeta : metav1.ObjectMeta {Name : "p1" , Labels : selector1 },
319
- Spec : v1.PodSpec {NodeName : "nodeA" },
320
- },
321
- {ObjectMeta : metav1.ObjectMeta {Name : "p2" },
322
- Spec : v1.PodSpec {
323
- NodeName : "nodeC" ,
324
- Affinity : & v1.Affinity {
325
- PodAntiAffinity : antiAffinityFooBar ,
326
- PodAffinity : affinityComplex ,
327
- },
328
- },
329
- },
330
- },
331
- addedPod : & v1.Pod {
332
- ObjectMeta : metav1.ObjectMeta {Name : "addedPod" , Labels : selector1 },
333
- Spec : v1.PodSpec {
334
- NodeName : "nodeA" ,
335
- Affinity : & v1.Affinity {
336
- PodAntiAffinity : antiAffinityComplex ,
337
- },
338
- },
339
- },
340
- services : []* v1.Service {{Spec : v1.ServiceSpec {Selector : selector1 }}},
341
- nodes : []* v1.Node {
342
- {ObjectMeta : metav1.ObjectMeta {Name : "nodeA" , Labels : label1 }},
343
- {ObjectMeta : metav1.ObjectMeta {Name : "nodeB" , Labels : label2 }},
344
- {ObjectMeta : metav1.ObjectMeta {Name : "nodeC" , Labels : label3 }},
345
- },
346
- },
347
164
}
348
165
349
166
for _ , test := range tests {
@@ -385,6 +202,31 @@ func TestPredicateMetadata_AddRemovePod(t *testing.T) {
385
202
}
386
203
}
387
204
205
+ func TestPodAffinityMetadata_Clone (t * testing.T ) {
206
+ source := & PodAffinityMetadata {
207
+ topologyToMatchedExistingAntiAffinityTerms : topologyToMatchedTermCount {
208
+ {key : "name" , value : "machine1" }: 1 ,
209
+ {key : "name" , value : "machine2" }: 1 ,
210
+ },
211
+ topologyToMatchedAffinityTerms : topologyToMatchedTermCount {
212
+ {key : "name" , value : "nodeA" }: 1 ,
213
+ {key : "name" , value : "nodeC" }: 2 ,
214
+ },
215
+ topologyToMatchedAntiAffinityTerms : topologyToMatchedTermCount {
216
+ {key : "name" , value : "nodeN" }: 3 ,
217
+ {key : "name" , value : "nodeM" }: 1 ,
218
+ },
219
+ }
220
+
221
+ clone := source .Clone ()
222
+ if clone == source {
223
+ t .Errorf ("Clone returned the exact same object!" )
224
+ }
225
+ if ! reflect .DeepEqual (clone , source ) {
226
+ t .Errorf ("Copy is not equal to source!" )
227
+ }
228
+ }
229
+
388
230
// TestPredicateMetadata_ShallowCopy tests the ShallowCopy function. It is based
389
231
// on the idea that shallow-copy should produce an object that is deep-equal to the original
390
232
// object.
@@ -415,20 +257,6 @@ func TestPredicateMetadata_ShallowCopy(t *testing.T) {
415
257
},
416
258
},
417
259
},
418
- podAffinityMetadata : & podAffinityMetadata {
419
- topologyToMatchedExistingAntiAffinityTerms : topologyToMatchedTermCount {
420
- {key : "name" , value : "machine1" }: 1 ,
421
- {key : "name" , value : "machine2" }: 1 ,
422
- },
423
- topologyToMatchedAffinityTerms : topologyToMatchedTermCount {
424
- {key : "name" , value : "nodeA" }: 1 ,
425
- {key : "name" , value : "nodeC" }: 2 ,
426
- },
427
- topologyToMatchedAntiAffinityTerms : topologyToMatchedTermCount {
428
- {key : "name" , value : "nodeN" }: 3 ,
429
- {key : "name" , value : "nodeM" }: 1 ,
430
- },
431
- },
432
260
evenPodsSpreadMetadata : & evenPodsSpreadMetadata {
433
261
tpKeyToCriticalPaths : map [string ]* criticalPaths {
434
262
"name" : {{"nodeA" , 1 }, {"nodeC" , 2 }},
0 commit comments