From af561151098eb5fb735321513981c8996fab4ba9 Mon Sep 17 00:00:00 2001 From: Razvan-Daniel Mihai <84674+razvan@users.noreply.github.com> Date: Thu, 11 Jan 2024 10:01:36 +0100 Subject: [PATCH] feat(tests): added test for restarter (#199) * fix(doc): typo * feat(tests): added test for restarter * fix(test): yamllint --- .../modules/commons-operator/pages/index.adoc | 3 +- .../templates/kuttl/restarter/00-rbac.yaml.j2 | 30 +++++++++++++ .../templates/kuttl/restarter/10-assert.yaml | 12 ++++++ tests/templates/kuttl/restarter/10-sleep.yaml | 43 +++++++++++++++++++ .../templates/kuttl/restarter/20-assert.yaml | 6 +++ .../kuttl/restarter/20-update-cm.yaml | 7 +++ tests/test-definition.yaml | 16 +++++++ 7 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 tests/templates/kuttl/restarter/00-rbac.yaml.j2 create mode 100644 tests/templates/kuttl/restarter/10-assert.yaml create mode 100644 tests/templates/kuttl/restarter/10-sleep.yaml create mode 100644 tests/templates/kuttl/restarter/20-assert.yaml create mode 100644 tests/templates/kuttl/restarter/20-update-cm.yaml create mode 100644 tests/test-definition.yaml diff --git a/docs/modules/commons-operator/pages/index.adoc b/docs/modules/commons-operator/pages/index.adoc index 2a99020..687a796 100644 --- a/docs/modules/commons-operator/pages/index.adoc +++ b/docs/modules/commons-operator/pages/index.adoc @@ -1,3 +1,4 @@ = Stackable Commons Operator -This is an operator for Kubernetes that provides and manages common Object of the Stackable Data Platform. +This is an operator for Kubernetes that provides and manages common objects of +the Stackable Data Platform. diff --git a/tests/templates/kuttl/restarter/00-rbac.yaml.j2 b/tests/templates/kuttl/restarter/00-rbac.yaml.j2 new file mode 100644 index 0000000..1f8813b --- /dev/null +++ b/tests/templates/kuttl/restarter/00-rbac.yaml.j2 @@ -0,0 +1,30 @@ +--- +kind: Role +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: use-integration-tests-scc +rules: +{% if test_scenario['values']['openshift'] == "true" %} + - apiGroups: ["security.openshift.io"] + resources: ["securitycontextconstraints"] + resourceNames: ["privileged"] + verbs: ["use"] +{% endif %} +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: integration-tests-sa +--- +kind: RoleBinding +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: use-integration-tests-scc +subjects: + - kind: ServiceAccount + name: integration-tests-sa +roleRef: + kind: Role + name: use-integration-tests-scc + apiGroup: rbac.authorization.k8s.io + diff --git a/tests/templates/kuttl/restarter/10-assert.yaml b/tests/templates/kuttl/restarter/10-assert.yaml new file mode 100644 index 0000000..8926a3d --- /dev/null +++ b/tests/templates/kuttl/restarter/10-assert.yaml @@ -0,0 +1,12 @@ +--- +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +timeout: 30 +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: sleep +status: + readyReplicas: 1 + replicas: 1 diff --git a/tests/templates/kuttl/restarter/10-sleep.yaml b/tests/templates/kuttl/restarter/10-sleep.yaml new file mode 100644 index 0000000..5b9c4ca --- /dev/null +++ b/tests/templates/kuttl/restarter/10-sleep.yaml @@ -0,0 +1,43 @@ +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: sleep +data: + property: value +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: sleep + labels: + restarter.stackable.tech/enabled: "true" +spec: + selector: + matchLabels: + app: sleep + serviceName: "sleep" + replicas: 1 + template: + metadata: + labels: + app: sleep + spec: + serviceAccount: integration-tests-sa + volumes: + - name: config + configMap: + name: sleep + items: + - key: property + path: property + containers: + - name: sleep + image: alpine + command: + - sleep + args: + - infinity + volumeMounts: + - name: config + mountPath: /config diff --git a/tests/templates/kuttl/restarter/20-assert.yaml b/tests/templates/kuttl/restarter/20-assert.yaml new file mode 100644 index 0000000..5235897 --- /dev/null +++ b/tests/templates/kuttl/restarter/20-assert.yaml @@ -0,0 +1,6 @@ +--- +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +timeout: 180 +commands: + - script: test "restarted" = $(kubectl exec sleep-0 -c sleep -n $NAMESPACE -- cat /config/property) diff --git a/tests/templates/kuttl/restarter/20-update-cm.yaml b/tests/templates/kuttl/restarter/20-update-cm.yaml new file mode 100644 index 0000000..0ac0446 --- /dev/null +++ b/tests/templates/kuttl/restarter/20-update-cm.yaml @@ -0,0 +1,7 @@ +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: sleep +data: + property: restarted diff --git a/tests/test-definition.yaml b/tests/test-definition.yaml new file mode 100644 index 0000000..3e78406 --- /dev/null +++ b/tests/test-definition.yaml @@ -0,0 +1,16 @@ +--- +dimensions: + - name: openshift + values: + - "false" +tests: + - name: restarter + dimensions: + - openshift +suites: + - name: nightly + - name: openshift + patch: + - dimensions: + - name: openshift + expr: "true"