@@ -192,6 +192,73 @@ var _ = Describe("RayCluster controller", func() {
192192 }).WithTimeout (time .Second * 10 ).Should (Satisfy (errors .IsNotFound ))
193193 })
194194
195+ It ("should not delete the head pod if RayCluster CR provides image pull secrets" , func (ctx SpecContext ) {
196+ By ("creating an instance of the RayCluster CR with imagePullSecret" )
197+ rayclusterWithPullSecret := & rayv1.RayCluster {
198+ ObjectMeta : metav1.ObjectMeta {
199+ Name : "pull-secret-cluster" ,
200+ Namespace : namespaceName ,
201+ },
202+ Spec : rayv1.RayClusterSpec {
203+ HeadGroupSpec : rayv1.HeadGroupSpec {
204+ Template : corev1.PodTemplateSpec {
205+ Spec : corev1.PodSpec {
206+ ImagePullSecrets : []corev1.LocalObjectReference {{Name : "custom-pull-secret" }},
207+ Containers : []corev1.Container {},
208+ },
209+ },
210+ RayStartParams : map [string ]string {},
211+ },
212+ },
213+ }
214+ _ , err := rayClient .RayV1 ().RayClusters (namespaceName ).Create (ctx , rayclusterWithPullSecret , metav1.CreateOptions {})
215+ Expect (err ).To (Not (HaveOccurred ()))
216+
217+ Eventually (func () (* corev1.ServiceAccount , error ) {
218+ return k8sClient .CoreV1 ().ServiceAccounts (namespaceName ).Get (ctx , oauthServiceAccountNameFromCluster (rayclusterWithPullSecret ), metav1.GetOptions {})
219+ }).WithTimeout (time .Second * 10 ).Should (WithTransform (OwnerReferenceKind , Equal ("RayCluster" )))
220+
221+ headPodName := "head-pod"
222+ headPod := & corev1.Pod {
223+ ObjectMeta : metav1.ObjectMeta {
224+ Name : headPodName ,
225+ Namespace : namespaceName ,
226+ Labels : map [string ]string {
227+ "ray.io/node-type" : "head" ,
228+ "ray.io/cluster" : rayclusterWithPullSecret .Name ,
229+ },
230+ },
231+ Spec : corev1.PodSpec {
232+ ImagePullSecrets : []corev1.LocalObjectReference {
233+ {Name : "custom-pull-secret" },
234+ },
235+ Containers : []corev1.Container {
236+ {
237+ Name : "head-container" ,
238+ Image : "busybox" ,
239+ },
240+ },
241+ },
242+ }
243+ _ , err = k8sClient .CoreV1 ().Pods (namespaceName ).Create (ctx , headPod , metav1.CreateOptions {})
244+ Expect (err ).To (Not (HaveOccurred ()))
245+
246+ Eventually (func () (* corev1.Pod , error ) {
247+ return k8sClient .CoreV1 ().Pods (namespaceName ).Get (ctx , headPodName , metav1.GetOptions {})
248+ }).WithTimeout (time .Second * 10 ).ShouldNot (BeNil ())
249+
250+ sa , err := k8sClient .CoreV1 ().ServiceAccounts (namespaceName ).Get (ctx , oauthServiceAccountNameFromCluster (rayclusterWithPullSecret ), metav1.GetOptions {})
251+ Expect (err ).To (Not (HaveOccurred ()))
252+
253+ sa .ImagePullSecrets = append (sa .ImagePullSecrets , corev1.LocalObjectReference {Name : "test-image-pull-secret" })
254+ _ , err = k8sClient .CoreV1 ().ServiceAccounts (namespaceName ).Update (ctx , sa , metav1.UpdateOptions {})
255+ Expect (err ).To (Not (HaveOccurred ()))
256+
257+ Consistently (func () (* corev1.Pod , error ) {
258+ return k8sClient .CoreV1 ().Pods (namespaceName ).Get (ctx , headPodName , metav1.GetOptions {})
259+ }).WithTimeout (time .Second * 5 ).Should (Not (BeNil ()))
260+ })
261+
195262 It ("should remove CRB when the RayCluster is deleted" , func (ctx SpecContext ) {
196263 foundRayCluster , err := rayClient .RayV1 ().RayClusters (namespaceName ).Get (ctx , rayClusterName , metav1.GetOptions {})
197264 Expect (err ).To (Not (HaveOccurred ()))
0 commit comments