@@ -10,6 +10,8 @@ import (
1010
1111 rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
1212 "github.com/ray-project/kuberay/ray-operator/controllers/ray/common"
13+ "github.com/ray-project/kuberay/ray-operator/controllers/ray/utils"
14+ rayv1ac "github.com/ray-project/kuberay/ray-operator/pkg/client/applyconfiguration/ray/v1"
1315 . "github.com/ray-project/kuberay/ray-operator/test/support"
1416)
1517
@@ -289,3 +291,72 @@ func TestRayServiceRayClusterDeletionDelaySeconds(t *testing.T) {
289291
290292 waitingForRayClusterSwitchWithDeletionDelay (g , test , newRayService , oldClusterName , 10 * time .Second )
291293}
294+
295+ func TestRayServiceAuthToken (t * testing.T ) {
296+ test := With (t )
297+ g := NewWithT (t )
298+
299+ // Create a namespace
300+ namespace := test .NewTestNamespace ()
301+
302+ // Create the RayService for testing with auth token using programmatic configuration
303+ rayServiceName := "rayservice-auth"
304+ rayServiceSpec := RayServiceSampleYamlApplyConfiguration ()
305+ rayServiceSpec .RayClusterSpec .WithAuthOptions (rayv1ac .AuthOptions ().WithMode (rayv1 .AuthModeToken ))
306+
307+ rayServiceAC := rayv1ac .RayService (rayServiceName , namespace .Name ).WithSpec (rayServiceSpec )
308+
309+ rayService , err := test .Client ().Ray ().RayV1 ().RayServices (namespace .Name ).Apply (test .Ctx (), rayServiceAC , TestApplyOptions )
310+ g .Expect (err ).NotTo (HaveOccurred ())
311+ g .Expect (rayService ).NotTo (BeNil ())
312+ LogWithTimestamp (test .T (), "Created RayService %s/%s successfully with AuthModeToken" , rayService .Namespace , rayService .Name )
313+
314+ // Wait for RayService to be ready
315+ LogWithTimestamp (test .T (), "Waiting for RayService %s/%s to be ready" , rayService .Namespace , rayService .Name )
316+ g .Eventually (RayService (test , rayService .Namespace , rayService .Name ), TestTimeoutMedium ).
317+ Should (WithTransform (IsRayServiceReady , BeTrue ()))
318+
319+ // Get the RayService
320+ rayService , err = GetRayService (test , namespace .Name , rayServiceName )
321+ g .Expect (err ).NotTo (HaveOccurred ())
322+ LogWithTimestamp (test .T (), "RayService %s/%s is ready" , rayService .Namespace , rayService .Name )
323+
324+ // Get the underlying RayCluster of the RayService
325+ rayClusterName := rayService .Status .ActiveServiceStatus .RayClusterName
326+ g .Expect (rayClusterName ).NotTo (BeEmpty (), "RayCluster name should be populated" )
327+ LogWithTimestamp (test .T (), "RayService %s/%s has active RayCluster %s" , rayService .Namespace , rayService .Name , rayClusterName )
328+
329+ // Wait for the RayCluster to become ready
330+ LogWithTimestamp (test .T (), "Waiting for RayCluster %s/%s to become ready" , namespace .Name , rayClusterName )
331+ g .Eventually (RayCluster (test , namespace .Name , rayClusterName ), TestTimeoutMedium ).
332+ Should (WithTransform (RayClusterState , Equal (rayv1 .Ready )))
333+
334+ rayCluster , err := GetRayCluster (test , namespace .Name , rayClusterName )
335+ g .Expect (err ).NotTo (HaveOccurred ())
336+
337+ // Verify the head pod has auth token environment variables
338+ headPod , err := GetHeadPod (test , rayCluster )
339+ g .Expect (err ).NotTo (HaveOccurred ())
340+ g .Expect (headPod ).NotTo (BeNil ())
341+ LogWithTimestamp (test .T (), "Found head pod %s/%s" , headPod .Namespace , headPod .Name )
342+
343+ // Verify Ray container has auth token env vars
344+ VerifyContainerAuthTokenEnvVars (test , rayCluster , & headPod .Spec .Containers [utils .RayContainerIndex ])
345+ LogWithTimestamp (test .T (), "Verified auth token env vars in head pod Ray container" )
346+
347+ // Verify worker pods have auth token env vars
348+ workerPods , err := GetWorkerPods (test , rayCluster )
349+ g .Expect (err ).NotTo (HaveOccurred ())
350+ g .Expect (workerPods ).ToNot (BeEmpty (), "RayCluster should have at least one worker pod" )
351+ LogWithTimestamp (test .T (), "Found %d worker pod(s)" , len (workerPods ))
352+
353+ for _ , workerPod := range workerPods {
354+ VerifyContainerAuthTokenEnvVars (test , rayCluster , & workerPod .Spec .Containers [utils .RayContainerIndex ])
355+ LogWithTimestamp (test .T (), "Verified auth token env vars in worker pod %s/%s" , workerPod .Namespace , workerPod .Name )
356+ }
357+
358+ // Clean up the RayService
359+ err = test .Client ().Ray ().RayV1 ().RayServices (namespace .Name ).Delete (test .Ctx (), rayService .Name , metav1.DeleteOptions {})
360+ g .Expect (err ).NotTo (HaveOccurred ())
361+ LogWithTimestamp (test .T (), "Deleted RayService %s/%s successfully" , rayService .Namespace , rayService .Name )
362+ }
0 commit comments