From e79a99e59c8adde52b58a366f4f315567d8c9d8b Mon Sep 17 00:00:00 2001 From: jmontesi <100689165+jmontesi@users.noreply.github.com> Date: Thu, 18 Apr 2024 11:11:47 +0200 Subject: [PATCH] Add some resources required for testing specific test cases (#422) * Add some resources required for testing specific test cases The ones included in this change allow testing "lifecycle-affinity-required-pods". --- Makefile | 1 + scripts/clean.sh | 1 + scripts/delete-special-resources.sh | 13 ++++ scripts/deploy-special-resources.sh | 13 ++++ test-target/special-resources.yaml | 92 +++++++++++++++++++++++++++++ 5 files changed, 120 insertions(+) create mode 100755 scripts/delete-special-resources.sh create mode 100755 scripts/deploy-special-resources.sh create mode 100644 test-target/special-resources.yaml diff --git a/Makefile b/Makefile index 4099cfa0..f0ea8180 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,7 @@ install: ./scripts/deploy-test-pods.sh ./scripts/deploy-statefulset-test-pods.sh ./scripts/deploy-pod-disruption-budget.sh + ./scripts/deploy-special-resources.sh ./scripts/deploy-test-crds.sh ./scripts/install-olm.sh ./scripts/deploy-community-operator.sh diff --git a/scripts/clean.sh b/scripts/clean.sh index 590e1e2c..45f3f078 100755 --- a/scripts/clean.sh +++ b/scripts/clean.sh @@ -8,6 +8,7 @@ source "$SCRIPT_DIR"/init-env.sh # Delete tnf, partner and operator and litmus ./"$SCRIPT_DIR"/delete-test-pods.sh +./"$SCRIPT_DIR"/delete-special-resources.sh ./"$SCRIPT_DIR"/delete-hpa.sh ./"$SCRIPT_DIR"/delete-test-crds.sh ./"$SCRIPT_DIR"/delete-debug-ds.sh diff --git a/scripts/delete-special-resources.sh b/scripts/delete-special-resources.sh new file mode 100755 index 00000000..c7c330bb --- /dev/null +++ b/scripts/delete-special-resources.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +# Initialization +SCRIPT_DIR=$(dirname "$0") + +# shellcheck disable=SC1091 # Not following. +source "$SCRIPT_DIR"/init-env.sh + +mkdir -p ./temp + +"$SCRIPT_DIR"/mo ./test-target/special-resources.yaml >./temp/rendered-test-special-resources.yaml +oc delete --filename ./temp/rendered-test-special-resources.yaml -n "$TNF_EXAMPLE_CNF_NAMESPACE" --ignore-not-found=true +rm ./temp/rendered-test-special-resources.yaml diff --git a/scripts/deploy-special-resources.sh b/scripts/deploy-special-resources.sh new file mode 100755 index 00000000..f5a4286f --- /dev/null +++ b/scripts/deploy-special-resources.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +# Initialization +SCRIPT_DIR=$(dirname "$0") + +# shellcheck disable=SC1091 # Not following. +source "$SCRIPT_DIR"/init-env.sh + +mkdir -p ./temp + +"$SCRIPT_DIR"/mo ./test-target/special-resources.yaml >./temp/rendered-test-special-resources.yaml +oc apply --filename ./temp/rendered-test-special-resources.yaml --namespace "$TNF_EXAMPLE_CNF_NAMESPACE" +rm ./temp/rendered-test-special-resources.yaml diff --git a/test-target/special-resources.yaml b/test-target/special-resources.yaml new file mode 100644 index 00000000..599ce017 --- /dev/null +++ b/test-target/special-resources.yaml @@ -0,0 +1,92 @@ + +apiVersion: apps/v1 +kind: Deployment +metadata: + name: special-dp + namespace: {{ TNF_EXAMPLE_CNF_NAMESPACE }} + labels: + test-network-function.com/generic: target +spec: + replicas: 2 + selector: + matchLabels: + app: special-dp + template: + metadata: + labels: + test-network-function.com/generic: target + test-network-function.com/container: target + app: special-dp + AffinityRequired: "true" + name: special-dp + spec: + terminationGracePeriodSeconds: 30 + automountServiceAccountToken: false + serviceAccountName: test-pod-sa + containers: + - image: quay.io/testnetworkfunction/cnf-test-partner:latest + imagePullPolicy: IfNotPresent + name: test + ports: + - name: "http-probe" + containerPort: 8080 + resources: + limits: + memory: 512Mi + cpu: 0.25 + lifecycle: + postStart: + exec: + command: ["/bin/sh", "-c", "echo Hello from the postStart handler > /tmp/message"] + preStop: + exec: + command: ["/bin/sh", "-c", "killall -0 tail"] + livenessProbe: + httpGet: + path: /health + port: 8080 + httpHeaders: + - name: health-check + value: liveness + initialDelaySeconds: 10 + periodSeconds: 5 + readinessProbe: + httpGet: + path: /ready + port: 8080 + httpHeaders: + - name: health-check + value: readiness + initialDelaySeconds: 10 + periodSeconds: 5 + startupProbe: + httpGet: + path: /health + port: 8080 + httpHeaders: + - name: health-check + value: startup + failureThreshold: 10 + periodSeconds: 5 + command: ["./bin/app"] + terminationMessagePolicy: FallbackToLogsOnError + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - key: node-role.kubernetes.io/worker + operator: In + values: + - worker +--- +apiVersion: policy/v1 +kind: PodDisruptionBudget +metadata: + name: special-pdb + namespace: {{ TNF_EXAMPLE_CNF_NAMESPACE }} +spec: + minAvailable: 1 + selector: + matchLabels: + app: special-dp