@@ -40,6 +40,7 @@ import (
4040
4141 configv1 "github.com/openshift/api/config/v1"
4242
43+ "github.com/k8stopologyawareschedwg/deployer/pkg/deployer/platform"
4344 depmanifests "github.com/k8stopologyawareschedwg/deployer/pkg/manifests"
4445 depobjupdate "github.com/k8stopologyawareschedwg/deployer/pkg/objectupdate"
4546
@@ -632,6 +633,164 @@ var _ = ginkgo.Describe("Test NUMAResourcesScheduler Reconcile", func() {
632633 gomega .Expect (* dp .Spec .Replicas ).To (gomega .Equal (int32 (numOfMasters )), "number of replicas is different than number of control-planes nodes; want=%d got=%d" , numOfMasters , * dp .Spec .Replicas )
633634 })
634635 })
636+
637+ ginkgo .Context ("with kubelet PodResourcesAPI listing active pods by default" , func () {
638+ var nrs * nropv1.NUMAResourcesScheduler
639+ var reconciler * NUMAResourcesSchedulerReconciler
640+ numOfMasters := 3
641+
642+ ginkgo .When ("kubelet fix is enabled" , func () {
643+ fixedVersion , _ := platform .ParseVersion (activePodsResourcesSupportSince )
644+
645+ ginkgo .DescribeTable ("should configure by default the informerMode to the expected when field is not set" , func (reconcilerPlatInfo PlatformInfo , expectedInformer string ) {
646+ var err error
647+ nrs = testobjs .NewNUMAResourcesScheduler ("numaresourcesscheduler" , "some/url:latest" , testSchedulerName , 11 * time .Second )
648+ initObjects := []runtime.Object {nrs }
649+ initObjects = append (initObjects , fakeNodes (numOfMasters , 3 )... )
650+ reconciler , err = NewFakeNUMAResourcesSchedulerReconciler (initObjects ... )
651+ gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
652+
653+ reconciler .PlatformInfo = reconcilerPlatInfo
654+
655+ key := client .ObjectKeyFromObject (nrs )
656+ _ , err = reconciler .Reconcile (context .TODO (), reconcile.Request {NamespacedName : key })
657+ gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
658+
659+ expectCacheParams (reconciler .Client , depmanifests .CacheResyncAutodetect , depmanifests .CacheResyncOnlyExclusiveResources , expectedInformer )
660+ },
661+ ginkgo .Entry ("with fixed Openshift the default informer is Shared" , PlatformInfo {
662+ Platform : platform .OpenShift ,
663+ Version : fixedVersion ,
664+ }, depmanifests .CacheInformerShared ),
665+ ginkgo .Entry ("with fixed Hypershift the default informer is Shared" , PlatformInfo {
666+ Platform : platform .HyperShift ,
667+ Version : fixedVersion ,
668+ }, depmanifests .CacheInformerShared ),
669+ ginkgo .Entry ("with unknown platform the default informer is Dedicated (unchanged)" , PlatformInfo {}, depmanifests .CacheInformerDedicated ))
670+
671+ ginkgo .DescribeTable ("should preserve informerMode value if set" , func (reconcilerPlatInfo PlatformInfo ) {
672+ var err error
673+ nrs = testobjs .NewNUMAResourcesScheduler ("numaresourcesscheduler" , "some/url:latest" , testSchedulerName , 11 * time .Second )
674+ infMode := nropv1 .SchedulerInformerDedicated
675+ nrs .Spec .SchedulerInformer = & infMode
676+ initObjects := []runtime.Object {nrs }
677+ initObjects = append (initObjects , fakeNodes (numOfMasters , 3 )... )
678+ reconciler , err = NewFakeNUMAResourcesSchedulerReconciler (initObjects ... )
679+ gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
680+
681+ reconciler .PlatformInfo = reconcilerPlatInfo
682+
683+ key := client .ObjectKeyFromObject (nrs )
684+ _ , err = reconciler .Reconcile (context .TODO (), reconcile.Request {NamespacedName : key })
685+ gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
686+ expectCacheParams (reconciler .Client , depmanifests .CacheResyncAutodetect , depmanifests .CacheResyncOnlyExclusiveResources , string (infMode ))
687+ },
688+ ginkgo .Entry ("with Openshift" , PlatformInfo {
689+ Platform : platform .OpenShift ,
690+ Version : fixedVersion ,
691+ }),
692+ ginkgo .Entry ("with Hypershift" , PlatformInfo {
693+ Platform : platform .HyperShift ,
694+ Version : fixedVersion ,
695+ }),
696+ ginkgo .Entry ("with unknown platform" , PlatformInfo {}))
697+
698+ ginkgo .DescribeTable ("should allow to update the informerMode to be Dedicated after an overridden default" , func (reconcilerPlatInfo PlatformInfo ) {
699+ var err error
700+ nrs = testobjs .NewNUMAResourcesScheduler ("numaresourcesscheduler" , "some/url:latest" , testSchedulerName , 11 * time .Second )
701+ initObjects := []runtime.Object {nrs }
702+ initObjects = append (initObjects , fakeNodes (numOfMasters , 3 )... )
703+ reconciler , err = NewFakeNUMAResourcesSchedulerReconciler (initObjects ... )
704+ gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
705+
706+ reconciler .PlatformInfo = reconcilerPlatInfo
707+
708+ key := client .ObjectKeyFromObject (nrs )
709+ _ , err = reconciler .Reconcile (context .TODO (), reconcile.Request {NamespacedName : key })
710+ gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
711+
712+ // intentionally skip checking default value
713+
714+ // should query the object after reconcile because the defaults are overridden
715+ gomega .Expect (reconciler .Client .Get (context .TODO (), key , nrs )).ToNot (gomega .HaveOccurred ())
716+
717+ nrsUpdated := nrs .DeepCopy ()
718+ informerMode := nropv1 .SchedulerInformerDedicated
719+ nrsUpdated .Spec .SchedulerInformer = & informerMode
720+ gomega .Eventually (func () bool {
721+ if err := reconciler .Client .Update (context .TODO (), nrsUpdated ); err != nil {
722+ klog .Warningf ("failed to update the scheduler object; err: %v" , err )
723+ return false
724+ }
725+ return true
726+ }, 30 * time .Second , 5 * time .Second ).Should (gomega .BeTrue ())
727+
728+ _ , err = reconciler .Reconcile (context .TODO (), reconcile.Request {NamespacedName : key })
729+ gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
730+
731+ expectCacheParams (reconciler .Client , depmanifests .CacheResyncAutodetect , depmanifests .CacheResyncOnlyExclusiveResources , string (informerMode ))
732+ },
733+ ginkgo .Entry ("with Openshift" , PlatformInfo {
734+ Platform : platform .OpenShift ,
735+ Version : fixedVersion ,
736+ }),
737+ ginkgo .Entry ("with Hypershift" , PlatformInfo {
738+ Platform : platform .HyperShift ,
739+ Version : fixedVersion ,
740+ }))
741+ })
742+ })
743+ })
744+
745+ var _ = ginkgo .Describe ("Test scheduler spec PreNormalize" , func () {
746+ ginkgo .When ("Spec.SchedulerInformer is not set by the user" , func () {
747+ ginkgo .It ("should override default informer to Shared if kubelet is fixed - first supported zstream version" , func () {
748+ v , _ := platform .ParseVersion (activePodsResourcesSupportSince )
749+ spec := nropv1.NUMAResourcesSchedulerSpec {}
750+ platformNormalize (& spec , PlatformInfo {Platform : platform .OpenShift , Version : v })
751+ gomega .Expect (* spec .SchedulerInformer ).To (gomega .Equal (nropv1 .SchedulerInformerShared ))
752+ })
753+
754+ ginkgo .It ("should override default informer to Shared if kubelet is fixed - version is greater than first supported (zstream)" , func () {
755+ v , _ := platform .ParseVersion ("4.20.1000" )
756+ spec := nropv1.NUMAResourcesSchedulerSpec {}
757+ platformNormalize (& spec , PlatformInfo {Platform : platform .OpenShift , Version : v })
758+ gomega .Expect (* spec .SchedulerInformer ).To (gomega .Equal (nropv1 .SchedulerInformerShared ))
759+ })
760+
761+ ginkgo .It ("should override default informer to Shared if kubelet is fixed - version is greater than first supported (ystream)" , func () {
762+ v , _ := platform .ParseVersion ("4.21.0" )
763+ spec := nropv1.NUMAResourcesSchedulerSpec {}
764+ platformNormalize (& spec , PlatformInfo {Platform : platform .OpenShift , Version : v })
765+ gomega .Expect (* spec .SchedulerInformer ).To (gomega .Equal (nropv1 .SchedulerInformerShared ))
766+ })
767+
768+ ginkgo .It ("should not override default informer if kubelet is not fixed - version is less than first supported (zstream)" , func () {
769+ // this is only for testing purposes as there is plan to backport the fix to older minor versions
770+ // will need to remove this test if the fix is supported starting the first zstream of the release
771+ v , _ := platform .ParseVersion ("4.20.0" )
772+ spec := nropv1.NUMAResourcesSchedulerSpec {}
773+ platformNormalize (& spec , PlatformInfo {Platform : platform .OpenShift , Version : v })
774+ gomega .Expect (spec .SchedulerInformer ).To (gomega .BeNil ())
775+ })
776+
777+ ginkgo .It ("should not override default informer if kubelet is not fixed - version is less than first supported (ystream)" , func () {
778+ v , _ := platform .ParseVersion ("4.13.0" )
779+ spec := nropv1.NUMAResourcesSchedulerSpec {}
780+ platformNormalize (& spec , PlatformInfo {Platform : platform .OpenShift , Version : v })
781+ gomega .Expect (spec .SchedulerInformer ).To (gomega .BeNil ())
782+ })
783+ })
784+ ginkgo .When ("Spec.SchedulerInformer is set by the user" , func () {
785+ ginkgo .It ("should preserve informer value set by the user even if kubelet is fixed" , func () {
786+ v , _ := platform .ParseVersion (activePodsResourcesSupportSince )
787+ spec := nropv1.NUMAResourcesSchedulerSpec {
788+ SchedulerInformer : ptr .To (nropv1 .SchedulerInformerDedicated ),
789+ }
790+ platformNormalize (& spec , PlatformInfo {Platform : platform .OpenShift , Version : v })
791+ gomega .Expect (* spec .SchedulerInformer ).To (gomega .Equal (nropv1 .SchedulerInformerDedicated ))
792+ })
793+ })
635794})
636795
637796func pop (m map [string ]string , k string ) string {
0 commit comments