@@ -686,4 +686,43 @@ var _ = Context("Inside the default namespace", func() {
686
686
Expect (rayCluster .Status .DesiredCPU ).To (Equal (desiredCPU ))
687
687
})
688
688
})
689
+
690
+ Describe ("RayCluster with invalid NumOfHosts" , func () {
691
+ // Some users only upgrade the KubeRay image without upgrading the CRD. For example, when a
692
+ // user upgrades the KubeRay operator from v1.0.0 to v1.1.0 without upgrading the CRD, the
693
+ // KubeRay operator will use the zero value of `NumOfHosts` in the CRD. Hence, all worker
694
+ // Pods will be deleted. This test case is designed to prevent Pods from being deleted.
695
+ ctx := context .Background ()
696
+ namespace := "default"
697
+ rayCluster := rayClusterTemplate ("raycluster-invalid-numofhosts" , namespace )
698
+ numOfHosts := int32 (0 )
699
+ rayCluster .Spec .WorkerGroupSpecs [0 ].NumOfHosts = numOfHosts
700
+ workerPods := corev1.PodList {}
701
+ workerFilters := common .RayClusterGroupPodsAssociationOptions (rayCluster , rayCluster .Spec .WorkerGroupSpecs [0 ].GroupName ).ToListOptions ()
702
+
703
+ It ("Verify RayCluster spec" , func () {
704
+ // These test are designed based on the following assumptions:
705
+ // (1) There is only one worker group, and its `replicas` is set to 3, and `workersToDelete` is empty.
706
+ // (2) The worker group has an invalid `numOfHosts` value of 0.
707
+ Expect (len (rayCluster .Spec .WorkerGroupSpecs )).To (Equal (1 ))
708
+ Expect (rayCluster .Spec .WorkerGroupSpecs [0 ].NumOfHosts ).To (Equal (numOfHosts ))
709
+ Expect (rayCluster .Spec .WorkerGroupSpecs [0 ].Replicas ).To (Equal (pointer .Int32 (3 )))
710
+ Expect (rayCluster .Spec .WorkerGroupSpecs [0 ].ScaleStrategy .WorkersToDelete ).To (BeEmpty ())
711
+ })
712
+
713
+ It ("Create a RayCluster custom resource" , func () {
714
+ err := k8sClient .Create (ctx , rayCluster )
715
+ Expect (err ).NotTo (HaveOccurred (), "Failed to create RayCluster" )
716
+ Eventually (
717
+ getResourceFunc (ctx , client.ObjectKey {Name : rayCluster .Name , Namespace : namespace }, rayCluster ),
718
+ time .Second * 3 , time .Millisecond * 500 ).Should (BeNil (), "Should be able to see RayCluster: %v" , rayCluster .Name )
719
+ })
720
+
721
+ It ("Check the number of worker Pods" , func () {
722
+ numWorkerPods := 3 * int (numOfHosts )
723
+ Eventually (
724
+ listResourceFunc (ctx , & workerPods , workerFilters ... ),
725
+ time .Second * 3 , time .Millisecond * 500 ).Should (Equal (numWorkerPods ), fmt .Sprintf ("workerGroup %v" , workerPods .Items ))
726
+ })
727
+ })
689
728
})
0 commit comments