From c144e121f34c61ed581d5681a0e3bb4e30206026 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 (cherry picked from commit 3b18522c319810b82d8af86a6faf63daf26d9528) --- tests/e2e/authcontroller_test.go | 31 ++++++++++++++++++++----------- tests/e2e/controller_test.go | 6 ++++++ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/tests/e2e/authcontroller_test.go b/tests/e2e/authcontroller_test.go index 0850cab414f..5aac559022f 100644 --- a/tests/e2e/authcontroller_test.go +++ b/tests/e2e/authcontroller_test.go @@ -11,6 +11,7 @@ import ( "k8s.io/apimachinery/pkg/types" serviceApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/services/v1alpha1" + "github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster" . "github.com/onsi/gomega" ) @@ -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,8 @@ 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 +175,20 @@ 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..785fe7c0e27 100644 --- a/tests/e2e/controller_test.go +++ b/tests/e2e/controller_test.go @@ -31,6 +31,7 @@ import ( dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1" featurev1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/features/v1" serviceApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/services/v1alpha1" + "github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster" ) type TestFn func(t *testing.T) @@ -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 }