From 006a35a365a187ac7d175a3fc62a05c135ce7003 Mon Sep 17 00:00:00 2001 From: Janos Laszlo Vasik Date: Tue, 25 Jun 2024 14:43:22 +0200 Subject: [PATCH] feat: RHINENG-9589 add autopromotion pipeline tests --- Dockerfile | 1 + stage_test.sh | 25 +++++++++++++++++ stage_test.yaml | 75 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 stage_test.sh create mode 100644 stage_test.yaml diff --git a/Dockerfile b/Dockerfile index 9eb643e..e250951 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,3 +16,4 @@ RUN ansible-galaxy collection install -r ${HOME}/requirements.yml \ COPY watches.yaml ${HOME}/watches.yaml COPY roles/ ${HOME}/roles/ COPY playbooks/ ${HOME}/playbooks/ +COPY stage_test.sh ${HOME}/stage_test.sh diff --git a/stage_test.sh b/stage_test.sh new file mode 100644 index 0000000..0288368 --- /dev/null +++ b/stage_test.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Get names of all cronjobs, if not found any ignore the error message +# to not let k8s raise an error with an exit code indicating success +CRONJOBS=$(kubectl get cronjobs 2>/dev/null | awk 'NR>1 {print $1}') + +if [ -z "$CRONJOBS" ]; then + echo $CRONJOBS + echo "ERROR: no cronjobs found" + exit 1 +fi + +for CRONJOB in $CRONJOBS; do + SUCCESS=$(kubectl get job -l "pod=${CRONJOB}" -o jsonpath='{.items[].status.succeeded}{"\n"}') + + if [ -z "$SUCCESS" ]; then + echo "ERROR: cronjob $CRONJOB has not created any jobs" + exit 1 + fi + + if [ "$SUCCESS" != "1" ]; then + echo "ERROR: cronjob $CRONJOB has not created successful jobs" + exit 1 + fi +done diff --git a/stage_test.yaml b/stage_test.yaml new file mode 100644 index 0000000..469b7b7 --- /dev/null +++ b/stage_test.yaml @@ -0,0 +1,75 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: stage-test-account + namespace: default +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: stage-test-role +rules: +- apiGroups: + - batch + resources: + - cronjobs + - jobs + verbs: + - get + - list + - watch +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: stage-test-rolebinding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: stage-test-role +subjects: +- kind: ServiceAccount + name: stage-test-account + namespace: default +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: floorist-operator-stage-test + namespace: default +spec: + template: + spec: + restartPolicy: Never + serviceAccountName: stage-test-account + containers: + - image: quay.io/rhn_engineering_jvasik/floorist-operator:0.0.1 # TODO: use cloudservices quay.io + name: floorist-operator-stage-test + imagePullPolicy: Always + command: + - sh + args: + - stage_test.sh + resources: + requests: + memory: 256Mi + cpu: 300m + limits: + memory: 512Mi + +# parameters: +# - name: IMAGE +# value: quay.io/cloudservices/floorist-operator +# - name: IMAGE_TAG +# value: lastest +# required: true +# - name: SERVICE_ACCOUNT +# value: floorist-operator-stage-test +# displayName: floorist-operator-stage-test service account +# description: name of the service account to use when deploying the pod +# - name: MEMORY_REQUESTS +# value: 256Mi +# - name: MEMORY_LIMIT +# value: 512Mi +# - name: CPU_REQUESTS +# value: 300m