@@ -597,4 +597,212 @@ var _ = Describe("CleanupRemovedNodes", func() {
597597 Expect (skyhook .Status .CompartmentBatchStates ["compartment2" ].CurrentBatch ).To (Equal (2 ))
598598 })
599599 })
600+
601+ Describe ("IntrospectSkyhook" , func () {
602+ var testSkyhook * v1alpha1.Skyhook
603+ var testNode * corev1.Node
604+
605+ BeforeEach (func () {
606+ testSkyhook = & v1alpha1.Skyhook {
607+ ObjectMeta : metav1.ObjectMeta {
608+ Name : "test-skyhook" ,
609+ Annotations : map [string ]string {},
610+ },
611+ Spec : v1alpha1.SkyhookSpec {
612+ Packages : map [string ]v1alpha1.Package {
613+ "test-package" : {
614+ PackageRef : v1alpha1.PackageRef {Name : "test-package" , Version : "1.0.0" },
615+ Image : "test-image" ,
616+ },
617+ },
618+ },
619+ Status : v1alpha1.SkyhookStatus {
620+ Status : v1alpha1 .StatusInProgress ,
621+ },
622+ }
623+
624+ testNode = & corev1.Node {
625+ ObjectMeta : metav1.ObjectMeta {
626+ Name : "test-node" ,
627+ },
628+ }
629+ })
630+
631+ It ("should set status to disabled when skyhook is disabled" , func () {
632+ // Set up the skyhook as disabled
633+ testSkyhook .Annotations ["skyhook.nvidia.com/disable" ] = "true"
634+
635+ skyhookNode , err := wrapper .NewSkyhookNode (testNode , testSkyhook )
636+ Expect (err ).NotTo (HaveOccurred ())
637+
638+ skyhookNodes := & skyhookNodes {
639+ skyhook : wrapper .NewSkyhookWrapper (testSkyhook ),
640+ nodes : []wrapper.SkyhookNode {skyhookNode },
641+ }
642+
643+ // Call the function
644+ changed := IntrospectSkyhook (skyhookNodes , []SkyhookNodes {skyhookNodes })
645+
646+ // Verify the result
647+ Expect (changed ).To (BeTrue ())
648+ Expect (skyhookNodes .Status ()).To (Equal (v1alpha1 .StatusDisabled ))
649+ })
650+
651+ It ("should set status to paused when skyhook is paused" , func () {
652+ // Set up the skyhook as paused
653+ testSkyhook .Annotations ["skyhook.nvidia.com/pause" ] = "true"
654+
655+ skyhookNode , err := wrapper .NewSkyhookNode (testNode , testSkyhook )
656+ Expect (err ).NotTo (HaveOccurred ())
657+
658+ skyhookNodes := & skyhookNodes {
659+ skyhook : wrapper .NewSkyhookWrapper (testSkyhook ),
660+ nodes : []wrapper.SkyhookNode {skyhookNode },
661+ }
662+
663+ // Call the function
664+ changed := IntrospectSkyhook (skyhookNodes , []SkyhookNodes {skyhookNodes })
665+
666+ // Verify the result
667+ Expect (changed ).To (BeTrue ())
668+ Expect (skyhookNodes .Status ()).To (Equal (v1alpha1 .StatusPaused ))
669+ })
670+
671+ It ("should set status to waiting when another skyhook has higher priority" , func () {
672+ // Create higher priority skyhook (priority 1)
673+ higherPrioritySkyhook := & v1alpha1.Skyhook {
674+ ObjectMeta : metav1.ObjectMeta {Name : "skyhook-1" },
675+ Spec : v1alpha1.SkyhookSpec {
676+ Priority : 1 ,
677+ Packages : map [string ]v1alpha1.Package {
678+ "test-package-1" : {
679+ PackageRef : v1alpha1.PackageRef {Name : "test-package-1" , Version : "1.0.0" },
680+ Image : "test-image-1" ,
681+ },
682+ },
683+ },
684+ Status : v1alpha1.SkyhookStatus {Status : v1alpha1 .StatusInProgress },
685+ }
686+
687+ // Create lower priority skyhook (priority 2)
688+ lowerPrioritySkyhook := & v1alpha1.Skyhook {
689+ ObjectMeta : metav1.ObjectMeta {Name : "skyhook-2" },
690+ Spec : v1alpha1.SkyhookSpec {
691+ Priority : 2 ,
692+ Packages : map [string ]v1alpha1.Package {
693+ "test-package-2" : {
694+ PackageRef : v1alpha1.PackageRef {Name : "test-package-2" , Version : "1.0.0" },
695+ Image : "test-image-2" ,
696+ },
697+ },
698+ },
699+ Status : v1alpha1.SkyhookStatus {Status : v1alpha1 .StatusInProgress },
700+ }
701+
702+ node1 := & corev1.Node {ObjectMeta : metav1.ObjectMeta {Name : "node-1" }}
703+ node2 := & corev1.Node {ObjectMeta : metav1.ObjectMeta {Name : "node-2" }}
704+
705+ skyhookNode1 , err := wrapper .NewSkyhookNode (node1 , higherPrioritySkyhook )
706+ Expect (err ).NotTo (HaveOccurred ())
707+
708+ skyhookNode2 , err := wrapper .NewSkyhookNode (node2 , lowerPrioritySkyhook )
709+ Expect (err ).NotTo (HaveOccurred ())
710+
711+ skyhookNodes1 := & skyhookNodes {
712+ skyhook : wrapper .NewSkyhookWrapper (higherPrioritySkyhook ),
713+ nodes : []wrapper.SkyhookNode {skyhookNode1 },
714+ }
715+
716+ skyhookNodes2 := & skyhookNodes {
717+ skyhook : wrapper .NewSkyhookWrapper (lowerPrioritySkyhook ),
718+ nodes : []wrapper.SkyhookNode {skyhookNode2 },
719+ }
720+
721+ allSkyhooks := []SkyhookNodes {skyhookNodes1 , skyhookNodes2 }
722+
723+ // Call the function - skyhook2 should be waiting because skyhook1 has higher priority
724+ changed := IntrospectSkyhook (skyhookNodes2 , allSkyhooks )
725+
726+ // Verify the result
727+ Expect (changed ).To (BeTrue ())
728+ Expect (skyhookNodes2 .Status ()).To (Equal (v1alpha1 .StatusWaiting ))
729+ })
730+
731+ It ("should not change status when skyhook is complete" , func () {
732+ // Create a complete skyhook with no packages
733+ completeSkyhook := & v1alpha1.Skyhook {
734+ ObjectMeta : metav1.ObjectMeta {Name : "test-skyhook" },
735+ Status : v1alpha1.SkyhookStatus {Status : v1alpha1 .StatusComplete },
736+ }
737+
738+ node := & corev1.Node {
739+ ObjectMeta : metav1.ObjectMeta {Name : "test-node" },
740+ Status : corev1.NodeStatus {
741+ Conditions : []corev1.NodeCondition {
742+ {Type : corev1 .NodeReady , Status : corev1 .ConditionTrue },
743+ },
744+ },
745+ }
746+
747+ skyhookNode , err := wrapper .NewSkyhookNode (node , completeSkyhook )
748+ Expect (err ).NotTo (HaveOccurred ())
749+ skyhookNode .SetStatus (v1alpha1 .StatusComplete )
750+
751+ skyhookNodes := & skyhookNodes {
752+ skyhook : wrapper .NewSkyhookWrapper (completeSkyhook ),
753+ nodes : []wrapper.SkyhookNode {skyhookNode },
754+ }
755+
756+ // Call the function
757+ _ = IntrospectSkyhook (skyhookNodes , []SkyhookNodes {skyhookNodes })
758+
759+ // Verify the result - status should stay complete
760+ Expect (skyhookNodes .Status ()).To (Equal (v1alpha1 .StatusComplete ))
761+ })
762+
763+ It ("should return true when node status changes" , func () {
764+ skyhookNode , err := wrapper .NewSkyhookNode (testNode , testSkyhook )
765+ Expect (err ).NotTo (HaveOccurred ())
766+ skyhookNode .SetStatus (v1alpha1 .StatusUnknown )
767+
768+ skyhookNodes := & skyhookNodes {
769+ skyhook : wrapper .NewSkyhookWrapper (testSkyhook ),
770+ nodes : []wrapper.SkyhookNode {skyhookNode },
771+ }
772+
773+ // Call the function
774+ changed := IntrospectSkyhook (skyhookNodes , []SkyhookNodes {skyhookNodes })
775+
776+ // Verify the result
777+ Expect (changed ).To (BeTrue ())
778+ })
779+
780+ It ("should handle multiple nodes correctly when disabled" , func () {
781+ // Set up the skyhook as disabled
782+ testSkyhook .Annotations ["skyhook.nvidia.com/disable" ] = "true"
783+
784+ node1 := & corev1.Node {ObjectMeta : metav1.ObjectMeta {Name : "node-1" }}
785+ node2 := & corev1.Node {ObjectMeta : metav1.ObjectMeta {Name : "node-2" }}
786+
787+ skyhookNode1 , err := wrapper .NewSkyhookNode (node1 , testSkyhook )
788+ Expect (err ).NotTo (HaveOccurred ())
789+
790+ skyhookNode2 , err := wrapper .NewSkyhookNode (node2 , testSkyhook )
791+ Expect (err ).NotTo (HaveOccurred ())
792+
793+ skyhookNodes := & skyhookNodes {
794+ skyhook : wrapper .NewSkyhookWrapper (testSkyhook ),
795+ nodes : []wrapper.SkyhookNode {skyhookNode1 , skyhookNode2 },
796+ }
797+
798+ // Call the function
799+ changed := IntrospectSkyhook (skyhookNodes , []SkyhookNodes {skyhookNodes })
800+
801+ // Verify the result
802+ Expect (changed ).To (BeTrue ())
803+ Expect (skyhookNodes .Status ()).To (Equal (v1alpha1 .StatusDisabled ))
804+ Expect (skyhookNode1 .Status ()).To (Equal (v1alpha1 .StatusDisabled ))
805+ Expect (skyhookNode2 .Status ()).To (Equal (v1alpha1 .StatusDisabled ))
806+ })
807+ })
600808})
0 commit comments