Skip to content

Commit

Permalink
ci: add "ci" to e2e test namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
3u13r committed Dec 9, 2024
1 parent d7d61a2 commit 20453a5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/e2e_aks_runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion e2e/aks-runtime/aks_runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
19 changes: 14 additions & 5 deletions e2e/internal/contrasttest/contrasttest.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"context"
"crypto/rand"
"crypto/x509"
"encoding/hex"
"encoding/json"
"flag"
"fmt"
Expand Down Expand Up @@ -41,13 +40,15 @@ type testFlags struct {
PlatformStr string
ImageReplacementsFile string
NamespaceFile string
NamespaceSuffix string
SkipUndeploy bool
}

// RegisterFlags registers the flags that are shared between all tests.
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")
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 20453a5

Please sign in to comment.