From 206b7e1e8e55ad817c401bb7be66e07eeab76b51 Mon Sep 17 00:00:00 2001 From: Wayne Starr Date: Thu, 13 Jun 2024 14:41:59 -0600 Subject: [PATCH] fix: no longer remove the agent ignore label from namespaces (#2623) ## Description Fixes namespaces being able to be excluded from Zarf's mutation (deleting the label forces everything through the Zarf agent). ## Related Issue Fixes #N/A ## Checklist before merging - [ ] Test, docs, adr added or updated as needed - [X] [Contributor Guide Steps](https://github.com/defenseunicorns/zarf/blob/main/.github/CONTRIBUTING.md#developer-workflow) followed --------- Co-authored-by: Austin Abro <37223396+AustinAbro321@users.noreply.github.com> Signed-off-by: Austin Abro --- src/pkg/cluster/namespace.go | 1 - src/test/e2e/26_simple_packages_test.go | 16 +++++++++++++ .../26-agent-ignore/manifests/deployment.yaml | 20 ++++++++++++++++ .../26-agent-ignore/manifests/namespace.yaml | 6 +++++ src/test/packages/26-agent-ignore/zarf.yaml | 23 +++++++++++++++++++ 5 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/test/packages/26-agent-ignore/manifests/deployment.yaml create mode 100644 src/test/packages/26-agent-ignore/manifests/namespace.yaml create mode 100644 src/test/packages/26-agent-ignore/zarf.yaml diff --git a/src/pkg/cluster/namespace.go b/src/pkg/cluster/namespace.go index f7e776146d..6a35ee6a56 100644 --- a/src/pkg/cluster/namespace.go +++ b/src/pkg/cluster/namespace.go @@ -67,6 +67,5 @@ func AdoptZarfManagedLabels(labels map[string]string) map[string]string { labels = make(map[string]string) } labels[k8s.ZarfManagedByLabel] = "zarf" - delete(labels, k8s.AgentLabel) return labels } diff --git a/src/test/e2e/26_simple_packages_test.go b/src/test/e2e/26_simple_packages_test.go index c7a96e80d6..347aad89fd 100644 --- a/src/test/e2e/26_simple_packages_test.go +++ b/src/test/e2e/26_simple_packages_test.go @@ -65,3 +65,19 @@ func TestManifests(t *testing.T) { stdOut, stdErr, err = e2e.Zarf("package", "remove", "manifests", "--confirm") require.NoError(t, err, stdOut, stdErr) } + +func TestAgentIgnore(t *testing.T) { + t.Log("E2E: Test Manifests that are Agent Ignored") + e2e.SetupWithCluster(t) + + testCreate := filepath.Join("src", "test", "packages", "26-agent-ignore") + testDeploy := filepath.Join("build", fmt.Sprintf("zarf-package-agent-ignore-namespace-%s.tar.zst", e2e.Arch)) + + // Create the agent ignore test package + stdOut, stdErr, err := e2e.Zarf("package", "create", testCreate, "-o", "build", "--confirm") + require.NoError(t, err, stdOut, stdErr) + + // Deploy the agent ignore test package + stdOut, stdErr, err = e2e.Zarf("package", "deploy", testDeploy, "--confirm") + require.NoError(t, err, stdOut, stdErr) +} diff --git a/src/test/packages/26-agent-ignore/manifests/deployment.yaml b/src/test/packages/26-agent-ignore/manifests/deployment.yaml new file mode 100644 index 0000000000..46bbab17c1 --- /dev/null +++ b/src/test/packages/26-agent-ignore/manifests/deployment.yaml @@ -0,0 +1,20 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: httpd-deployment +spec: + selector: + matchLabels: + app: httpd + replicas: 2 # tells deployment to run 2 pods matching the template + template: + metadata: + labels: + app: httpd + spec: + containers: + - name: httpd + # This is explicitly a different tag than examples/manifests to ensure it has to pull the image from outside the cluster + image: "httpd:alpine" + ports: + - containerPort: 80 diff --git a/src/test/packages/26-agent-ignore/manifests/namespace.yaml b/src/test/packages/26-agent-ignore/manifests/namespace.yaml new file mode 100644 index 0000000000..53e30073c4 --- /dev/null +++ b/src/test/packages/26-agent-ignore/manifests/namespace.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: httpd-ignored + labels: + zarf.dev/agent: ignore diff --git a/src/test/packages/26-agent-ignore/zarf.yaml b/src/test/packages/26-agent-ignore/zarf.yaml new file mode 100644 index 0000000000..d945eef803 --- /dev/null +++ b/src/test/packages/26-agent-ignore/zarf.yaml @@ -0,0 +1,23 @@ +kind: ZarfPackageConfig +metadata: + name: agent-ignore-namespace + description: Simple test to check that Zarf respects ignored namespaces. + +components: + - name: httpd-deployment + required: true + manifests: + - name: agent-ignore-httpd + namespace: httpd-ignored + files: + - manifests/deployment.yaml + - manifests/namespace.yaml + actions: + onDeploy: + after: + - wait: + cluster: + kind: deployment + name: httpd-deployment + namespace: httpd-ignored + condition: "{.status.readyReplicas}=2"