@@ -33,7 +33,7 @@ import (
3333
3434var _ = Describe ("RayCluster controller" , func () {
3535 Context ("RayCluster controller test" , func () {
36- var rayClusterName = "test-raycluster"
36+ rayClusterName : = "test-raycluster"
3737 var namespaceName string
3838 BeforeEach (func (ctx SpecContext ) {
3939 By ("Creating a namespace for running the tests." )
@@ -145,6 +145,53 @@ var _ = Describe("RayCluster controller", func() {
145145 }).WithTimeout (time .Second * 10 ).Should (WithTransform (OwnerReferenceName , Equal (foundRayCluster .Name )))
146146 })
147147
148+ It ("should delete the head pod if missing image pull secrets" , func (ctx SpecContext ) {
149+ foundRayCluster , err := rayClient .RayV1 ().RayClusters (namespaceName ).Get (ctx , rayClusterName , metav1.GetOptions {})
150+ Expect (err ).To (Not (HaveOccurred ()))
151+
152+ Eventually (func () (* corev1.ServiceAccount , error ) {
153+ return k8sClient .CoreV1 ().ServiceAccounts (namespaceName ).Get (ctx , oauthServiceAccountNameFromCluster (foundRayCluster ), metav1.GetOptions {})
154+ }).WithTimeout (time .Second * 10 ).Should (WithTransform (OwnerReferenceKind , Equal ("RayCluster" )))
155+
156+ headPodName := "head-pod"
157+ headPod := & corev1.Pod {
158+ ObjectMeta : metav1.ObjectMeta {
159+ Name : headPodName ,
160+ Namespace : namespaceName ,
161+ Labels : map [string ]string {
162+ "ray.io/node-type" : "head" ,
163+ "ray.io/cluster" : foundRayCluster .Name ,
164+ },
165+ },
166+ Spec : corev1.PodSpec {
167+ Containers : []corev1.Container {
168+ {
169+ Name : "head-container" ,
170+ Image : "busybox" ,
171+ },
172+ },
173+ },
174+ }
175+ _ , err = k8sClient .CoreV1 ().Pods (namespaceName ).Create (ctx , headPod , metav1.CreateOptions {})
176+ Expect (err ).To (Not (HaveOccurred ()))
177+
178+ Eventually (func () (* corev1.Pod , error ) {
179+ return k8sClient .CoreV1 ().Pods (namespaceName ).Get (ctx , headPodName , metav1.GetOptions {})
180+ }).WithTimeout (time .Second * 10 ).ShouldNot (BeNil ())
181+
182+ sa , err := k8sClient .CoreV1 ().ServiceAccounts (namespaceName ).Get (ctx , oauthServiceAccountNameFromCluster (foundRayCluster ), metav1.GetOptions {})
183+ Expect (err ).To (Not (HaveOccurred ()))
184+
185+ sa .ImagePullSecrets = append (sa .ImagePullSecrets , corev1.LocalObjectReference {Name : "test-image-pull-secret" })
186+ _ , err = k8sClient .CoreV1 ().ServiceAccounts (namespaceName ).Update (ctx , sa , metav1.UpdateOptions {})
187+ Expect (err ).To (Not (HaveOccurred ()))
188+
189+ Eventually (func () error {
190+ _ , err := k8sClient .CoreV1 ().Pods (namespaceName ).Get (ctx , headPodName , metav1.GetOptions {})
191+ return err
192+ }).WithTimeout (time .Second * 10 ).Should (Satisfy (errors .IsNotFound ))
193+ })
194+
148195 It ("should remove CRB when the RayCluster is deleted" , func (ctx SpecContext ) {
149196 foundRayCluster , err := rayClient .RayV1 ().RayClusters (namespaceName ).Get (ctx , rayClusterName , metav1.GetOptions {})
150197 Expect (err ).To (Not (HaveOccurred ()))
@@ -157,7 +204,6 @@ var _ = Describe("RayCluster controller", func() {
157204 return err
158205 }).WithTimeout (time .Second * 10 ).Should (Satisfy (errors .IsNotFound ))
159206 })
160-
161207 })
162208})
163209
0 commit comments