From 3b18522c319810b82d8af86a6faf63daf26d9528 Mon Sep 17 00:00:00 2001 From: VaishnaviHire Date: Tue, 14 Jan 2025 23:35:03 +0530 Subject: [PATCH] Update Auth controller tests for RHOAI --- tests/e2e/authcontroller_test.go | 29 ++++++++++++++++++----------- tests/e2e/controller_test.go | 6 ++++++ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/tests/e2e/authcontroller_test.go b/tests/e2e/authcontroller_test.go index 0850cab414f..e31c1da93d7 100644 --- a/tests/e2e/authcontroller_test.go +++ b/tests/e2e/authcontroller_test.go @@ -3,6 +3,7 @@ package e2e_test import ( "errors" "fmt" + "github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster" "testing" "time" @@ -94,8 +95,14 @@ func (tc *AuthControllerTestCtx) validateAuthCRDefaultContent() error { return errors.New("AdminGroups is empty ") } - if tc.testAuthInstance.Spec.AdminGroups[0] != "odh-admins" { - return fmt.Errorf("expected odh-admins, found %v", tc.testAuthInstance.Spec.AdminGroups[0]) + if tc.platform == cluster.SelfManagedRhoai || tc.platform == cluster.ManagedRhoai { + if tc.testAuthInstance.Spec.AdminGroups[0] != "rhods-admins" { + return fmt.Errorf("expected rhods-admins, found %v", tc.testAuthInstance.Spec.AdminGroups[0]) + } + } else { + if tc.testAuthInstance.Spec.AdminGroups[0] != "odh-admins" { + return fmt.Errorf("expected odh-admins, found %v", tc.testAuthInstance.Spec.AdminGroups[0]) + } } if tc.testAuthInstance.Spec.AllowedGroups[0] != "system:authenticated" { @@ -109,11 +116,11 @@ func (tc *AuthControllerTestCtx) validateAuthCRRoleCreation() error { adminRole := &rbacv1.Role{} allowedRole := &rbacv1.Role{} - if err := tc.testContext.customClient.Get(tc.ctx, types.NamespacedName{Namespace: "opendatahub", Name: "admingroup-role"}, adminRole); err != nil { + if err := tc.testContext.customClient.Get(tc.ctx, types.NamespacedName{Namespace: tc.applicationsNamespace, Name: "admingroup-role"}, adminRole); err != nil { return err } - if err := tc.testContext.customClient.Get(tc.ctx, types.NamespacedName{Namespace: "opendatahub", Name: "allowedgroup-role"}, allowedRole); err != nil { + if err := tc.testContext.customClient.Get(tc.ctx, types.NamespacedName{Namespace: tc.applicationsNamespace, Name: "allowedgroup-role"}, allowedRole); err != nil { return err } @@ -123,7 +130,7 @@ func (tc *AuthControllerTestCtx) validateAuthCRRoleCreation() error { func (tc *AuthControllerTestCtx) validateAuthCRClusterRoleCreation() error { adminClusterRole := &rbacv1.ClusterRole{} - if err := tc.testContext.customClient.Get(tc.ctx, types.NamespacedName{Namespace: "opendatahub", Name: "admingroupcluster-role"}, adminClusterRole); err != nil { + if err := tc.testContext.customClient.Get(tc.ctx, types.NamespacedName{Namespace: tc.applicationsNamespace, Name: "admingroupcluster-role"}, adminClusterRole); err != nil { return err } @@ -134,11 +141,11 @@ func (tc *AuthControllerTestCtx) validateAuthCRRoleBindingCreation() error { adminRolebinding := &rbacv1.RoleBinding{} allowedRolebinding := &rbacv1.RoleBinding{} - if err := tc.testContext.customClient.Get(tc.ctx, types.NamespacedName{Namespace: "opendatahub", Name: "admingroup-rolebinding"}, adminRolebinding); err != nil { + if err := tc.testContext.customClient.Get(tc.ctx, types.NamespacedName{Namespace: tc.applicationsNamespace, Name: "admingroup-rolebinding"}, adminRolebinding); err != nil { return err } - if err := tc.testContext.customClient.Get(tc.ctx, types.NamespacedName{Namespace: "opendatahub", Name: "allowedgroup-rolebinding"}, allowedRolebinding); err != nil { + if err := tc.testContext.customClient.Get(tc.ctx, types.NamespacedName{Namespace: tc.applicationsNamespace, Name: "allowedgroup-rolebinding"}, allowedRolebinding); err != nil { return err } @@ -148,7 +155,7 @@ func (tc *AuthControllerTestCtx) validateAuthCRRoleBindingCreation() error { func (tc *AuthControllerTestCtx) validateAuthCRClusterRoleBindingCreation() error { adminClusterRolebinding := &rbacv1.ClusterRoleBinding{} - if err := tc.testContext.customClient.Get(tc.ctx, types.NamespacedName{Namespace: "opendatahub", Name: "admingroupcluster-rolebinding"}, adminClusterRolebinding); err != nil { + if err := tc.testContext.customClient.Get(tc.ctx, types.NamespacedName{Namespace: tc.applicationsNamespace, Name: "admingroupcluster-rolebinding"}, adminClusterRolebinding); err != nil { return err } @@ -167,19 +174,19 @@ func (tc *AuthControllerTestCtx) validateAddingGroups() error { adminClusterRolebinding := &rbacv1.ClusterRoleBinding{} allowedRolebinding := &rbacv1.RoleBinding{} - if err := tc.testContext.customClient.Get(tc.ctx, types.NamespacedName{Namespace: "opendatahub", Name: "admingroup-rolebinding"}, adminRolebinding); err != nil { + if err := tc.testContext.customClient.Get(tc.ctx, types.NamespacedName{Namespace: tc.applicationsNamespace, Name: "admingroup-rolebinding"}, adminRolebinding); err != nil { if adminRolebinding.Subjects[1].Name != "aTestAdminGroup" { return fmt.Errorf("Expected aTestAdminGroup found %s ", adminRolebinding.Subjects[1].Name) } } - if err := tc.testContext.customClient.Get(tc.ctx, types.NamespacedName{Namespace: "opendatahub", Name: "admingroupcluster-rolebinding"}, adminClusterRolebinding); err != nil { + if err := tc.testContext.customClient.Get(tc.ctx, types.NamespacedName{Namespace: tc.applicationsNamespace, Name: "admingroupcluster-rolebinding"}, adminClusterRolebinding); err != nil { if adminRolebinding.Subjects[1].Name != "aTestAdminGroup" { return fmt.Errorf("Expected aTestAdminGroup found %s ", adminRolebinding.Subjects[1].Name) } } - if err := tc.testContext.customClient.Get(tc.ctx, types.NamespacedName{Namespace: "opendatahub", Name: "allowedgroup-rolebinding"}, allowedRolebinding); err != nil { + if err := tc.testContext.customClient.Get(tc.ctx, types.NamespacedName{Namespace: tc.applicationsNamespace, Name: "allowedgroup-rolebinding"}, allowedRolebinding); err != nil { if allowedRolebinding.Subjects[1].Name != "aTestAllowedGroup" { return fmt.Errorf("Expected aTestAllowedGroup found %s ", allowedRolebinding.Subjects[1].Name) } diff --git a/tests/e2e/controller_test.go b/tests/e2e/controller_test.go index e1e58279e22..56751007790 100644 --- a/tests/e2e/controller_test.go +++ b/tests/e2e/controller_test.go @@ -4,6 +4,7 @@ import ( "context" "flag" "fmt" + "github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster" "os" "slices" "strings" @@ -93,6 +94,8 @@ type testContext struct { testDsc *dscv1.DataScienceCluster // test DSCI CR because we do not create it in ODH by default testDSCI *dsciv1.DSCInitialization + // test platform + platform cluster.Platform // context for accessing resources //nolint:containedctx //reason: legacy v1 test setup ctx context.Context @@ -120,6 +123,8 @@ func NewTestContext() (*testContext, error) { return nil, fmt.Errorf("failed to initialize custom client: %w", err) } + release := cluster.GetRelease() + // setup DSCI CR since we do not create automatically by operator testDSCI := setupDSCICR("e2e-test-dsci") // Setup DataScienceCluster CR @@ -134,6 +139,7 @@ func NewTestContext() (*testContext, error) { ctx: context.TODO(), testDsc: testDSC, testDSCI: testDSCI, + platform: release.Name, testOpts: testOpts, }, nil }