From 1114f0af36ad6c2128375e5bcb29cf74a0429f60 Mon Sep 17 00:00:00 2001 From: Shivam Kumar <122988410+ShivamJha2436@users.noreply.github.com> Date: Tue, 8 Oct 2024 00:55:33 +0530 Subject: [PATCH] Added chainsaw test for the ttl based cleanup poliy (#11328) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added chainsaw test for the ttl based cleanup poliy Signed-off-by: ShivamJha2436 * Updated the ttl/propagation-policy chainsaw test structure Signed-off-by: ShivamJha2436 * Enhanced the chainsaw tests for the ttl/propagation-policy Signed-off-by: ShivamJha2436 * orphan Signed-off-by: Charles-Edouard Brétéché * Update test/conformance/chainsaw/ttl/propagation-policy/orphan/chainsaw-test.yaml Signed-off-by: Charles-Edouard Brétéché * Improved chainsaw tests for foreground and background propagation policies Signed-off-by: ShivamJha2436 * Fix background policy test: assert pod is deleted after job removal Signed-off-by: ShivamJha2436 * Fix: changed pod-deleted-assert.yaml to pod-assert.yaml in the foreground Signed-off-by: ShivamJha2436 * Change assert to error check for pod deletion in foreground test Signed-off-by: ShivamJha2436 * Removed the pod-deleted-assert.yaml file Signed-off-by: ShivamJha2436 --------- Signed-off-by: ShivamJha2436 Signed-off-by: Charles-Edouard Brétéché Co-authored-by: Charles-Edouard Brétéché --- .../background/chainsaw-test.yaml | 22 +++++++++++++++++++ .../propagation-policy/background/job.yaml | 17 ++++++++++++++ .../background/pod-assert.yaml | 4 ++++ .../foreground/chainsaw-test.yaml | 22 +++++++++++++++++++ .../propagation-policy/foreground/job.yaml | 17 ++++++++++++++ .../foreground/pod-assert.yaml | 5 +++++ .../orphan/chainsaw-test.yaml | 22 +++++++++++++++++++ .../ttl/propagation-policy/orphan/job.yaml | 17 ++++++++++++++ .../propagation-policy/orphan/pod-assert.yaml | 4 ++++ 9 files changed, 130 insertions(+) create mode 100644 test/conformance/chainsaw/ttl/propagation-policy/background/chainsaw-test.yaml create mode 100644 test/conformance/chainsaw/ttl/propagation-policy/background/job.yaml create mode 100644 test/conformance/chainsaw/ttl/propagation-policy/background/pod-assert.yaml create mode 100644 test/conformance/chainsaw/ttl/propagation-policy/foreground/chainsaw-test.yaml create mode 100644 test/conformance/chainsaw/ttl/propagation-policy/foreground/job.yaml create mode 100644 test/conformance/chainsaw/ttl/propagation-policy/foreground/pod-assert.yaml create mode 100644 test/conformance/chainsaw/ttl/propagation-policy/orphan/chainsaw-test.yaml create mode 100644 test/conformance/chainsaw/ttl/propagation-policy/orphan/job.yaml create mode 100644 test/conformance/chainsaw/ttl/propagation-policy/orphan/pod-assert.yaml diff --git a/test/conformance/chainsaw/ttl/propagation-policy/background/chainsaw-test.yaml b/test/conformance/chainsaw/ttl/propagation-policy/background/chainsaw-test.yaml new file mode 100644 index 0000000000..c8c7f669e3 --- /dev/null +++ b/test/conformance/chainsaw/ttl/propagation-policy/background/chainsaw-test.yaml @@ -0,0 +1,22 @@ +apiVersion: chainsaw.kyverno.io/v1alpha1 +kind: Test +metadata: + name: background +spec: + steps: + - name: Create job with background deletion policy + try: + - create: + file: job.yaml + - name: Wait pod is running + try: + - assert: + file: pod-assert.yaml + - name: Delete job with background deletion policy + try: + - delete: + file: job.yaml + - name: Assert pod is no longer running + try: + - error: + file: pod-assert.yaml diff --git a/test/conformance/chainsaw/ttl/propagation-policy/background/job.yaml b/test/conformance/chainsaw/ttl/propagation-policy/background/job.yaml new file mode 100644 index 0000000000..41a5fac371 --- /dev/null +++ b/test/conformance/chainsaw/ttl/propagation-policy/background/job.yaml @@ -0,0 +1,17 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: job + annotations: + cleanup.kyverno.io/propagation-policy: Background +spec: + template: + spec: + restartPolicy: Never + containers: + - name: main + image: docker.io/library/bash:5 + command: ["bash"] + args: + - -c + - sleep 120s diff --git a/test/conformance/chainsaw/ttl/propagation-policy/background/pod-assert.yaml b/test/conformance/chainsaw/ttl/propagation-policy/background/pod-assert.yaml new file mode 100644 index 0000000000..35f86072a7 --- /dev/null +++ b/test/conformance/chainsaw/ttl/propagation-policy/background/pod-assert.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Pod +status: + phase: Running diff --git a/test/conformance/chainsaw/ttl/propagation-policy/foreground/chainsaw-test.yaml b/test/conformance/chainsaw/ttl/propagation-policy/foreground/chainsaw-test.yaml new file mode 100644 index 0000000000..7cbcadb4c8 --- /dev/null +++ b/test/conformance/chainsaw/ttl/propagation-policy/foreground/chainsaw-test.yaml @@ -0,0 +1,22 @@ +apiVersion: chainsaw.kyverno.io/v1alpha1 +kind: Test +metadata: + name: foreground +spec: + steps: + - name: Create job with foreground deletion policy + try: + - create: + file: job.yaml + - name: Wait pod is running + try: + - assert: + file: pod-assert.yaml + - name: Delete job with foreground deletion policy + try: + - delete: + file: job.yaml + - name: Assert pod is no longer running + try: + - error: + file: pod-assert.yaml diff --git a/test/conformance/chainsaw/ttl/propagation-policy/foreground/job.yaml b/test/conformance/chainsaw/ttl/propagation-policy/foreground/job.yaml new file mode 100644 index 0000000000..55e805bd11 --- /dev/null +++ b/test/conformance/chainsaw/ttl/propagation-policy/foreground/job.yaml @@ -0,0 +1,17 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: job + annotations: + cleanup.kyverno.io/propagation-policy: Foreground +spec: + template: + spec: + restartPolicy: Never + containers: + - name: main + image: docker.io/library/bash:5 + command: ["bash"] + args: + - -c + - sleep 120s diff --git a/test/conformance/chainsaw/ttl/propagation-policy/foreground/pod-assert.yaml b/test/conformance/chainsaw/ttl/propagation-policy/foreground/pod-assert.yaml new file mode 100644 index 0000000000..0c784d0c93 --- /dev/null +++ b/test/conformance/chainsaw/ttl/propagation-policy/foreground/pod-assert.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +kind: Pod +status: + phase: Running + \ No newline at end of file diff --git a/test/conformance/chainsaw/ttl/propagation-policy/orphan/chainsaw-test.yaml b/test/conformance/chainsaw/ttl/propagation-policy/orphan/chainsaw-test.yaml new file mode 100644 index 0000000000..e237c3d97a --- /dev/null +++ b/test/conformance/chainsaw/ttl/propagation-policy/orphan/chainsaw-test.yaml @@ -0,0 +1,22 @@ +apiVersion: chainsaw.kyverno.io/v1alpha1 +kind: Test +metadata: + name: orphan +spec: + steps: + - name: Create job with orphan deletion policy + try: + - create: + file: job.yaml + - name: Wait pod is running + try: + - assert: + file: pod-assert.yaml + - name: Delete job + try: + - delete: + file: job.yaml + - name: Assert pod is still running + try: + - assert: + file: pod-assert.yaml diff --git a/test/conformance/chainsaw/ttl/propagation-policy/orphan/job.yaml b/test/conformance/chainsaw/ttl/propagation-policy/orphan/job.yaml new file mode 100644 index 0000000000..77dd649ddb --- /dev/null +++ b/test/conformance/chainsaw/ttl/propagation-policy/orphan/job.yaml @@ -0,0 +1,17 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: job + annotations: + cleanup.kyverno.io/propagation-policy: Orphan +spec: + template: + spec: + restartPolicy: Never + containers: + - name: main + image: docker.io/library/bash:5 + command: ["bash"] + args: + - -c + - sleep 120s diff --git a/test/conformance/chainsaw/ttl/propagation-policy/orphan/pod-assert.yaml b/test/conformance/chainsaw/ttl/propagation-policy/orphan/pod-assert.yaml new file mode 100644 index 0000000000..35f86072a7 --- /dev/null +++ b/test/conformance/chainsaw/ttl/propagation-policy/orphan/pod-assert.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Pod +status: + phase: Running