Skip to content

Commit dc5a83e

Browse files
test(restarter): Test annotation restarter.stackable.tech/ignore
1 parent bc0e239 commit dc5a83e

9 files changed

Lines changed: 177 additions & 54 deletions

File tree

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
apiVersion: kuttl.dev/v1beta1
33
kind: TestAssert
4-
timeout: 30
4+
timeout: 120
55
---
66
apiVersion: apps/v1
77
kind: StatefulSet
88
metadata:
9-
name: sleep
9+
name: test
1010
status:
1111
readyReplicas: 1
1212
replicas: 1
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
name: configmap-not-ignored
6+
data:
7+
revision: "1"
8+
---
9+
apiVersion: v1
10+
kind: Secret
11+
metadata:
12+
name: secret-not-ignored
13+
stringData:
14+
revision: "1"
15+
---
16+
apiVersion: v1
17+
kind: ConfigMap
18+
metadata:
19+
name: configmap-ignored
20+
annotations:
21+
restarter.stackable.tech/ignore: "true"
22+
data:
23+
revision: "1"
24+
---
25+
apiVersion: v1
26+
kind: Secret
27+
metadata:
28+
name: secret-ignored
29+
annotations:
30+
restarter.stackable.tech/ignore: "true"
31+
stringData:
32+
revision: "1"
33+
---
34+
apiVersion: apps/v1
35+
kind: StatefulSet
36+
metadata:
37+
name: test
38+
labels:
39+
restarter.stackable.tech/enabled: "true"
40+
spec:
41+
selector:
42+
matchLabels:
43+
app: test
44+
serviceName: test
45+
replicas: 1
46+
template:
47+
metadata:
48+
labels:
49+
app: test
50+
spec:
51+
serviceAccount: integration-tests-sa
52+
volumes:
53+
- name: configmap-not-ignored
54+
configMap:
55+
name: configmap-not-ignored
56+
- name: secret-not-ignored
57+
secret:
58+
secretName: secret-not-ignored
59+
- name: configmap-ignored
60+
configMap:
61+
name: configmap-ignored
62+
- name: secret-ignored
63+
secret:
64+
secretName: secret-ignored
65+
containers:
66+
- name: test
67+
image: alpine
68+
command:
69+
- sleep
70+
args:
71+
- infinity
72+
volumeMounts:
73+
- mountPath: /config/configmap-not-ignored-subpath/revision
74+
name: configmap-not-ignored
75+
# Use a subPath, so that changes are only visible after a restart.
76+
subPath: revision
77+
- mountPath: /config/secret-not-ignored-subpath/revision
78+
name: secret-not-ignored
79+
# Use a subPath, so that changes are only visible after a restart.
80+
subPath: revision
81+
- mountPath: /config/configmap-ignored
82+
name: configmap-ignored
83+
- mountPath: /config/secret-ignored
84+
name: secret-ignored
85+
- mountPath: /config/configmap-ignored-subpath/revision
86+
name: configmap-ignored
87+
# Use a subPath, so that changes are only visible after a restart.
88+
subPath: revision
89+
- mountPath: /config/secret-ignored-subpath/revision
90+
name: secret-ignored
91+
# Use a subPath, so that changes are only visible after a restart.
92+
subPath: revision
93+
terminationGracePeriodSeconds: 5

tests/templates/kuttl/restarter/10-sleep.yaml

Lines changed: 0 additions & 44 deletions
This file was deleted.

tests/templates/kuttl/restarter/20-assert.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,16 @@ apiVersion: kuttl.dev/v1beta1
33
kind: TestAssert
44
timeout: 180
55
commands:
6-
- script: test "restarted" = $(kubectl exec sleep-0 -c sleep -n $NAMESPACE -- cat /config/property)
6+
- script: |
7+
. ../../../../templates/kuttl/restarter/test-script.sh
8+
9+
# Resources mounted via subPath are not hot-reloaded by Kubernetes.
10+
# It is expected, that the restart controller ignored the annotated resources and that only
11+
# the resources not mounted via subPath were updated.
12+
13+
assert_revision 1 configmap-not-ignored-subpath
14+
assert_revision 1 secret-not-ignored-subpath
15+
assert_revision 1 configmap-ignored-subpath
16+
assert_revision 1 secret-ignored-subpath
17+
assert_revision 2 configmap-ignored
18+
assert_revision 2 secret-ignored
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
name: configmap-ignored
6+
data:
7+
revision: "2"
8+
---
9+
apiVersion: v1
10+
kind: Secret
11+
metadata:
12+
name: secret-ignored
13+
stringData:
14+
revision: "2"

tests/templates/kuttl/restarter/20-update-cm.yaml

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
apiVersion: kuttl.dev/v1beta1
3+
kind: TestAssert
4+
timeout: 180
5+
commands:
6+
- script: |
7+
. ../../../../templates/kuttl/restarter/test-script.sh
8+
9+
# After a restart, all resources should have been updated.
10+
11+
assert_revision 2 configmap-not-ignored-subpath
12+
assert_revision 2 secret-not-ignored-subpath
13+
assert_revision 2 configmap-ignored-subpath
14+
assert_revision 2 secret-ignored-subpath
15+
assert_revision 2 configmap-ignored
16+
assert_revision 2 secret-ignored
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
name: configmap-not-ignored
6+
data:
7+
revision: "2"
8+
---
9+
apiVersion: v1
10+
kind: Secret
11+
metadata:
12+
name: secret-not-ignored
13+
stringData:
14+
revision: "2"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env sh
2+
3+
get_revision () {
4+
resource="$1"
5+
6+
kubectl exec test-0 \
7+
--namespace "$NAMESPACE" \
8+
--container test -- \
9+
cat "/config/$resource/revision"
10+
}
11+
12+
assert_revision () {
13+
expected_value="$1"
14+
resource="$2"
15+
16+
actual_value="$(get_revision "$resource")"
17+
if test "$expected_value" = "$actual_value"
18+
then
19+
echo "[PASS] $resource contains expected value"
20+
else
21+
echo "[FAIL] $resource does not contain expected value: " \
22+
"expected: $expected_value != actual: $actual_value"
23+
exit 1
24+
fi
25+
}

0 commit comments

Comments
 (0)