@@ -461,12 +461,12 @@ var _ = SIGDescribe("SchedulerPreemption [Serial]", func() {
461
461
ginkgo .AfterEach (func () {
462
462
// print out additional info if tests failed
463
463
if ginkgo .CurrentGinkgoTestDescription ().Failed {
464
- // list existing priorities
464
+ // List existing PriorityClasses.
465
465
priorityList , err := cs .SchedulingV1 ().PriorityClasses ().List (context .TODO (), metav1.ListOptions {})
466
466
if err != nil {
467
- framework .Logf ("Unable to list priorities : %v" , err )
467
+ framework .Logf ("Unable to list PriorityClasses : %v" , err )
468
468
} else {
469
- framework .Logf ("List existing priorities :" )
469
+ framework .Logf ("List existing PriorityClasses :" )
470
470
for _ , p := range priorityList .Items {
471
471
framework .Logf ("%v/%v created at %v" , p .Name , p .Value , p .CreationTimestamp )
472
472
}
@@ -518,8 +518,7 @@ var _ = SIGDescribe("SchedulerPreemption [Serial]", func() {
518
518
priorityPairs = append (priorityPairs , priorityPair {name : priorityName , value : priorityVal })
519
519
_ , err := cs .SchedulingV1 ().PriorityClasses ().Create (context .TODO (), & schedulingv1.PriorityClass {ObjectMeta : metav1.ObjectMeta {Name : priorityName }, Value : priorityVal }, metav1.CreateOptions {})
520
520
if err != nil {
521
- framework .Logf ("Failed to create priority '%v/%v': %v" , priorityName , priorityVal , err )
522
- framework .Logf ("Reason: %v. Msg: %v" , apierrors .ReasonForError (err ), err )
521
+ framework .Logf ("Failed to create priority '%v/%v'. Reason: %v. Msg: %v" , priorityName , priorityVal , apierrors .ReasonForError (err ), err )
523
522
}
524
523
framework .ExpectEqual (err == nil || apierrors .IsAlreadyExists (err ), true )
525
524
}
@@ -669,6 +668,87 @@ var _ = SIGDescribe("SchedulerPreemption [Serial]", func() {
669
668
}
670
669
})
671
670
})
671
+
672
+ ginkgo .Context ("PriorityClass endpoints" , func () {
673
+ var cs clientset.Interface
674
+ f := framework .NewDefaultFramework ("sched-preemption-path" )
675
+ var pcs []* schedulingv1.PriorityClass
676
+
677
+ ginkgo .BeforeEach (func () {
678
+ cs = f .ClientSet
679
+ // Create 2 PriorityClass: p1, p2.
680
+ for i := 1 ; i <= 2 ; i ++ {
681
+ name , val := fmt .Sprintf ("p%d" , i ), int32 (i )
682
+ pc , err := cs .SchedulingV1 ().PriorityClasses ().Create (context .TODO (), & schedulingv1.PriorityClass {ObjectMeta : metav1.ObjectMeta {Name : name }, Value : val }, metav1.CreateOptions {})
683
+ if err != nil {
684
+ framework .Logf ("Failed to create priority '%v/%v'. Reason: %v. Msg: %v" , name , val , apierrors .ReasonForError (err ), err )
685
+ }
686
+ framework .ExpectEqual (err == nil || apierrors .IsAlreadyExists (err ), true )
687
+ pcs = append (pcs , pc )
688
+ }
689
+ })
690
+
691
+ ginkgo .AfterEach (func () {
692
+ // Print out additional info if tests failed.
693
+ if ginkgo .CurrentGinkgoTestDescription ().Failed {
694
+ // List existing PriorityClasses.
695
+ priorityList , err := cs .SchedulingV1 ().PriorityClasses ().List (context .TODO (), metav1.ListOptions {})
696
+ if err != nil {
697
+ framework .Logf ("Unable to list PriorityClasses: %v" , err )
698
+ } else {
699
+ framework .Logf ("List existing PriorityClasses:" )
700
+ for _ , p := range priorityList .Items {
701
+ framework .Logf ("%v/%v created at %v" , p .Name , p .Value , p .CreationTimestamp )
702
+ }
703
+ }
704
+ }
705
+
706
+ // Cannot run collection deletion which would delete all system level priority classes.
707
+ for _ , pc := range pcs {
708
+ err := cs .SchedulingV1 ().PriorityClasses ().Delete (context .TODO (), pc .Name , * metav1 .NewDeleteOptions (0 ))
709
+ framework .ExpectNoError (err )
710
+ }
711
+ })
712
+
713
+ ginkgo .It ("verify PriorityClass endpoints can be operated with different HTTP methods" , func () {
714
+ // 1. Patch/Update on immutable fields will fail.
715
+ pcCopy := pcs [0 ].DeepCopy ()
716
+ pcCopy .Value = pcCopy .Value * 10
717
+ err := patchPriorityClass (cs , pcs [0 ], pcCopy )
718
+ framework .ExpectError (err , "expect a patch error on an immutable field" )
719
+ framework .Logf ("%v" , err )
720
+
721
+ pcCopy = pcs [1 ].DeepCopy ()
722
+ pcCopy .Value = pcCopy .Value * 10
723
+ _ , err = cs .SchedulingV1 ().PriorityClasses ().Update (context .TODO (), pcCopy , metav1.UpdateOptions {})
724
+ framework .ExpectError (err , "expect an update error on an immutable field" )
725
+ framework .Logf ("%v" , err )
726
+
727
+ // 2. Patch/Update on mutable fields will succeed.
728
+ newDesc := "updated description"
729
+ pcCopy = pcs [0 ].DeepCopy ()
730
+ pcCopy .Description = newDesc
731
+ err = patchPriorityClass (cs , pcs [0 ], pcCopy )
732
+ framework .ExpectNoError (err )
733
+
734
+ pcCopy = pcs [1 ].DeepCopy ()
735
+ pcCopy .Description = newDesc
736
+ _ , err = cs .SchedulingV1 ().PriorityClasses ().Update (context .TODO (), pcCopy , metav1.UpdateOptions {})
737
+ framework .ExpectNoError (err )
738
+
739
+ // 3. List existing PriorityClasses.
740
+ _ , err = cs .SchedulingV1 ().PriorityClasses ().List (context .TODO (), metav1.ListOptions {})
741
+ framework .ExpectNoError (err )
742
+
743
+ // 4. Verify fields of updated PriorityClasses.
744
+ for _ , pc := range pcs {
745
+ livePC , err := cs .SchedulingV1 ().PriorityClasses ().Get (context .TODO (), pc .Name , metav1.GetOptions {})
746
+ framework .ExpectNoError (err )
747
+ framework .ExpectEqual (livePC .Value , pc .Value )
748
+ framework .ExpectEqual (livePC .Description , newDesc )
749
+ }
750
+ })
751
+ })
672
752
})
673
753
674
754
type pauseRSConfig struct {
@@ -756,3 +836,21 @@ func patchNode(client clientset.Interface, old *v1.Node, new *v1.Node) error {
756
836
_ , err = client .CoreV1 ().Nodes ().Patch (context .TODO (), old .Name , types .StrategicMergePatchType , patchBytes , metav1.PatchOptions {}, "status" )
757
837
return err
758
838
}
839
+
840
+ func patchPriorityClass (cs clientset.Interface , old , new * schedulingv1.PriorityClass ) error {
841
+ oldData , err := json .Marshal (old )
842
+ if err != nil {
843
+ return err
844
+ }
845
+
846
+ newData , err := json .Marshal (new )
847
+ if err != nil {
848
+ return err
849
+ }
850
+ patchBytes , err := strategicpatch .CreateTwoWayMergePatch (oldData , newData , & schedulingv1.PriorityClass {})
851
+ if err != nil {
852
+ return fmt .Errorf ("failed to create merge patch for PriorityClass %q: %v" , old .Name , err )
853
+ }
854
+ _ , err = cs .SchedulingV1 ().PriorityClasses ().Patch (context .TODO (), old .Name , types .StrategicMergePatchType , patchBytes , metav1.PatchOptions {})
855
+ return err
856
+ }
0 commit comments