Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions ray-operator/test/e2erayservice/rayservice_auth_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package e2erayservice

import (
"testing"

. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
"github.com/ray-project/kuberay/ray-operator/controllers/ray/utils"
rayv1ac "github.com/ray-project/kuberay/ray-operator/pkg/client/applyconfiguration/ray/v1"
. "github.com/ray-project/kuberay/ray-operator/test/support"
)

func TestRayServiceAuthToken(t *testing.T) {
test := With(t)
g := NewWithT(t)

namespace := test.NewTestNamespace()

rayServiceName := "rayservice-auth"
rayServiceSpec := RayServiceSampleYamlApplyConfiguration()
rayServiceSpec.RayClusterSpec.WithAuthOptions(rayv1ac.AuthOptions().WithMode(rayv1.AuthModeToken))

rayServiceAC := rayv1ac.RayService(rayServiceName, namespace.Name).WithSpec(rayServiceSpec)

rayService, err := test.Client().Ray().RayV1().RayServices(namespace.Name).Apply(test.Ctx(), rayServiceAC, TestApplyOptions)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(rayService).NotTo(BeNil())
LogWithTimestamp(test.T(), "Created RayService %s/%s successfully with AuthModeToken", rayService.Namespace, rayService.Name)

defer func() {
err := test.Client().Ray().RayV1().RayServices(namespace.Name).Delete(test.Ctx(), rayService.Name, metav1.DeleteOptions{})
if err != nil {
LogWithTimestamp(test.T(), "WARNING: Failed to delete RayService %s: %v", rayService.Name, err)
} else {
LogWithTimestamp(test.T(), "Deleted RayService %s/%s successfully", rayService.Namespace, rayService.Name)
}
}()

LogWithTimestamp(test.T(), "Waiting for RayService %s/%s to be ready", rayService.Namespace, rayService.Name)
g.Eventually(RayService(test, rayService.Namespace, rayService.Name), TestTimeoutMedium).
Should(WithTransform(IsRayServiceReady, BeTrue()))

rayService, err = GetRayService(test, namespace.Name, rayServiceName)
g.Expect(err).NotTo(HaveOccurred())
LogWithTimestamp(test.T(), "RayService %s/%s is ready", rayService.Namespace, rayService.Name)

rayClusterName := rayService.Status.ActiveServiceStatus.RayClusterName
g.Expect(rayClusterName).NotTo(BeEmpty(), "RayCluster name should be populated in status")
LogWithTimestamp(test.T(), "RayService %s/%s has active RayCluster %s", rayService.Namespace, rayService.Name, rayClusterName)

rayCluster, err := GetRayCluster(test, namespace.Name, rayClusterName)
g.Expect(err).NotTo(HaveOccurred())

headPod, err := GetHeadPod(test, rayCluster)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(headPod).NotTo(BeNil())
LogWithTimestamp(test.T(), "Found head pod %s/%s", headPod.Namespace, headPod.Name)

// Verify Ray container has auth token env vars
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Verify Ray container has auth token env vars
// Verify Ray container has auth token env vars
g.Expect(len(headPod.Spec.Containers)).To(BeNumerically(">", utils.RayContainerIndex),
"Head pod should have at least %d containers", utils.RayContainerIndex+1)

How about adding a container bounds checking?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think current implementation is good enough, thank you for the review!

VerifyContainerAuthTokenEnvVars(test, rayCluster, &headPod.Spec.Containers[utils.RayContainerIndex])

g.Expect(rayService.Status.NumServeEndpoints).To(BeNumerically(">", 0),
"RayService should have at least one serve endpoint")

LogWithTimestamp(test.T(), "RayService %s/%s completed successfully with auth token", rayService.Namespace, rayService.Name)
}
Loading