From dd38bdf4f720142f54f8365027a7c4d05e8ef350 Mon Sep 17 00:00:00 2001 From: "Jiahui (Jack) Zhang" Date: Tue, 5 Dec 2023 11:38:44 -0800 Subject: [PATCH] tests: add test cronjob manifests for errors and delays (#70) * add test cronjob manifests for errors and delays * clean up shell commands --- k8s/errors/cronjob-basic-error.yaml | 4 +-- k8s/errors/cronjob-late-maybe-error.yaml | 32 ++++++++++++++++++++++++ k8s/errors/cronjob-late-success.yaml | 30 ++++++++++++++++++++++ k8s/errors/cronjob-maybe-error.yaml | 29 +++++++++++++++++++++ 4 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 k8s/errors/cronjob-late-maybe-error.yaml create mode 100644 k8s/errors/cronjob-late-success.yaml create mode 100644 k8s/errors/cronjob-maybe-error.yaml diff --git a/k8s/errors/cronjob-basic-error.yaml b/k8s/errors/cronjob-basic-error.yaml index e1d275d..22cc423 100644 --- a/k8s/errors/cronjob-basic-error.yaml +++ b/k8s/errors/cronjob-basic-error.yaml @@ -22,7 +22,5 @@ spec: command: - /bin/sh - -c - - | - sleep 1 - invalid_command + - sleep 1; invalid_command restartPolicy: Never diff --git a/k8s/errors/cronjob-late-maybe-error.yaml b/k8s/errors/cronjob-late-maybe-error.yaml new file mode 100644 index 0000000..ccb9a22 --- /dev/null +++ b/k8s/errors/cronjob-late-maybe-error.yaml @@ -0,0 +1,32 @@ +apiVersion: batch/v1 +kind: CronJob +metadata: + name: cronjob-late-maybe-error + labels: + type: test-pod +spec: + schedule: "* * * * *" + jobTemplate: + spec: + backoffLimit: 0 + template: + metadata: + labels: + type: test-pod + run: cronjob-late-maybe-error + spec: + containers: + - name: hello + image: busybox:1.28 + imagePullPolicy: IfNotPresent + command: + - /bin/sh + - -c + - | + MINWAIT=0 + MAXWAIT=60 + sleep $((MINWAIT+RANDOM % (MAXWAIT-MINWAIT))) + sleep 3 + r=$((RANDOM%2)) + if [ $r -eq 0 ]; then echo Hello!; else exit 1; fi + restartPolicy: Never diff --git a/k8s/errors/cronjob-late-success.yaml b/k8s/errors/cronjob-late-success.yaml new file mode 100644 index 0000000..19e07b9 --- /dev/null +++ b/k8s/errors/cronjob-late-success.yaml @@ -0,0 +1,30 @@ +apiVersion: batch/v1 +kind: CronJob +metadata: + name: cronjob-late-success + labels: + type: test-pod +spec: + schedule: "* * * * *" + jobTemplate: + spec: + template: + metadata: + labels: + type: test-pod + run: cronjob-late-success + spec: + containers: + - name: hello + image: busybox:1.28 + imagePullPolicy: IfNotPresent + command: + - /bin/sh + - -c + - | + date + MINWAIT=0 + MAXWAIT=60 + sleep $((MINWAIT+RANDOM % (MAXWAIT-MINWAIT))) + echo Hello! + restartPolicy: Never diff --git a/k8s/errors/cronjob-maybe-error.yaml b/k8s/errors/cronjob-maybe-error.yaml new file mode 100644 index 0000000..4947789 --- /dev/null +++ b/k8s/errors/cronjob-maybe-error.yaml @@ -0,0 +1,29 @@ +apiVersion: batch/v1 +kind: CronJob +metadata: + name: cronjob-maybe-error + labels: + type: test-pod +spec: + schedule: "* * * * *" + jobTemplate: + spec: + backoffLimit: 0 + template: + metadata: + labels: + type: test-pod + run: cronjob-maybe-error + spec: + containers: + - name: hello + image: busybox:1.28 + imagePullPolicy: IfNotPresent + command: + - /bin/sh + - -c + - | + sleep 3 + r=$((RANDOM%2)) + if [ $r -eq 0 ]; then echo Hello!; else exit 1; fi + restartPolicy: Never