Skip to content

Commit 0eb7326

Browse files
committed
Add kuttl test
1 parent e5e7b68 commit 0eb7326

7 files changed

Lines changed: 150 additions & 38 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{% if test_scenario['values']['openshift'] == 'true' %}
2+
# see https://github.com/stackabletech/issues/issues/566
3+
---
4+
apiVersion: kuttl.dev/v1beta1
5+
kind: TestStep
6+
commands:
7+
- script: kubectl patch namespace $NAMESPACE -p '{"metadata":{"labels":{"pod-security.kubernetes.io/enforce":"privileged"}}}'
8+
timeout: 120
9+
{% endif %}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
apiVersion: kuttl.dev/v1beta1
3+
kind: TestAssert
4+
timeout: 180
5+
commands:
6+
- script: |
7+
kubectl -n $NAMESPACE rollout status sts/early --timeout=5m
8+
9+
read n1 t1 n2 t2 n3 t3 < <(
10+
kubectl -n $NAMESPACE get pod early-{1,2,0} \
11+
-o jsonpath='{range .items[*]}{.metadata.name}{" "}{.metadata.creationTimestamp}{" "}{end}'
12+
)
13+
14+
if [[ "$t1" > "$t2" || "$t2" > "$t3" ]]; then
15+
echo "ERROR: Pod creation order invalid:"
16+
printf " %s: %s\n %s: %s\n %s: %s\n" "$n1" "$t1" "$n2" "$t2" "$n3" "$t3"
17+
exit 1
18+
fi
19+
20+
echo "OK: Pod creation order verified:"
21+
printf " %s (%s)\n %s (%s)\n %s (%s)\n" "$n1" "$t1" "$n2" "$t2" "$n3" "$t3"
22+
echo " Asserted: $n1 <= $n2 <= $n3"

_TEST.yaml renamed to tests/templates/kuttl/restarter-no-unneeded-restart/01-early-before-config.yaml

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,59 @@
1-
---
2-
apiVersion: v1
3-
kind: Service
4-
metadata:
5-
name: nginx
6-
labels:
7-
app: nginx
8-
spec:
9-
ports:
10-
- port: 80
11-
name: web
12-
clusterIP: None
13-
selector:
14-
app: nginx
15-
---
16-
apiVersion: v1
17-
kind: ConfigMap
18-
metadata:
19-
name: web-config
20-
data:
21-
foo: bar
22-
---
23-
apiVersion: v1
24-
kind: ConfigMap
25-
metadata:
26-
name: web-config-2
27-
data:
28-
foo: bar
29-
---
1+
# As the STS is created *before* the ConfigMap, even the mutating webhook can not prevent the first
2+
# Pod from being restarted.
3+
304
apiVersion: apps/v1
315
kind: StatefulSet
326
metadata:
33-
name: web
7+
name: early
348
labels:
359
restarter.stackable.tech/enabled: "true"
3610
spec:
3711
selector:
3812
matchLabels:
39-
app: nginx
40-
serviceName: nginx
13+
app: early
14+
serviceName: early
4115
replicas: 3
4216
template:
4317
metadata:
4418
labels:
45-
app: nginx
19+
app: early
4620
spec:
4721
terminationGracePeriodSeconds: 10
4822
containers:
4923
- name: nginx
5024
image: registry.k8s.io/nginx-slim:0.24
51-
ports:
52-
- containerPort: 80
53-
name: web
5425
volumeMounts:
5526
- name: config
5627
mountPath: "/config"
5728
envFrom:
5829
- configMapRef:
59-
name: web-config-2
30+
name: early-config-2
6031
volumes:
6132
- name: config
6233
configMap:
63-
name: web-config
34+
name: early-config
35+
---
36+
apiVersion: v1
37+
kind: Service
38+
metadata:
39+
name: early
40+
labels:
41+
app: early
42+
spec:
43+
clusterIP: None
44+
selector:
45+
app: early
46+
---
47+
apiVersion: v1
48+
kind: ConfigMap
49+
metadata:
50+
name: early-config
51+
data:
52+
foo: bar
53+
---
54+
apiVersion: v1
55+
kind: ConfigMap
56+
metadata:
57+
name: early-config-2
58+
data:
59+
foo: bar
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
apiVersion: kuttl.dev/v1beta1
3+
kind: TestAssert
4+
timeout: 180
5+
commands:
6+
- script: |
7+
kubectl -n $NAMESPACE rollout status sts/late --timeout=5m
8+
9+
read n0 t0 n1 t1 n2 t2 < <(
10+
kubectl -n $NAMESPACE get pod late-{0,1,2} \
11+
-o jsonpath='{range .items[*]}{.metadata.name}{" "}{.metadata.creationTimestamp}{" "}{end}'
12+
)
13+
14+
if [[ "$t0" > "$t1" || "$t1" > "$t2" ]]; then
15+
echo "ERROR: Pod creation order invalid:"
16+
printf " %s: %s\n %s: %s\n %s: %s\n" "$n0" "$t0" "$n1" "$t1" "$n2" "$t2"
17+
exit 1
18+
fi
19+
20+
echo "OK: Pod creation order verified:"
21+
printf " %s (%s)\n %s (%s)\n %s (%s)\n" "$n0" "$t0" "$n1" "$t1" "$n2" "$t2"
22+
echo " Asserted: $n0 <= $n1 <= $n2"
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Same situation as in 01-late-before-config.yaml, but this time the STS is created *after* the
2+
# mounted ConfigMaps, so no unneeded Pod restarts occur.
3+
4+
apiVersion: v1
5+
kind: ConfigMap
6+
metadata:
7+
name: late-config
8+
data:
9+
foo: bar
10+
---
11+
apiVersion: v1
12+
kind: ConfigMap
13+
metadata:
14+
name: late-config-2
15+
data:
16+
foo: bar
17+
---
18+
apiVersion: apps/v1
19+
kind: StatefulSet
20+
metadata:
21+
name: late
22+
labels:
23+
restarter.stackable.tech/enabled: "true"
24+
spec:
25+
selector:
26+
matchLabels:
27+
app: late
28+
serviceName: late
29+
replicas: 3
30+
template:
31+
metadata:
32+
labels:
33+
app: late
34+
spec:
35+
terminationGracePeriodSeconds: 10
36+
containers:
37+
- name: nginx
38+
image: registry.k8s.io/nginx-slim:0.24
39+
volumeMounts:
40+
- name: config
41+
mountPath: "/config"
42+
envFrom:
43+
- configMapRef:
44+
name: late-config-2
45+
volumes:
46+
- name: config
47+
configMap:
48+
name: late-config
49+
---
50+
apiVersion: v1
51+
kind: Service
52+
metadata:
53+
name: late
54+
labels:
55+
app: late
56+
spec:
57+
clusterIP: None
58+
selector:
59+
app: late

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ spec:
4141
volumeMounts:
4242
- name: config
4343
mountPath: /config
44+
terminationGracePeriodSeconds: 5

tests/test-definition.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ tests:
77
- name: restarter
88
dimensions:
99
- openshift
10+
- name: restarter-no-unneeded-restart
11+
dimensions:
12+
- openshift
1013
suites:
1114
- name: nightly
1215
- name: openshift

0 commit comments

Comments
 (0)