Skip to content

Commit 42a253d

Browse files
authored
Merge pull request opendatahub-io#565 from sutaakar/ray-fix1
Add explicit ServiceAccount creation for Ray notebook tests
2 parents d0f477d + 5b3d223 commit 42a253d

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

tests/odh/mnist_ray_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ func mnistRay(t *testing.T, numGpus int, gpuResourceName string, rayImage string
6868
// Create a namespace
6969
namespace := test.NewTestNamespace()
7070

71+
// Ensure Notebook ServiceAccount exists (no extra RBAC)
72+
ensureNotebookServiceAccount(test, namespace.Name)
73+
7174
// Create Kueue resources
7275
resourceFlavor := CreateKueueResourceFlavor(test, v1beta1.ResourceFlavorSpec{})
7376
defer test.Client().Kueue().KueueV1beta1().ResourceFlavors().Delete(test.Ctx(), resourceFlavor.Name, metav1.DeleteOptions{})

tests/odh/mnist_raytune_hpo_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ func mnistRayTuneHpo(t *testing.T, numGpus int) {
4848
// Creating a namespace
4949
namespace := test.NewTestNamespace()
5050

51+
// Ensure Notebook ServiceAccount exists (no extra RBAC)
52+
ensureNotebookServiceAccount(test, namespace.Name)
53+
5154
// Create Kueue resources
5255
resourceFlavor := CreateKueueResourceFlavor(test, v1beta1.ResourceFlavorSpec{})
5356
defer test.Client().Kueue().KueueV1beta1().ResourceFlavors().Delete(test.Ctx(), resourceFlavor.Name, metav1.DeleteOptions{})

tests/odh/ray_finetune_llm_deepspeed_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ func rayFinetuneLlmDeepspeed(t *testing.T, numGpus int, modelName string, modelC
4848
var workingDirectory, err = os.Getwd()
4949
test.Expect(err).ToNot(HaveOccurred())
5050

51+
// Ensure Notebook ServiceAccount exists (no extra RBAC)
52+
ensureNotebookServiceAccount(test, namespace.Name)
53+
5154
// Define the regular(non-admin) user
5255
userName := GetNotebookUserName(test)
5356
userToken := GetNotebookUserToken(test)

tests/odh/raytune_oai_mr_grpc_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ func raytuneHpo(t *testing.T, numGpus int) {
4848
// Create a namespace
4949
namespace := test.NewTestNamespace()
5050

51+
// Ensure Notebook ServiceAccount exists (no extra RBAC)
52+
ensureNotebookServiceAccount(test, namespace.Name)
53+
5154
// Get current working directory
5255
workingDirectory, err := os.Getwd()
5356
test.Expect(err).ToNot(HaveOccurred())

tests/odh/support.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ import (
2525
gomega "github.com/onsi/gomega"
2626
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
2727

28-
v1 "k8s.io/api/core/v1"
28+
corev1 "k8s.io/api/core/v1"
29+
apierrors "k8s.io/apimachinery/pkg/api/errors"
30+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2931

3032
"github.com/opendatahub-io/distributed-workloads/tests/common/support"
3133
)
@@ -58,7 +60,7 @@ func getNotebookCommand(rayImage string) []string {
5860
}
5961
}
6062

61-
func GetDashboardUrl(test support.Test, namespace *v1.Namespace, rayCluster *rayv1.RayCluster) string {
63+
func GetDashboardUrl(test support.Test, namespace *corev1.Namespace, rayCluster *rayv1.RayCluster) string {
6264
dashboardName := "ray-dashboard-" + rayCluster.Name
6365
route := support.GetRoute(test, namespace.Name, dashboardName)
6466
hostname := route.Status.Ingress[0].Host
@@ -79,6 +81,18 @@ func GetTestJobId(test support.Test, rayClient support.RayClusterClient) string
7981
return jobID
8082
}
8183

84+
// EnsureNotebookServiceAccount ensures the Notebook ServiceAccount exists in the target namespace.
85+
// This avoids webhook/controller failures when creating the Notebook CR.
86+
func ensureNotebookServiceAccount(test support.Test, namespace string) {
87+
test.T().Helper()
88+
saName := "jupyter-nb-kube-3aadmin"
89+
sa := &corev1.ServiceAccount{ObjectMeta: metav1.ObjectMeta{Name: saName, Namespace: namespace}}
90+
_, err := test.Client().Core().CoreV1().ServiceAccounts(namespace).Create(test.Ctx(), sa, metav1.CreateOptions{})
91+
if err != nil && !apierrors.IsAlreadyExists(err) {
92+
test.T().Fatalf("Failed to create ServiceAccount %s/%s: %v", namespace, saName, err)
93+
}
94+
}
95+
8296
// Adds a unique suffix to the provided string
8397
func uniqueSuffix(prefix string) string {
8498
suffix := gonanoid.MustGenerate("1234567890abcdef", 4)

0 commit comments

Comments
 (0)