From f4684d2520c76e60650ba383cd696e5891e6df38 Mon Sep 17 00:00:00 2001 From: Lukas Krejci Date: Wed, 28 May 2025 15:43:15 +0200 Subject: [PATCH 1/9] test for the bundled ns template tiers being annotated as such --- crc | 1 + test/e2e/parallel/nstemplatetier_test.go | 5 ++- test/migration/setup/setup_migration_test.go | 7 ++++ .../migration/verify/verify_migration_test.go | 25 ++++++++++++++ testsupport/init.go | 34 +++++++++++-------- testsupport/signup_request.go | 1 + testsupport/space/space.go | 2 +- testsupport/wait/host.go | 1 + testsupport/wait/stringify.go | 9 +++++ 9 files changed, 66 insertions(+), 19 deletions(-) create mode 100644 crc diff --git a/crc b/crc new file mode 100644 index 000000000..9209f6df0 --- /dev/null +++ b/crc @@ -0,0 +1 @@ +y delete diff --git a/test/e2e/parallel/nstemplatetier_test.go b/test/e2e/parallel/nstemplatetier_test.go index bcb912e16..8c8efb568 100644 --- a/test/e2e/parallel/nstemplatetier_test.go +++ b/test/e2e/parallel/nstemplatetier_test.go @@ -18,6 +18,7 @@ import ( toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" "github.com/codeready-toolchain/toolchain-common/pkg/states" testspace "github.com/codeready-toolchain/toolchain-common/pkg/test/space" + "github.com/codeready-toolchain/toolchain-e2e/testsupport" . "github.com/codeready-toolchain/toolchain-e2e/testsupport" . "github.com/codeready-toolchain/toolchain-e2e/testsupport/space" "github.com/codeready-toolchain/toolchain-e2e/testsupport/tiers" @@ -50,7 +51,7 @@ func TestNSTemplateTiers(t *testing.T) { space := user.Space // all tiers to check - keep the base as the last one, it will verify downgrade back to the default tier at the end of the test - tiersToCheck := []string{"advanced", "baseextendedidling", "baselarge", "test", "appstudio", "appstudiolarge", "appstudio-env", "base1ns", "base1nsnoidling", "base1ns6didler", "intelmedium", "intellarge", "intelxlarge", "base"} + tiersToCheck := testsupport.E2eNSTemplateTiers // when the tiers are created during the startup then we can verify them allTiers := &toolchainv1alpha1.NSTemplateTierList{} @@ -479,7 +480,6 @@ func TestTierTemplateRevision(t *testing.T) { Value: "100", }) }) - }) t.Run("when updating one tiertemplate the revisions field should be cleaned up from old entries", func(t *testing.T) { @@ -517,7 +517,6 @@ func TestTierTemplateRevision(t *testing.T) { // revisions values should be different compared to the previous ones assert.NotEqual(t, revisionsBeforeUpdate, updatedTier.Status.Revisions) }) - } func getTestCRQ(podsCount string) unstructured.Unstructured { diff --git a/test/migration/setup/setup_migration_test.go b/test/migration/setup/setup_migration_test.go index 77fc6f781..6fe263e23 100644 --- a/test/migration/setup/setup_migration_test.go +++ b/test/migration/setup/setup_migration_test.go @@ -1,6 +1,7 @@ package setup import ( + "os" "testing" "github.com/codeready-toolchain/toolchain-e2e/test/migration" @@ -8,6 +9,12 @@ import ( ) func TestSetupMigration(t *testing.T) { + os.Setenv("HOST_NS", "toolchain-host") + os.Setenv("MEMBER_NS", "toolchain-member") + os.Setenv("MEMBER_NS_2", "toolchain-member2") + os.Setenv("SECOND_MEMBER_MODE", "true") + os.Setenv("REGISTRATION_SERVICE_NS", "toolchain-host") + // given awaitilities := WaitForOperators(t) diff --git a/test/migration/verify/verify_migration_test.go b/test/migration/verify/verify_migration_test.go index 49bdc93e8..faf732e5e 100644 --- a/test/migration/verify/verify_migration_test.go +++ b/test/migration/verify/verify_migration_test.go @@ -3,6 +3,7 @@ package verify import ( "context" "fmt" + "slices" "sync" "testing" "time" @@ -12,6 +13,7 @@ import ( "github.com/codeready-toolchain/toolchain-common/pkg/hash" "github.com/codeready-toolchain/toolchain-common/pkg/states" "github.com/codeready-toolchain/toolchain-e2e/test/migration" + "github.com/codeready-toolchain/toolchain-e2e/testsupport" . "github.com/codeready-toolchain/toolchain-e2e/testsupport" "github.com/codeready-toolchain/toolchain-e2e/testsupport/cleanup" . "github.com/codeready-toolchain/toolchain-e2e/testsupport/space" @@ -20,6 +22,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -95,6 +98,7 @@ func runVerifyFunctions(t *testing.T, awaitilities wait.Awaitilities) { func() { verifyDeactivatedSignup(t, awaitilities, deactivatedSignup) }, func() { verifyBannedSignup(t, awaitilities, bannedSignup) }, func() { verifyAdditionalDeploymentsCreatedUsingSSA(t, &awaitilities) }, + func() { verifyBundledNSTemplateTiersAnnotated(t, &awaitilities) }, } // when & then - run all functions in parallel @@ -270,6 +274,27 @@ func verifyAdditionalDeploymentsCreatedUsingSSA(t *testing.T, awaitilities *wait }) } +func verifyBundledNSTemplateTiersAnnotated(t *testing.T, awaitilities *wait.Awaitilities) { + list := &toolchainv1alpha1.NSTemplateTierList{} + require.NoError(t, awaitilities.Host().Client.List(context.TODO(), list, client.InNamespace(awaitilities.Host().Namespace))) + + // e2e tests have custom appstudio tiers + assert.GreaterOrEqual(t, len(list.Items), len(testsupport.BundledNSTemplateTiers)) + + unmatchedBundledTiers := make([]string, len(testsupport.BundledNSTemplateTiers)) + copy(unmatchedBundledTiers, testsupport.BundledNSTemplateTiers) + + for _, tier := range list.Items { + if tier.Annotations[toolchainv1alpha1.BundledAnnotationKey] == "host-operator" { + if i := slices.Index(unmatchedBundledTiers, tier.Name); i >= 0 { + unmatchedBundledTiers = slices.Delete(unmatchedBundledTiers, i, i+1) + } + } + } + + assert.Empty(t, unmatchedBundledTiers) +} + func checkMURMigratedAndGetSignup(t *testing.T, hostAwait *wait.HostAwaitility, murName string) *toolchainv1alpha1.UserSignup { provisionedMur, err := hostAwait.WithRetryOptions(wait.TimeoutOption(time.Second*120)).WaitForMasterUserRecord(t, murName, wait.UntilMasterUserRecordHasCondition(wait.Provisioned()), diff --git a/testsupport/init.go b/testsupport/init.go index 5409f7af4..3cbe5a9a6 100644 --- a/testsupport/init.go +++ b/testsupport/init.go @@ -43,10 +43,12 @@ import ( ) var ( - initHostAwait *wait.HostAwaitility - initMemberAwait *wait.MemberAwaitility - initMember2Await *wait.MemberAwaitility - initOnce sync.Once + initHostAwait *wait.HostAwaitility + initMemberAwait *wait.MemberAwaitility + initMember2Await *wait.MemberAwaitility + initOnce sync.Once + BundledNSTemplateTiers []string = []string{"advanced", "baseextendedidling", "baselarge", "test", "base1ns", "base1nsnoidling", "base1ns6didler", "intelmedium", "intellarge", "intelxlarge", "base"} + E2eNSTemplateTiers []string = append(BundledNSTemplateTiers, "appstudio", "appstudiolarge", "appstudio-env") ) // WaitForOperators initializes test context, registers schemes and waits until both operators (host, member) @@ -59,6 +61,7 @@ func WaitForOperators(t *testing.T) wait.Awaitilities { }) return wait.NewAwaitilities(initHostAwait, initMemberAwait, initMember2Await) } + func waitForOperators(t *testing.T) { memberNs := os.Getenv(wait.MemberNsVar) memberNs2 := os.Getenv(wait.MemberNsVar2) @@ -82,7 +85,7 @@ func waitForOperators(t *testing.T) { }) require.NoError(t, err) - //updating the kubeconfig with the bearer token created + // updating the kubeconfig with the bearer token created kubeconfig.BearerToken = getE2EServiceAccountToken(t, hostNs, apiConfig, cl) initHostAwait = wait.NewHostAwaitility(kubeconfig, cl, hostNs, registrationServiceNs) @@ -120,7 +123,7 @@ func waitForOperators(t *testing.T) { func getE2EServiceAccountToken(t *testing.T, hostNs string, apiConfigsa *api.Config, sacl client.Client) string { // creating another config which is used for creating only resclient, - //so that the main kubeconfig is not altered + // so that the main kubeconfig is not altered restkubeconfig, err := util.BuildKubernetesRESTConfig(*apiConfigsa) require.NoError(t, err) @@ -132,7 +135,9 @@ func getE2EServiceAccountToken(t *testing.T, hostNs string, apiConfigsa *api.Con err := sacl.Create(context.TODO(), &corev1.ServiceAccount{ ObjectMeta: metav1.ObjectMeta{ Name: "e2e-test", - Namespace: hostNs}}) + Namespace: hostNs, + }, + }) require.NoError(t, err, "Error in creating Service account for e2e test") } else if err != nil { require.NoError(t, err, "Error fetching service accounts") @@ -166,18 +171,17 @@ func getE2EServiceAccountToken(t *testing.T, hostNs string, apiConfigsa *api.Con require.NoError(t, err, "Error fetching clusterrolebinding") } - //upating the restkubeconfig ,which requires groupversion to create restclient - restkubeconfig.ContentConfig = - rest.ContentConfig{ - GroupVersion: &authv1.SchemeGroupVersion, - NegotiatedSerializer: scheme.Codecs, - } + // upating the restkubeconfig ,which requires groupversion to create restclient + restkubeconfig.ContentConfig = rest.ContentConfig{ + GroupVersion: &authv1.SchemeGroupVersion, + NegotiatedSerializer: scheme.Codecs, + } - //Creating a Restclient to be used in creation and checking of bearer token required for authentication + // Creating a Restclient to be used in creation and checking of bearer token required for authentication rclient, err := rest.RESTClientFor(restkubeconfig) require.NoError(t, err, "Error in creating restclient") - //Creating a bearer token to be used for authentication(which is valid for 24 hrs) + // Creating a bearer token to be used for authentication(which is valid for 24 hrs) bt, err := toolchaincommon.CreateTokenRequest(context.TODO(), rclient, types.NamespacedName{Namespace: hostNs, Name: "e2e-test"}, 86400) require.NoError(t, err, "Error in creating Token") return bt diff --git a/testsupport/signup_request.go b/testsupport/signup_request.go index 862bf0d74..d9442a96d 100644 --- a/testsupport/signup_request.go +++ b/testsupport/signup_request.go @@ -310,6 +310,7 @@ func (r *SignupRequest) Execute(t *testing.T) *SignupResult { r.mur = mur } + t.Logf("Cleanup for the usersignup '%s' is disabled: %v", &userSignup.Name, r.cleanupDisabled) // We also need to ensure that the UserSignup is deleted at the end of the test (if the test itself doesn't delete it) // and if cleanup hasn't been disabled if !r.cleanupDisabled { diff --git a/testsupport/space/space.go b/testsupport/space/space.go index 0ad1e3e28..afb2a46ee 100644 --- a/testsupport/space/space.go +++ b/testsupport/space/space.go @@ -180,7 +180,7 @@ func CreateMurWithAdminSpaceBindingForSpace(t *testing.T, awaitilities wait.Awai user := builder.Execute(t) signup := user.UserSignup mur := user.MUR - t.Logf("The UserSignup %s and MUR %s were created", signup.Name, mur.Name) + t.Logf("The UserSignup %s and MUR %s were created", wait.SafeStringifyObject(signup), wait.SafeStringifyObject(mur)) var binding *toolchainv1alpha1.SpaceBinding if cleanup { binding = testsupportsb.CreateSpaceBinding(t, awaitilities.Host(), mur, space, "admin") diff --git a/testsupport/wait/host.go b/testsupport/wait/host.go index 104b03815..9f53abf40 100644 --- a/testsupport/wait/host.go +++ b/testsupport/wait/host.go @@ -649,6 +649,7 @@ func (a *HostAwaitility) WaitForUserSignup(t *testing.T, name string, criteria . if err != nil { a.printUserSignupWaitCriterionDiffs(t, userSignup, criteria...) } + t.Logf("UserSignup matching the criteria found: %v", SafeStringifyObject(userSignup)) return userSignup, err } diff --git a/testsupport/wait/stringify.go b/testsupport/wait/stringify.go index 1a7729c15..4b0bdb16d 100644 --- a/testsupport/wait/stringify.go +++ b/testsupport/wait/stringify.go @@ -1,6 +1,7 @@ package wait import ( + "fmt" "reflect" "github.com/ghodss/yaml" @@ -9,6 +10,14 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) +func SafeStringifyObject(obj client.Object) string { + yaml, err := StringifyObject(obj) + if err != nil { + return fmt.Sprintf("<<< strigification failed with: %s >>>", err.Error()) + } + return string(yaml) +} + // StringifyObject renders the object in YAML while omitting the soup of `metadata.managedFields` func StringifyObject(obj client.Object) ([]byte, error) { uObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj) From fb115bdaae33d5bf3b35fe07dd1bdafbfda69fe9 Mon Sep 17 00:00:00 2001 From: Lukas Krejci Date: Thu, 5 Jun 2025 17:05:52 +0200 Subject: [PATCH 2/9] remove the debugging code --- test/migration/setup/setup_migration_test.go | 7 ------- testsupport/signup_request.go | 1 - testsupport/space/space.go | 2 +- testsupport/wait/host.go | 1 - testsupport/wait/stringify.go | 9 --------- 5 files changed, 1 insertion(+), 19 deletions(-) diff --git a/test/migration/setup/setup_migration_test.go b/test/migration/setup/setup_migration_test.go index 6fe263e23..77fc6f781 100644 --- a/test/migration/setup/setup_migration_test.go +++ b/test/migration/setup/setup_migration_test.go @@ -1,7 +1,6 @@ package setup import ( - "os" "testing" "github.com/codeready-toolchain/toolchain-e2e/test/migration" @@ -9,12 +8,6 @@ import ( ) func TestSetupMigration(t *testing.T) { - os.Setenv("HOST_NS", "toolchain-host") - os.Setenv("MEMBER_NS", "toolchain-member") - os.Setenv("MEMBER_NS_2", "toolchain-member2") - os.Setenv("SECOND_MEMBER_MODE", "true") - os.Setenv("REGISTRATION_SERVICE_NS", "toolchain-host") - // given awaitilities := WaitForOperators(t) diff --git a/testsupport/signup_request.go b/testsupport/signup_request.go index d9442a96d..862bf0d74 100644 --- a/testsupport/signup_request.go +++ b/testsupport/signup_request.go @@ -310,7 +310,6 @@ func (r *SignupRequest) Execute(t *testing.T) *SignupResult { r.mur = mur } - t.Logf("Cleanup for the usersignup '%s' is disabled: %v", &userSignup.Name, r.cleanupDisabled) // We also need to ensure that the UserSignup is deleted at the end of the test (if the test itself doesn't delete it) // and if cleanup hasn't been disabled if !r.cleanupDisabled { diff --git a/testsupport/space/space.go b/testsupport/space/space.go index afb2a46ee..0ad1e3e28 100644 --- a/testsupport/space/space.go +++ b/testsupport/space/space.go @@ -180,7 +180,7 @@ func CreateMurWithAdminSpaceBindingForSpace(t *testing.T, awaitilities wait.Awai user := builder.Execute(t) signup := user.UserSignup mur := user.MUR - t.Logf("The UserSignup %s and MUR %s were created", wait.SafeStringifyObject(signup), wait.SafeStringifyObject(mur)) + t.Logf("The UserSignup %s and MUR %s were created", signup.Name, mur.Name) var binding *toolchainv1alpha1.SpaceBinding if cleanup { binding = testsupportsb.CreateSpaceBinding(t, awaitilities.Host(), mur, space, "admin") diff --git a/testsupport/wait/host.go b/testsupport/wait/host.go index 9f53abf40..104b03815 100644 --- a/testsupport/wait/host.go +++ b/testsupport/wait/host.go @@ -649,7 +649,6 @@ func (a *HostAwaitility) WaitForUserSignup(t *testing.T, name string, criteria . if err != nil { a.printUserSignupWaitCriterionDiffs(t, userSignup, criteria...) } - t.Logf("UserSignup matching the criteria found: %v", SafeStringifyObject(userSignup)) return userSignup, err } diff --git a/testsupport/wait/stringify.go b/testsupport/wait/stringify.go index 4b0bdb16d..1a7729c15 100644 --- a/testsupport/wait/stringify.go +++ b/testsupport/wait/stringify.go @@ -1,7 +1,6 @@ package wait import ( - "fmt" "reflect" "github.com/ghodss/yaml" @@ -10,14 +9,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -func SafeStringifyObject(obj client.Object) string { - yaml, err := StringifyObject(obj) - if err != nil { - return fmt.Sprintf("<<< strigification failed with: %s >>>", err.Error()) - } - return string(yaml) -} - // StringifyObject renders the object in YAML while omitting the soup of `metadata.managedFields` func StringifyObject(obj client.Object) ([]byte, error) { uObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj) From dfd75a251a949bd975506a1396e5d1a09d83a642 Mon Sep 17 00:00:00 2001 From: Lukas Krejci Date: Thu, 5 Jun 2025 17:11:40 +0200 Subject: [PATCH 3/9] remove the accidental file --- crc | 1 - 1 file changed, 1 deletion(-) delete mode 100644 crc diff --git a/crc b/crc deleted file mode 100644 index 9209f6df0..000000000 --- a/crc +++ /dev/null @@ -1 +0,0 @@ -y delete From b131f46a6224587b32016cf4677c9a6fd2376c61 Mon Sep 17 00:00:00 2001 From: Lukas Krejci Date: Thu, 5 Jun 2025 17:22:21 +0200 Subject: [PATCH 4/9] use the latest api --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index eea481642..5c1a4e2ba 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,7 @@ module github.com/codeready-toolchain/toolchain-e2e require ( - github.com/codeready-toolchain/api v0.0.0-20250506092100-39b4862e1271 + github.com/codeready-toolchain/api v0.0.0-20250605152105-383ffe6cac27 github.com/codeready-toolchain/toolchain-common v0.0.0-20250506093954-2b65ad3a2e12 github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc github.com/fatih/color v1.18.0 diff --git a/go.sum b/go.sum index 1e33e988d..7603f4c89 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I= github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU= github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA= -github.com/codeready-toolchain/api v0.0.0-20250506092100-39b4862e1271 h1:AHrFr/aPuJ4+0zHw4sFXcfMA92kChy12JAPS5bLODlw= -github.com/codeready-toolchain/api v0.0.0-20250506092100-39b4862e1271/go.mod h1:20258od6i5+jP406Z76YaI2ow/vc7URwsDU2bokpkRE= +github.com/codeready-toolchain/api v0.0.0-20250605152105-383ffe6cac27 h1:g1ivSPPHTC96RHp8S/gRmqODWgoHyivq+/d5kSI0pEs= +github.com/codeready-toolchain/api v0.0.0-20250605152105-383ffe6cac27/go.mod h1:20258od6i5+jP406Z76YaI2ow/vc7URwsDU2bokpkRE= github.com/codeready-toolchain/toolchain-common v0.0.0-20250506093954-2b65ad3a2e12 h1:w54sojJJ8PsHZzK1mC+/EUBrQ9F2sC/k7JUVc8LSqK4= github.com/codeready-toolchain/toolchain-common v0.0.0-20250506093954-2b65ad3a2e12/go.mod h1:TrMvD0sP69wI6Rouzfs7OsOUSj4CGn/ZiIdiDBAFQjk= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= From 4edae30c1383f0dce945f70b6551ea6d64e33c33 Mon Sep 17 00:00:00 2001 From: Lukas Krejci Date: Tue, 10 Jun 2025 14:14:00 +0200 Subject: [PATCH 5/9] move the constants listing the expected NSTemplateTiers to a more logical location --- test/e2e/parallel/nstemplatetier_test.go | 3 +-- test/migration/verify/verify_migration_test.go | 7 +++---- testsupport/init.go | 10 ++++------ testsupport/wait/host.go | 5 +++++ 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/test/e2e/parallel/nstemplatetier_test.go b/test/e2e/parallel/nstemplatetier_test.go index 8c8efb568..2af8040c9 100644 --- a/test/e2e/parallel/nstemplatetier_test.go +++ b/test/e2e/parallel/nstemplatetier_test.go @@ -18,7 +18,6 @@ import ( toolchainv1alpha1 "github.com/codeready-toolchain/api/api/v1alpha1" "github.com/codeready-toolchain/toolchain-common/pkg/states" testspace "github.com/codeready-toolchain/toolchain-common/pkg/test/space" - "github.com/codeready-toolchain/toolchain-e2e/testsupport" . "github.com/codeready-toolchain/toolchain-e2e/testsupport" . "github.com/codeready-toolchain/toolchain-e2e/testsupport/space" "github.com/codeready-toolchain/toolchain-e2e/testsupport/tiers" @@ -51,7 +50,7 @@ func TestNSTemplateTiers(t *testing.T) { space := user.Space // all tiers to check - keep the base as the last one, it will verify downgrade back to the default tier at the end of the test - tiersToCheck := testsupport.E2eNSTemplateTiers + tiersToCheck := wait.E2eNSTemplateTiersInHost // when the tiers are created during the startup then we can verify them allTiers := &toolchainv1alpha1.NSTemplateTierList{} diff --git a/test/migration/verify/verify_migration_test.go b/test/migration/verify/verify_migration_test.go index faf732e5e..606cbeebc 100644 --- a/test/migration/verify/verify_migration_test.go +++ b/test/migration/verify/verify_migration_test.go @@ -13,7 +13,6 @@ import ( "github.com/codeready-toolchain/toolchain-common/pkg/hash" "github.com/codeready-toolchain/toolchain-common/pkg/states" "github.com/codeready-toolchain/toolchain-e2e/test/migration" - "github.com/codeready-toolchain/toolchain-e2e/testsupport" . "github.com/codeready-toolchain/toolchain-e2e/testsupport" "github.com/codeready-toolchain/toolchain-e2e/testsupport/cleanup" . "github.com/codeready-toolchain/toolchain-e2e/testsupport/space" @@ -279,10 +278,10 @@ func verifyBundledNSTemplateTiersAnnotated(t *testing.T, awaitilities *wait.Awai require.NoError(t, awaitilities.Host().Client.List(context.TODO(), list, client.InNamespace(awaitilities.Host().Namespace))) // e2e tests have custom appstudio tiers - assert.GreaterOrEqual(t, len(list.Items), len(testsupport.BundledNSTemplateTiers)) + assert.GreaterOrEqual(t, len(list.Items), len(wait.BundledNSTemplateTiersInHost)) - unmatchedBundledTiers := make([]string, len(testsupport.BundledNSTemplateTiers)) - copy(unmatchedBundledTiers, testsupport.BundledNSTemplateTiers) + unmatchedBundledTiers := make([]string, len(wait.BundledNSTemplateTiersInHost)) + copy(unmatchedBundledTiers, wait.BundledNSTemplateTiersInHost) for _, tier := range list.Items { if tier.Annotations[toolchainv1alpha1.BundledAnnotationKey] == "host-operator" { diff --git a/testsupport/init.go b/testsupport/init.go index 3cbe5a9a6..0f4ade7b7 100644 --- a/testsupport/init.go +++ b/testsupport/init.go @@ -43,12 +43,10 @@ import ( ) var ( - initHostAwait *wait.HostAwaitility - initMemberAwait *wait.MemberAwaitility - initMember2Await *wait.MemberAwaitility - initOnce sync.Once - BundledNSTemplateTiers []string = []string{"advanced", "baseextendedidling", "baselarge", "test", "base1ns", "base1nsnoidling", "base1ns6didler", "intelmedium", "intellarge", "intelxlarge", "base"} - E2eNSTemplateTiers []string = append(BundledNSTemplateTiers, "appstudio", "appstudiolarge", "appstudio-env") + initHostAwait *wait.HostAwaitility + initMemberAwait *wait.MemberAwaitility + initMember2Await *wait.MemberAwaitility + initOnce sync.Once ) // WaitForOperators initializes test context, registers schemes and waits until both operators (host, member) diff --git a/testsupport/wait/host.go b/testsupport/wait/host.go index 104b03815..87eb5bc69 100644 --- a/testsupport/wait/host.go +++ b/testsupport/wait/host.go @@ -49,6 +49,11 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) +var ( + BundledNSTemplateTiersInHost []string = []string{"advanced", "baseextendedidling", "baselarge", "test", "base1ns", "base1nsnoidling", "base1ns6didler", "intelmedium", "intellarge", "intelxlarge", "base"} + E2eNSTemplateTiersInHost []string = append(BundledNSTemplateTiersInHost, "appstudio", "appstudiolarge", "appstudio-env") +) + // HostAwaitility the Awaitility for the Host cluster type HostAwaitility struct { *Awaitility From 6ad8e8675466e2b5c314937584f4537eb29978e6 Mon Sep 17 00:00:00 2001 From: Lukas Krejci Date: Tue, 10 Jun 2025 14:27:54 +0200 Subject: [PATCH 6/9] drop the InHost suffix - nstemplatetiers are only in host, so no need for that --- test/e2e/parallel/nstemplatetier_test.go | 2 +- test/migration/verify/verify_migration_test.go | 6 +++--- testsupport/wait/host.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/e2e/parallel/nstemplatetier_test.go b/test/e2e/parallel/nstemplatetier_test.go index 2af8040c9..f950cde2e 100644 --- a/test/e2e/parallel/nstemplatetier_test.go +++ b/test/e2e/parallel/nstemplatetier_test.go @@ -50,7 +50,7 @@ func TestNSTemplateTiers(t *testing.T) { space := user.Space // all tiers to check - keep the base as the last one, it will verify downgrade back to the default tier at the end of the test - tiersToCheck := wait.E2eNSTemplateTiersInHost + tiersToCheck := wait.E2eNSTemplateTiers // when the tiers are created during the startup then we can verify them allTiers := &toolchainv1alpha1.NSTemplateTierList{} diff --git a/test/migration/verify/verify_migration_test.go b/test/migration/verify/verify_migration_test.go index 606cbeebc..836c797a7 100644 --- a/test/migration/verify/verify_migration_test.go +++ b/test/migration/verify/verify_migration_test.go @@ -278,10 +278,10 @@ func verifyBundledNSTemplateTiersAnnotated(t *testing.T, awaitilities *wait.Awai require.NoError(t, awaitilities.Host().Client.List(context.TODO(), list, client.InNamespace(awaitilities.Host().Namespace))) // e2e tests have custom appstudio tiers - assert.GreaterOrEqual(t, len(list.Items), len(wait.BundledNSTemplateTiersInHost)) + assert.GreaterOrEqual(t, len(list.Items), len(wait.BundledNSTemplateTiers)) - unmatchedBundledTiers := make([]string, len(wait.BundledNSTemplateTiersInHost)) - copy(unmatchedBundledTiers, wait.BundledNSTemplateTiersInHost) + unmatchedBundledTiers := make([]string, len(wait.BundledNSTemplateTiers)) + copy(unmatchedBundledTiers, wait.BundledNSTemplateTiers) for _, tier := range list.Items { if tier.Annotations[toolchainv1alpha1.BundledAnnotationKey] == "host-operator" { diff --git a/testsupport/wait/host.go b/testsupport/wait/host.go index 87eb5bc69..5e843ad9c 100644 --- a/testsupport/wait/host.go +++ b/testsupport/wait/host.go @@ -50,8 +50,8 @@ import ( ) var ( - BundledNSTemplateTiersInHost []string = []string{"advanced", "baseextendedidling", "baselarge", "test", "base1ns", "base1nsnoidling", "base1ns6didler", "intelmedium", "intellarge", "intelxlarge", "base"} - E2eNSTemplateTiersInHost []string = append(BundledNSTemplateTiersInHost, "appstudio", "appstudiolarge", "appstudio-env") + BundledNSTemplateTiers []string = []string{"advanced", "baseextendedidling", "baselarge", "test", "base1ns", "base1nsnoidling", "base1ns6didler", "intelmedium", "intellarge", "intelxlarge", "base"} + E2eNSTemplateTiers []string = append(BundledNSTemplateTiers, "appstudio", "appstudiolarge", "appstudio-env") ) // HostAwaitility the Awaitility for the Host cluster From 57590326aad6dbcc148ce42c745133ed55caf95d Mon Sep 17 00:00:00 2001 From: Lukas Krejci Date: Tue, 10 Jun 2025 14:43:07 +0200 Subject: [PATCH 7/9] the bundled tiers now only have a finalizer, not an annotation --- test/migration/verify/verify_migration_test.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/migration/verify/verify_migration_test.go b/test/migration/verify/verify_migration_test.go index 836c797a7..17eaa1ad8 100644 --- a/test/migration/verify/verify_migration_test.go +++ b/test/migration/verify/verify_migration_test.go @@ -24,6 +24,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" ) func TestAfterMigration(t *testing.T) { @@ -97,7 +98,7 @@ func runVerifyFunctions(t *testing.T, awaitilities wait.Awaitilities) { func() { verifyDeactivatedSignup(t, awaitilities, deactivatedSignup) }, func() { verifyBannedSignup(t, awaitilities, bannedSignup) }, func() { verifyAdditionalDeploymentsCreatedUsingSSA(t, &awaitilities) }, - func() { verifyBundledNSTemplateTiersAnnotated(t, &awaitilities) }, + func() { verifyBundledNSTemplateTiersHaveFinalizer(t, &awaitilities) }, } // when & then - run all functions in parallel @@ -273,7 +274,7 @@ func verifyAdditionalDeploymentsCreatedUsingSSA(t *testing.T, awaitilities *wait }) } -func verifyBundledNSTemplateTiersAnnotated(t *testing.T, awaitilities *wait.Awaitilities) { +func verifyBundledNSTemplateTiersHaveFinalizer(t *testing.T, awaitilities *wait.Awaitilities) { list := &toolchainv1alpha1.NSTemplateTierList{} require.NoError(t, awaitilities.Host().Client.List(context.TODO(), list, client.InNamespace(awaitilities.Host().Namespace))) @@ -283,8 +284,9 @@ func verifyBundledNSTemplateTiersAnnotated(t *testing.T, awaitilities *wait.Awai unmatchedBundledTiers := make([]string, len(wait.BundledNSTemplateTiers)) copy(unmatchedBundledTiers, wait.BundledNSTemplateTiers) + finalizerName := toolchainv1alpha1.LabelKeyPrefix + toolchainv1alpha1.LabelKeyPrefix + "bundled-tier" for _, tier := range list.Items { - if tier.Annotations[toolchainv1alpha1.BundledAnnotationKey] == "host-operator" { + if controllerutil.ContainsFinalizer(&tier, finalizerName) { if i := slices.Index(unmatchedBundledTiers, tier.Name); i >= 0 { unmatchedBundledTiers = slices.Delete(unmatchedBundledTiers, i, i+1) } From 27b07c64661e6b8ce54cd6f1e15d50278045de01 Mon Sep 17 00:00:00 2001 From: Lukas Krejci Date: Tue, 10 Jun 2025 14:44:01 +0200 Subject: [PATCH 8/9] fix the typo --- test/migration/verify/verify_migration_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/migration/verify/verify_migration_test.go b/test/migration/verify/verify_migration_test.go index 17eaa1ad8..2b23d7106 100644 --- a/test/migration/verify/verify_migration_test.go +++ b/test/migration/verify/verify_migration_test.go @@ -284,7 +284,7 @@ func verifyBundledNSTemplateTiersHaveFinalizer(t *testing.T, awaitilities *wait. unmatchedBundledTiers := make([]string, len(wait.BundledNSTemplateTiers)) copy(unmatchedBundledTiers, wait.BundledNSTemplateTiers) - finalizerName := toolchainv1alpha1.LabelKeyPrefix + toolchainv1alpha1.LabelKeyPrefix + "bundled-tier" + finalizerName := toolchainv1alpha1.LabelKeyPrefix + "bundled-tier" for _, tier := range list.Items { if controllerutil.ContainsFinalizer(&tier, finalizerName) { if i := slices.Index(unmatchedBundledTiers, tier.Name); i >= 0 { From 6e92d58ffe4106665cfdf4991a1ead326b6a21e1 Mon Sep 17 00:00:00 2001 From: Lukas Krejci Date: Tue, 10 Jun 2025 14:51:15 +0200 Subject: [PATCH 9/9] undo the formatting changes in testsupport/init.go to minimize the diff --- testsupport/init.go | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/testsupport/init.go b/testsupport/init.go index 0f4ade7b7..5409f7af4 100644 --- a/testsupport/init.go +++ b/testsupport/init.go @@ -59,7 +59,6 @@ func WaitForOperators(t *testing.T) wait.Awaitilities { }) return wait.NewAwaitilities(initHostAwait, initMemberAwait, initMember2Await) } - func waitForOperators(t *testing.T) { memberNs := os.Getenv(wait.MemberNsVar) memberNs2 := os.Getenv(wait.MemberNsVar2) @@ -83,7 +82,7 @@ func waitForOperators(t *testing.T) { }) require.NoError(t, err) - // updating the kubeconfig with the bearer token created + //updating the kubeconfig with the bearer token created kubeconfig.BearerToken = getE2EServiceAccountToken(t, hostNs, apiConfig, cl) initHostAwait = wait.NewHostAwaitility(kubeconfig, cl, hostNs, registrationServiceNs) @@ -121,7 +120,7 @@ func waitForOperators(t *testing.T) { func getE2EServiceAccountToken(t *testing.T, hostNs string, apiConfigsa *api.Config, sacl client.Client) string { // creating another config which is used for creating only resclient, - // so that the main kubeconfig is not altered + //so that the main kubeconfig is not altered restkubeconfig, err := util.BuildKubernetesRESTConfig(*apiConfigsa) require.NoError(t, err) @@ -133,9 +132,7 @@ func getE2EServiceAccountToken(t *testing.T, hostNs string, apiConfigsa *api.Con err := sacl.Create(context.TODO(), &corev1.ServiceAccount{ ObjectMeta: metav1.ObjectMeta{ Name: "e2e-test", - Namespace: hostNs, - }, - }) + Namespace: hostNs}}) require.NoError(t, err, "Error in creating Service account for e2e test") } else if err != nil { require.NoError(t, err, "Error fetching service accounts") @@ -169,17 +166,18 @@ func getE2EServiceAccountToken(t *testing.T, hostNs string, apiConfigsa *api.Con require.NoError(t, err, "Error fetching clusterrolebinding") } - // upating the restkubeconfig ,which requires groupversion to create restclient - restkubeconfig.ContentConfig = rest.ContentConfig{ - GroupVersion: &authv1.SchemeGroupVersion, - NegotiatedSerializer: scheme.Codecs, - } + //upating the restkubeconfig ,which requires groupversion to create restclient + restkubeconfig.ContentConfig = + rest.ContentConfig{ + GroupVersion: &authv1.SchemeGroupVersion, + NegotiatedSerializer: scheme.Codecs, + } - // Creating a Restclient to be used in creation and checking of bearer token required for authentication + //Creating a Restclient to be used in creation and checking of bearer token required for authentication rclient, err := rest.RESTClientFor(restkubeconfig) require.NoError(t, err, "Error in creating restclient") - // Creating a bearer token to be used for authentication(which is valid for 24 hrs) + //Creating a bearer token to be used for authentication(which is valid for 24 hrs) bt, err := toolchaincommon.CreateTokenRequest(context.TODO(), rclient, types.NamespacedName{Namespace: hostNs, Name: "e2e-test"}, 86400) require.NoError(t, err, "Error in creating Token") return bt