Skip to content

test for the bundled ns template tiers being annotated as such #1154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
5 changes: 2 additions & 3 deletions test/e2e/parallel/nstemplatetier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
25 changes: 25 additions & 0 deletions test/migration/verify/verify_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import (
"context"
"fmt"
"slices"
"sync"
"testing"
"time"
Expand All @@ -12,6 +13,7 @@
"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"
Expand All @@ -20,6 +22,7 @@
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"
)
Expand Down Expand Up @@ -95,6 +98,7 @@
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
Expand Down Expand Up @@ -270,6 +274,27 @@
})
}

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" {

Check failure on line 288 in test/migration/verify/verify_migration_test.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint

undefined: toolchainv1alpha1.BundledAnnotationKey (typecheck)
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()),
Expand Down
34 changes: 19 additions & 15 deletions testsupport/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down
Loading