From 738645161997a0b73e6b17cb3129b8fa11448225 Mon Sep 17 00:00:00 2001 From: Leonard Cohnen Date: Fri, 6 Dec 2024 20:28:31 +0100 Subject: [PATCH] ci: add "ci" to e2e test namespaces --- .github/workflows/e2e.yml | 3 ++- .github/workflows/e2e_aks_runtime.yml | 3 ++- e2e/aks-runtime/aks_runtime_test.go | 2 +- e2e/internal/contrasttest/contrasttest.go | 19 ++++++++++++++----- justfile | 3 ++- 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index cc9473115..f8dca9fcf 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -79,7 +79,8 @@ jobs: --image-replacements workspace/just.containerlookup \ --namespace-file workspace/e2e.namespace \ --platform ${{ inputs.platform }} \ - --skip-undeploy="${{ inputs.skip-undeploy && 'true' || 'false' }}" + --skip-undeploy="${{ inputs.skip-undeploy && 'true' || 'false' }}" \ + --namespace-suffix="-ci" - name: Download logs if: always() run: | diff --git a/.github/workflows/e2e_aks_runtime.yml b/.github/workflows/e2e_aks_runtime.yml index 4b3d10d15..54ee53995 100644 --- a/.github/workflows/e2e_aks_runtime.yml +++ b/.github/workflows/e2e_aks_runtime.yml @@ -87,7 +87,8 @@ jobs: --image-replacements workspace/just.containerlookup \ --namespace-file workspace/e2e.namespace \ --platform AKS-CLH-SNP \ - --skip-undeploy="false" + --skip-undeploy="false" \ + --namespace-suffix="-ci" - name: Download logs if: always() run: | diff --git a/e2e/aks-runtime/aks_runtime_test.go b/e2e/aks-runtime/aks_runtime_test.go index 04ef2fa34..6738d8492 100644 --- a/e2e/aks-runtime/aks_runtime_test.go +++ b/e2e/aks-runtime/aks_runtime_test.go @@ -34,7 +34,7 @@ func TestAKSRuntime(t *testing.T) { require.NoError(err) imageReplacements, err := kuberesource.ImageReplacementsFromFile(f) require.NoError(err) - namespace := contrasttest.MakeNamespace(t) + namespace := contrasttest.MakeNamespace(t, contrasttest.Flags.NamespaceSuffix) // Log versions kataPolicyGenV, err := az.KataPolicyGenVersion() diff --git a/e2e/internal/contrasttest/contrasttest.go b/e2e/internal/contrasttest/contrasttest.go index 01220f161..a2e98e769 100644 --- a/e2e/internal/contrasttest/contrasttest.go +++ b/e2e/internal/contrasttest/contrasttest.go @@ -10,7 +10,6 @@ import ( "context" "crypto/rand" "crypto/x509" - "encoding/hex" "encoding/json" "flag" "fmt" @@ -41,6 +40,7 @@ type testFlags struct { PlatformStr string ImageReplacementsFile string NamespaceFile string + NamespaceSuffix string SkipUndeploy bool } @@ -48,6 +48,7 @@ type testFlags struct { func RegisterFlags() { flag.StringVar(&Flags.ImageReplacementsFile, "image-replacements", "", "path to image replacements file") flag.StringVar(&Flags.NamespaceFile, "namespace-file", "", "file to store the namespace in") + flag.StringVar(&Flags.NamespaceSuffix, "namespace-suffix", "", "suffix to append to the namespace") flag.StringVar(&Flags.PlatformStr, "platform", "", "Deployment platform") flag.BoolVar(&Flags.SkipUndeploy, "skip-undeploy", false, "Skip undeploying the test namespace") } @@ -75,7 +76,7 @@ func New(t *testing.T) *ContrastTest { require.NoError(t, err) return &ContrastTest{ - Namespace: MakeNamespace(t), + Namespace: MakeNamespace(t, Flags.NamespaceSuffix), WorkDir: t.TempDir(), ImageReplacementsFile: Flags.ImageReplacementsFile, Platform: platform, @@ -397,14 +398,22 @@ func (ct *ContrastTest) FactorPlatformTimeout(timeout time.Duration) time.Durati } // MakeNamespace creates a namespace string using a given *testing.T. -func MakeNamespace(t *testing.T) string { - buf := make([]byte, 4) +func MakeNamespace(t *testing.T, namespaceSuffix string) string { + var namespaceParts []string + + // First part(s) are consist of all valid characters in the lower case test name. re := regexp.MustCompile("[a-z0-9-]+") + namespaceParts = append(namespaceParts, re.FindAllString(strings.ToLower(t.Name()), -1)...) + + // Append some randomness + buf := make([]byte, 4) n, err := rand.Reader.Read(buf) require.NoError(t, err) require.Equal(t, 4, n) - return strings.Join(append(re.FindAllString(strings.ToLower(t.Name()), -1), hex.EncodeToString(buf)), "-") + namespaceParts = append(namespaceParts, fmt.Sprintf("%x", buf)) + + return strings.Join(namespaceParts, "-") + namespaceSuffix } func toPtr[T any](t T) *T { diff --git a/justfile b/justfile index 2aa454439..c81a79c48 100644 --- a/justfile +++ b/justfile @@ -72,7 +72,8 @@ e2e target=default_deploy_target platform=default_platform: soft-clean coordinat --image-replacements ./{{ workspace_dir }}/just.containerlookup \ --namespace-file ./{{ workspace_dir }}/just.namespace \ --platform {{ platform }} \ - --skip-undeploy=true + --skip-undeploy=true \ + --namespace-suffix=${namespace_suffix-} # Generate policies, apply Kubernetes manifests. deploy target=default_deploy_target cli=default_cli platform=default_platform: (runtime target platform) (apply "runtime") (populate target platform) (generate cli platform) (apply target)