From f2ea6dc55929db10802d826837f1238e9fb29685 Mon Sep 17 00:00:00 2001 From: miampf Date: Tue, 3 Dec 2024 11:25:32 +0100 Subject: [PATCH 1/2] fix(e2e): log collection download --- .github/workflows/e2e.yml | 4 ++-- .github/workflows/e2e_aks_runtime.yml | 2 +- packages/scripts.nix | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index f8dca9fcf..f81d5bf69 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -100,6 +100,6 @@ jobs: message: "e2e test ${{ inputs.test-name }} failed" additionalFields: '[{"title": "Platform", "value": "${{ inputs.platform }}"}]' - name: Cleanup - if: cancelled() && !inputs.skip-undeploy + if: always() && !inputs.skip-undeploy run: | - kubectl delete ns "$(cat workspace/e2e.namespace)" --timeout 5m + kubectl delete ns "$(cat workspace/e2e.namespace)" --timeout 10m diff --git a/.github/workflows/e2e_aks_runtime.yml b/.github/workflows/e2e_aks_runtime.yml index c7ae37188..41fe749c2 100644 --- a/.github/workflows/e2e_aks_runtime.yml +++ b/.github/workflows/e2e_aks_runtime.yml @@ -110,6 +110,6 @@ jobs: message: "e2e test aks-runtime failed" additionalFields: '[{"title": "Platform", "value": "AKS-CLH-SNP"}]' - name: Cleanup - if: cancelled() + if: always() run: | kubectl delete ns "$(cat workspace/e2e.namespace)" --timeout 5m diff --git a/packages/scripts.nix b/packages/scripts.nix index 8521235e4..2d8c7047d 100644 --- a/packages/scripts.nix +++ b/packages/scripts.nix @@ -453,10 +453,10 @@ namespace="$(head -n1 "$2")" pod="$(kubectl get pods -o name -n "$namespace" | grep log-collector | cut -c 5-)" mkdir -p ./workspace/logs - kubectl wait --for=condition=Ready -n "$namespace" "pod/$pod" 1>/dev/null 2>/dev/null - kubectl exec -n "$namespace" "$pod" -- /bin/bash -c "rm -f /exported-logs.tar.gz; tar zcvf /exported-logs.tar.gz /export" 1>/dev/null 2>/dev/null - kubectl cp -n "$namespace" "$pod:/exported-logs.tar.gz" ./workspace/logs/exported-logs.tar.gz 1>/dev/null 2>/dev/null - tar xzvf ./workspace/logs/exported-logs.tar.gz --directory ./workspace/logs 1>/dev/null 2>/dev/null + kubectl wait --for=condition=Ready -n "$namespace" "pod/$pod" + kubectl exec -n "$namespace" "$pod" -- /bin/bash -c "rm -f /exported-logs.tar.gz; tar zcvf /exported-logs.tar.gz /export" + kubectl cp -n "$namespace" "$pod:/exported-logs.tar.gz" ./workspace/logs/exported-logs.tar.gz + tar xzvf ./workspace/logs/exported-logs.tar.gz --directory ./workspace/logs ;; *) echo "Unknown option $1" From 33ea1b0d568537d7f901e29b3a7ab4fde221b88f Mon Sep 17 00:00:00 2001 From: miampf Date: Thu, 5 Dec 2024 11:54:30 +0100 Subject: [PATCH 2/2] e2e: remove `skip-undeploy` flag and go cleanup logic --- .github/workflows/e2e.yml | 1 - .github/workflows/e2e_aks_runtime.yml | 1 - e2e/aks-runtime/aks_runtime_test.go | 15 --------------- e2e/internal/contrasttest/contrasttest.go | 18 ------------------ 4 files changed, 35 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index f81d5bf69..d3f906e2a 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -79,7 +79,6 @@ jobs: --image-replacements workspace/just.containerlookup \ --namespace-file workspace/e2e.namespace \ --platform ${{ inputs.platform }} \ - --skip-undeploy="${{ inputs.skip-undeploy && 'true' || 'false' }}" \ --namespace-suffix="-ci" - name: Download logs if: always() diff --git a/.github/workflows/e2e_aks_runtime.yml b/.github/workflows/e2e_aks_runtime.yml index 41fe749c2..0f383ba65 100644 --- a/.github/workflows/e2e_aks_runtime.yml +++ b/.github/workflows/e2e_aks_runtime.yml @@ -89,7 +89,6 @@ jobs: --image-replacements workspace/just.containerlookup \ --namespace-file workspace/e2e.namespace \ --platform AKS-CLH-SNP \ - --skip-undeploy="false" \ --namespace-suffix="-ci" - name: Download logs if: always() diff --git a/e2e/aks-runtime/aks_runtime_test.go b/e2e/aks-runtime/aks_runtime_test.go index 3a5c5922e..fc0306bff 100644 --- a/e2e/aks-runtime/aks_runtime_test.go +++ b/e2e/aks-runtime/aks_runtime_test.go @@ -20,7 +20,6 @@ import ( "github.com/edgelesssys/contrast/internal/kuberesource" "github.com/stretchr/testify/require" corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) const testContainer = "testcontainer" @@ -104,20 +103,6 @@ func TestAKSRuntime(t *testing.T) { require.NoError(err) require.NoError(c.WaitFor(ctx, kubeclient.Ready, kubeclient.Deployment{}, namespace, testContainer)) - t.Cleanup(func() { - if contrasttest.Flags.SkipUndeploy { - return - } - - // delete the deployment - deletePolicy := metav1.DeletePropagationForeground - if err = c.Client.CoreV1().Namespaces().Delete(context.Background(), namespace, metav1.DeleteOptions{ - PropagationPolicy: &deletePolicy, - }); err != nil { - t.Fatalf("Failed to delete namespace %s", namespace) - } - }) - pods, err := c.PodsFromDeployment(ctx, namespace, testContainer) require.NoError(err) require.Len(pods, 1) diff --git a/e2e/internal/contrasttest/contrasttest.go b/e2e/internal/contrasttest/contrasttest.go index a2e98e769..96e13e37d 100644 --- a/e2e/internal/contrasttest/contrasttest.go +++ b/e2e/internal/contrasttest/contrasttest.go @@ -41,7 +41,6 @@ type testFlags struct { ImageReplacementsFile string NamespaceFile string NamespaceSuffix string - SkipUndeploy bool } // RegisterFlags registers the flags that are shared between all tests. @@ -50,7 +49,6 @@ func RegisterFlags() { 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") } // ContrastTest is the Contrast test helper struct. @@ -62,7 +60,6 @@ type ContrastTest struct { ImageReplacementsFile string Platform platforms.Platform NamespaceFile string - SkipUndeploy bool Kubeclient *kubeclient.Kubeclient // outputs of contrast subcommands @@ -81,7 +78,6 @@ func New(t *testing.T) *ContrastTest { ImageReplacementsFile: Flags.ImageReplacementsFile, Platform: platform, NamespaceFile: Flags.NamespaceFile, - SkipUndeploy: Flags.SkipUndeploy, Kubeclient: kubeclient.NewForTest(t), } } @@ -135,20 +131,6 @@ func (ct *ContrastTest) Init(t *testing.T, resources []any) { ct.Kubeclient.LogDebugInfo(ctx) } - if !ct.SkipUndeploy { - // Deleting the namespace sometimes fails when the cluster is - // unavailable (e.g. after a K3s restart). Retry deleting for up to - // 30 seconds. - for range 30 { - if err := ct.Kubeclient.Delete(ctx, namespace...); err != nil { - t.Logf("Could not delete namespace %q: %v", ct.Namespace, err) - time.Sleep(1 * time.Second) - } else { - break - } - } - } - if fifo != nil { if err := fifo.Done(ctx); err != nil { t.Logf("Could not mark fifo ticket as done: %v", err)