@@ -83,11 +83,7 @@ var _ = SIGDescribe("SchedulerPreemption", framework.WithSerial(), func() {
83
83
_ = cs .SchedulingV1 ().PriorityClasses ().Delete (ctx , pair .name , * metav1 .NewDeleteOptions (0 ))
84
84
}
85
85
for _ , node := range nodeList .Items {
86
- nodeCopy := node .DeepCopy ()
87
- delete (nodeCopy .Status .Capacity , testExtendedResource )
88
- delete (nodeCopy .Status .Allocatable , testExtendedResource )
89
- err := patchNode (ctx , cs , & node , nodeCopy )
90
- framework .ExpectNoError (err )
86
+ e2enode .RemoveExtendedResource (ctx , cs , node .Name , testExtendedResource )
91
87
}
92
88
})
93
89
@@ -134,11 +130,7 @@ var _ = SIGDescribe("SchedulerPreemption", framework.WithSerial(), func() {
134
130
// One of them has low priority, making it the victim for preemption.
135
131
for i , node := range nodeList .Items {
136
132
// Update each node to advertise 3 available extended resources
137
- nodeCopy := node .DeepCopy ()
138
- nodeCopy .Status .Capacity [testExtendedResource ] = resource .MustParse ("5" )
139
- nodeCopy .Status .Allocatable [testExtendedResource ] = resource .MustParse ("5" )
140
- err := patchNode (ctx , cs , & node , nodeCopy )
141
- framework .ExpectNoError (err )
133
+ e2enode .AddExtendedResource (ctx , cs , node .Name , testExtendedResource , resource .MustParse ("5" ))
142
134
143
135
for j := 0 ; j < 2 ; j ++ {
144
136
// Request 2 of the available resources for the victim pods
@@ -225,11 +217,7 @@ var _ = SIGDescribe("SchedulerPreemption", framework.WithSerial(), func() {
225
217
pods := make ([]* v1.Pod , 0 , len (nodeList .Items ))
226
218
for i , node := range nodeList .Items {
227
219
// Update each node to advertise 3 available extended resources
228
- nodeCopy := node .DeepCopy ()
229
- nodeCopy .Status .Capacity [testExtendedResource ] = resource .MustParse ("5" )
230
- nodeCopy .Status .Allocatable [testExtendedResource ] = resource .MustParse ("5" )
231
- err := patchNode (ctx , cs , & node , nodeCopy )
232
- framework .ExpectNoError (err )
220
+ e2enode .AddExtendedResource (ctx , cs , node .Name , testExtendedResource , resource .MustParse ("5" ))
233
221
234
222
for j := 0 ; j < 2 ; j ++ {
235
223
// Request 2 of the available resources for the victim pods
@@ -332,11 +320,7 @@ var _ = SIGDescribe("SchedulerPreemption", framework.WithSerial(), func() {
332
320
ginkgo .By ("Select a node to run the lower and higher priority pods" )
333
321
gomega .Expect (nodeList .Items ).ToNot (gomega .BeEmpty (), "We need at least one node for the test to run" )
334
322
node := nodeList .Items [0 ]
335
- nodeCopy := node .DeepCopy ()
336
- nodeCopy .Status .Capacity [testExtendedResource ] = resource .MustParse ("1" )
337
- nodeCopy .Status .Allocatable [testExtendedResource ] = resource .MustParse ("1" )
338
- err := patchNode (ctx , cs , & node , nodeCopy )
339
- framework .ExpectNoError (err )
323
+ e2enode .AddExtendedResource (ctx , cs , node .Name , testExtendedResource , resource .MustParse ("1" ))
340
324
341
325
// prepare node affinity to make sure both the lower and higher priority pods are scheduled on the same node
342
326
testNodeAffinity := v1.Affinity {
@@ -385,7 +369,7 @@ var _ = SIGDescribe("SchedulerPreemption", framework.WithSerial(), func() {
385
369
framework .Logf ("Created pod: %v" , preemptorPod .Name )
386
370
387
371
ginkgo .By ("Waiting for the victim pod to be terminating" )
388
- err = e2epod .WaitForPodTerminatingInNamespaceTimeout (ctx , f .ClientSet , victimPod .Name , victimPod .Namespace , framework .PodDeleteTimeout )
372
+ err : = e2epod .WaitForPodTerminatingInNamespaceTimeout (ctx , f .ClientSet , victimPod .Name , victimPod .Namespace , framework .PodDeleteTimeout )
389
373
framework .ExpectNoError (err )
390
374
391
375
ginkgo .By ("Verifying the pod has the pod disruption condition" )
@@ -412,11 +396,7 @@ var _ = SIGDescribe("SchedulerPreemption", framework.WithSerial(), func() {
412
396
framework .ExpectNoError (err )
413
397
// update Node API object with a fake resource
414
398
ginkgo .By (fmt .Sprintf ("Apply 10 fake resource to node %v." , node .Name ))
415
- nodeCopy := node .DeepCopy ()
416
- nodeCopy .Status .Capacity [fakeRes ] = resource .MustParse ("10" )
417
- nodeCopy .Status .Allocatable [fakeRes ] = resource .MustParse ("10" )
418
- err = patchNode (ctx , cs , node , nodeCopy )
419
- framework .ExpectNoError (err )
399
+ e2enode .AddExtendedResource (ctx , cs , node .Name , fakeRes , resource .MustParse ("10" ))
420
400
nodes = append (nodes , node )
421
401
}
422
402
})
@@ -425,11 +405,7 @@ var _ = SIGDescribe("SchedulerPreemption", framework.WithSerial(), func() {
425
405
e2enode .RemoveLabelOffNode (cs , nodeName , topologyKey )
426
406
}
427
407
for _ , node := range nodes {
428
- nodeCopy := node .DeepCopy ()
429
- delete (nodeCopy .Status .Capacity , fakeRes )
430
- delete (nodeCopy .Status .Allocatable , fakeRes )
431
- err := patchNode (ctx , cs , node , nodeCopy )
432
- framework .ExpectNoError (err )
408
+ e2enode .RemoveExtendedResource (ctx , cs , node .Name , fakeRes )
433
409
}
434
410
})
435
411
@@ -564,11 +540,7 @@ var _ = SIGDescribe("SchedulerPreemption", framework.WithSerial(), func() {
564
540
}
565
541
566
542
if node != nil {
567
- nodeCopy := node .DeepCopy ()
568
- delete (nodeCopy .Status .Capacity , fakecpu )
569
- delete (nodeCopy .Status .Allocatable , fakecpu )
570
- err := patchNode (ctx , cs , node , nodeCopy )
571
- framework .ExpectNoError (err )
543
+ e2enode .RemoveExtendedResource (ctx , cs , node .Name , fakecpu )
572
544
}
573
545
for _ , pair := range priorityPairs {
574
546
_ = cs .SchedulingV1 ().PriorityClasses ().Delete (ctx , pair .name , * metav1 .NewDeleteOptions (0 ))
@@ -597,11 +569,7 @@ var _ = SIGDescribe("SchedulerPreemption", framework.WithSerial(), func() {
597
569
}
598
570
599
571
// update Node API object with a fake resource
600
- nodeCopy := node .DeepCopy ()
601
- nodeCopy .Status .Capacity [fakecpu ] = resource .MustParse ("1000" )
602
- nodeCopy .Status .Allocatable [fakecpu ] = resource .MustParse ("1000" )
603
- err = patchNode (ctx , cs , node , nodeCopy )
604
- framework .ExpectNoError (err )
572
+ e2enode .AddExtendedResource (ctx , cs , node .Name , fakecpu , resource .MustParse ("1000" ))
605
573
606
574
// create four PriorityClass: p1, p2, p3, p4
607
575
for i := 1 ; i <= 4 ; i ++ {
@@ -920,24 +888,6 @@ func waitForPreemptingWithTimeout(ctx context.Context, f *framework.Framework, p
920
888
framework .ExpectNoError (err , "pod %v/%v failed to preempt other pods" , pod .Namespace , pod .Name )
921
889
}
922
890
923
- func patchNode (ctx context.Context , client clientset.Interface , old * v1.Node , new * v1.Node ) error {
924
- oldData , err := json .Marshal (old )
925
- if err != nil {
926
- return err
927
- }
928
-
929
- newData , err := json .Marshal (new )
930
- if err != nil {
931
- return err
932
- }
933
- patchBytes , err := strategicpatch .CreateTwoWayMergePatch (oldData , newData , & v1.Node {})
934
- if err != nil {
935
- return fmt .Errorf ("failed to create merge patch for node %q: %w" , old .Name , err )
936
- }
937
- _ , err = client .CoreV1 ().Nodes ().Patch (ctx , old .Name , types .StrategicMergePatchType , patchBytes , metav1.PatchOptions {}, "status" )
938
- return err
939
- }
940
-
941
891
func patchPriorityClass (ctx context.Context , cs clientset.Interface , old , new * schedulingv1.PriorityClass ) error {
942
892
oldData , err := json .Marshal (old )
943
893
if err != nil {
0 commit comments