Skip to content

Commit 270f358

Browse files
authored
Merge pull request #292 from StackStorm/helm-unittest
Add unit tests for env, envFrom, st2.packs.images, and st2.packs.volumes
2 parents 4da2983 + 35ce7b6 commit 270f358

File tree

4 files changed

+1310
-3
lines changed

4 files changed

+1310
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Advanced Feature: Make securityContext (on Deployments/Jobs) and podSecurityContext (on Pods) configurable. This allows dropping all capabilities, for example. You can override the securityContext for `st2actionrunner`, `st2sensorcontainer`, and `st2client` if your actions or sensors need, for example, additional capabilites that the rest of StackStorm does not need. (#271) (by @cognifloyd)
55
* Prefix template helpers with chart name and format helper comments as template comments. (#272) (by @cognifloyd)
66
* New feature: Add `extra_volumes` to all python-based st2 deployments. This can facilitate changing log levels by loading logging conf file(s) from a custom ConfigMap. (#276) (by @cognifloyd)
7-
* Initialize basic unittest infrastructure using `helm-unittest`. Added tests for labels, custom annotations, SecurityContext, pullSecrets, pullPolicy, Resources, nodeSelector, tolerations, affinity, dnsPolicy, dnsConfig, ServiceAccount attach, postStartScript, and both sensor-modes. (#284, #288)
7+
* Initialize basic unittest infrastructure using `helm-unittest`. Added tests for labels, custom annotations, SecurityContext, pullSecrets, pullPolicy, Resources, nodeSelector, tolerations, affinity, dnsPolicy, dnsConfig, ServiceAccount attach, postStartScript, both sensor-modes, env, envFrom, st2.packs.images, and st2.packs.volumes. (#284, #288, #292)
88
* Allow partitioning sensors using the hash_range strategy instead of one sensor per pod. (#218) (by @cognifloyd)
99
* New feature to include possibility for external services in st2api, st2stream and st2auth, setting default value for this services as `ClusterIP` and `hostname: ""`. Also, added new entry for custom_annotations_test.yaml and created new unit test services_test.yaml. (by @sandesvitor)
1010

templates/deployments.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,6 @@ spec:
485485
envFrom:
486486
- configMapRef:
487487
name: {{ .Release.Name }}-st2-urls
488-
optional: true
489488
{{- if or .Values.st2web.config .Values.st2web.extra_volumes .Values.st2web.postStartScript }}
490489
volumeMounts:
491490
{{- else }}
@@ -1306,7 +1305,7 @@ spec:
13061305
{{- end }}
13071306
{{- end }}
13081307
{{- if $sensor.env }}
1309-
env: {{- include "stackstorm-ha.customEnv" . | nindent 8 }}
1308+
env: {{- include "stackstorm-ha.customEnv" $sensor | nindent 8 }}
13101309
{{- end }}
13111310
envFrom:
13121311
- configMapRef:
@@ -1964,6 +1963,9 @@ spec:
19641963
configMap:
19651964
name: {{ .Release.Name }}-st2chatops-post-start-script
19661965
{{- end }}
1966+
{{- else }}
1967+
volumeMounts: []
1968+
volumes: []
19671969
{{- end }}
19681970
{{- if .Values.st2chatops.serviceAccount.attach }}
19691971
serviceAccountName: {{ template "stackstorm-ha.serviceAccountName" . }}

tests/unit/env_test.yaml

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
---
2+
suite: Environment Vars
3+
templates:
4+
# primary template files
5+
- deployments.yaml
6+
- jobs.yaml
7+
8+
# included templates must also be listed
9+
- configmaps_packs.yaml
10+
- configmaps_rbac.yaml
11+
- configmaps_st2-conf.yaml
12+
- configmaps_st2-urls.yaml
13+
- configmaps_st2web.yaml
14+
- secrets_datastore_crypto_key.yaml
15+
- secrets_ssh.yaml
16+
- secrets_st2apikeys.yaml
17+
- secrets_st2auth.yaml
18+
- secrets_st2chatops.yaml
19+
20+
tests:
21+
- it: Deployments default to no env (except st2client)
22+
template: deployments.yaml
23+
set:
24+
st2: { packs: { sensors: [] } } # ensure only 1 sensor
25+
st2chatops:
26+
enabled: true
27+
asserts:
28+
- hasDocuments:
29+
count: 14
30+
- equal:
31+
path: spec.template.spec.containers[0].env
32+
value:
33+
- name: ST2CLIENT
34+
value: "1"
35+
documentIndex: 12
36+
- isNull: &is_null_env
37+
path: spec.template.spec.containers[0].env
38+
documentIndex: 0
39+
- isNull: *is_null_env
40+
documentIndex: 1
41+
- isNull: *is_null_env
42+
documentIndex: 2
43+
- isNull: *is_null_env
44+
documentIndex: 3
45+
- isNull: *is_null_env
46+
documentIndex: 4
47+
- isNull: *is_null_env
48+
documentIndex: 5
49+
- isNull: *is_null_env
50+
documentIndex: 6
51+
- isNull: *is_null_env
52+
documentIndex: 7
53+
- isNull: *is_null_env
54+
documentIndex: 8
55+
- isNull: *is_null_env
56+
documentIndex: 9
57+
- isNull: *is_null_env
58+
documentIndex: 10
59+
- isNull: *is_null_env
60+
documentIndex: 11
61+
- isNull: *is_null_env
62+
documentIndex: 13
63+
64+
- it: Jobs default to no env
65+
template: jobs.yaml
66+
set:
67+
st2:
68+
rbac: { enabled: true } # enable rbac job
69+
asserts:
70+
- hasDocuments:
71+
count: 4
72+
- isNull: *is_null_env
73+
74+
- it: Deployments accept custom env
75+
template: deployments.yaml
76+
set:
77+
st2auth:
78+
env: &env
79+
FOO: bar
80+
st2api:
81+
env: *env
82+
st2stream:
83+
env: *env
84+
st2web:
85+
env: *env
86+
st2rulesengine:
87+
env: *env
88+
st2timersengine:
89+
env: *env
90+
st2workflowengine:
91+
env: *env
92+
st2scheduler:
93+
env: *env
94+
st2notifier:
95+
env: *env
96+
st2sensorcontainer:
97+
env: *env
98+
st2: { packs: { sensors: [] } } # ensure only 1 sensor
99+
st2actionrunner:
100+
env: *env
101+
st2garbagecollector:
102+
env: *env
103+
st2client:
104+
env: *env
105+
st2chatops:
106+
enabled: false
107+
asserts:
108+
- hasDocuments:
109+
count: 13 # st2chatops env handled as secrets
110+
111+
- contains: &contains_env
112+
path: spec.template.spec.containers[0].env
113+
content:
114+
name: FOO
115+
value: bar
116+
117+
- it: Jobs accept custom env
118+
template: jobs.yaml
119+
set:
120+
st2:
121+
rbac: { enabled: true } # enable rbac job
122+
jobs:
123+
env: *env
124+
asserts:
125+
- hasDocuments:
126+
count: 4
127+
128+
- contains: *contains_env
129+
130+
- it: Deployments envFrom defaults include st2-urls configMap and st2chatops secretRef
131+
template: deployments.yaml
132+
set:
133+
st2: { packs: { sensors: [] } } # ensure only 1 sensor
134+
st2chatops:
135+
enabled: true
136+
release:
137+
name: st2ha
138+
asserts:
139+
- hasDocuments:
140+
count: 14
141+
- contains: &contains_st2_urls
142+
path: spec.template.spec.containers[0].envFrom
143+
content:
144+
configMapRef:
145+
name: st2ha-st2-urls
146+
# this is how st2chatops.env loads vars
147+
- contains:
148+
path: spec.template.spec.containers[0].envFrom
149+
content:
150+
secretRef: # not a configMap
151+
name: st2ha-st2chatops
152+
documentIndex: 13
153+
154+
- it: Jobs envFrom defaults
155+
template: jobs.yaml
156+
set:
157+
st2:
158+
rbac: { enabled: true } # enable rbac job
159+
release:
160+
name: st2ha
161+
asserts:
162+
- hasDocuments:
163+
count: 4
164+
165+
- contains: *contains_st2_urls
166+
documentIndex: 1
167+
- contains: *contains_st2_urls
168+
documentIndex: 2
169+
170+
- isNull: &is_null_envFrom
171+
path: spec.template.spec.containers[0].envFrom
172+
documentIndex: 0
173+
- isNull: *is_null_envFrom
174+
documentIndex: 3
175+
176+
- it: Deployments support envFromSecrets (st2actionrunner, st2sensorcontainer, and st2client)
177+
template: deployments.yaml
178+
set:
179+
st2: { packs: { sensors: [] } } # ensure only 1 sensor
180+
st2actionrunner:
181+
envFromSecrets: &envFromSecrets
182+
- my-external-secret-1
183+
- my-external-secret-2
184+
st2sensorcontainer:
185+
envFromSecrets: *envFromSecrets
186+
st2client:
187+
envFromSecrets: *envFromSecrets
188+
asserts:
189+
- contains: &contains_external_secret1
190+
path: spec.template.spec.containers[0].envFrom
191+
content:
192+
secretRef:
193+
name: my-external-secret-1
194+
documentIndex: 9
195+
- contains: *contains_external_secret1
196+
documentIndex: 10
197+
- contains: *contains_external_secret1
198+
documentIndex: 12
199+
200+
- contains: &contains_external_secret2
201+
path: spec.template.spec.containers[0].envFrom
202+
content:
203+
secretRef:
204+
name: my-external-secret-2
205+
documentIndex: 9
206+
- contains: *contains_external_secret2
207+
documentIndex: 10
208+
- contains: *contains_external_secret2
209+
documentIndex: 12
210+
211+
- it: Jobs support envFromSecrets
212+
template: jobs.yaml
213+
set:
214+
st2:
215+
rbac: { enabled: true } # enable rbac job
216+
jobs:
217+
envFromSecrets: *envFromSecrets
218+
asserts:
219+
- contains: *contains_external_secret1
220+
- contains: *contains_external_secret2

0 commit comments

Comments
 (0)