Skip to content

Commit 2c03fb1

Browse files
committed
Merge branch 'master' into dynamic-st2sensors
2 parents 4a8268d + 524c0e1 commit 2c03fb1

15 files changed

+1888
-3
lines changed

.github/workflows/unit-tests.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
name: Unit Tests
3+
4+
on:
5+
push:
6+
branches:
7+
- master
8+
pull_request:
9+
branches:
10+
- master
11+
12+
jobs:
13+
helm-unittest:
14+
15+
runs-on: ubuntu-latest
16+
# strategy:
17+
# matrix:
18+
# Relevant tools installed by default on ubuntu 20.04:
19+
# - helm 3.8.0
20+
# - jq 1.6
21+
# - kind 0.11.1
22+
# - kubectl 1.23.3
23+
# - minikube 1.25.1
24+
# - python 3.8.10
25+
# - yamllint 1.26.3
26+
# - yq 4.19.1
27+
# see: https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-Readme.md
28+
29+
steps:
30+
- uses: actions/checkout@v2
31+
32+
- name: Install helm-unittest
33+
# We should periodically check to see if another fork has taken over maintenance,
34+
# as the de-facto "best" fork has changed several times over the years.
35+
run: |
36+
helm plugin install https://github.com/quintush/helm-unittest
37+
38+
- name: Install chart dependencies
39+
run: |
40+
helm dependency update
41+
42+
- name: Run helm-unittest
43+
# by default looks for tests/*_test.yaml
44+
run: |
45+
helm unittest --color --helm3 -f 'tests/unit/*_test.yaml' .

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +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)
78
* Allow partitioning sensors using the hash_range strategy instead of one sensor per pod. (#218) (by @cognifloyd)
89

910
## v0.80.0

templates/tests/st2tests-configmap.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ metadata:
1111
heritage: {{ .Release.Service }}
1212
data:
1313
st2tests.sh: |
14-
{{ .Files.Get "tests/st2tests.sh" | indent 4 }}
14+
{{ .Files.Get "tests/integration/st2tests.sh" | indent 4 }}

tests/README.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
11
# `stackstorm-ha` Helm chart Tests
22

3-
This directory contains Helm chart tests, powered by [BATS](https://github.com/sstephenson/bats) Bash Automated Testing System.
3+
This directory contains Helm chart unit and integration tests (under `tests/unit/` and `tests/integration/` respectively).
4+
5+
## Unit tests
6+
7+
Unit tests (`tests/unit/*_test.yaml`) use [`helm-unittest`](https://github.com/quintush/helm-unittest).
8+
`helm-unittest` uses a yaml-based test file to ensure that the templates generate expected features.
9+
For example, they can ensure that custom annotations are applied consistently to all of the deployments.
10+
Unit tests do not require a running kubernetes cluster.
11+
12+
Before running unit tests, install the `helm-unittest` plugin and ensure you have sub-charts installed:
13+
```
14+
helm plugin install https://github.com/quintush/helm-unittest
15+
helm dependency update
16+
```
17+
18+
To run the tests manually from the chart's root dir:
19+
```
20+
helm unittest --helm3 -f 'tests/unit/*_test.yaml' .
21+
```
22+
23+
> Note! If you need to add unit tests, file names should follow this pattern: `tests/unit/name_your_test.yaml`
24+
25+
See https://github.com/quintush/helm-unittest/blob/master/DOCUMENT.md for details on writing unit tests.
26+
27+
## Integration tests
28+
29+
Integration tests (under `tests/integration/`) use `helm-test` and are powered by [BATS](https://github.com/sstephenson/bats) (Bash Automated Testing System).
30+
As integratin tests, these require a running kubernetes cluster where helm can do test deployments of this chart.
31+
432
Despite the minimum amount of smoke tests written, they ensure that StackStorm was really deployed,
533
works correctly at its core and alive end-to-end without checking deeply specific functionality or configuration.
634
If something is terribly wrong, - it'll show up via failed tests.
@@ -18,4 +46,4 @@ To show the test results:
1846
kubectl logs <release-name>-st2tests
1947
```
2048

21-
See https://helm.sh/docs/developing_charts/#chart-tests with more information about Helm chart tests.
49+
See https://helm.sh/docs/topics/chart-tests/ with more information about Helm chart tests.
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
---
2+
suite: Custom Annotations
3+
templates:
4+
# primary template files
5+
- deployments.yaml
6+
- ingress.yaml
7+
- jobs.yaml
8+
- service-account.yaml
9+
- services.yaml
10+
11+
# included templates must also be listed
12+
- configmaps_packs.yaml
13+
- configmaps_rbac.yaml
14+
- configmaps_st2-conf.yaml
15+
- configmaps_st2-urls.yaml
16+
- configmaps_st2web.yaml
17+
- secrets_datastore_crypto_key.yaml
18+
- secrets_ssh.yaml
19+
- secrets_st2apikeys.yaml
20+
- secrets_st2auth.yaml
21+
- secrets_st2chatops.yaml
22+
23+
tests:
24+
- it: ServiceAccount accepts custom annotations
25+
template: service-account.yaml
26+
set:
27+
serviceAccount:
28+
create: true
29+
serviceAccountAnnotations: &annotations
30+
foo: bar
31+
answer: "42"
32+
asserts: &annotations_asserts
33+
- isNotNull:
34+
path: metadata.annotations
35+
- equal:
36+
path: metadata.annotations.foo
37+
value: bar
38+
- equal:
39+
path: metadata.annotations.answer
40+
value: "42"
41+
42+
- it: st2web Ingress accepts custom annotations
43+
template: ingress.yaml
44+
set:
45+
st2web:
46+
service:
47+
hostname: some-host-name
48+
ingress:
49+
enabled: true
50+
annotations: *annotations
51+
asserts: *annotations_asserts
52+
53+
# st2auth, st2api, st2stream services do not accept custom annotations
54+
55+
- it: st2web Service accepts custom annotations
56+
template: services.yaml
57+
documentIndex: 3
58+
set:
59+
st2web:
60+
service:
61+
hostname: some-host-name
62+
annotations: *annotations
63+
asserts: *annotations_asserts
64+
65+
# st2chatops service does not accept custom annotations
66+
67+
- it: Deployments+Pods accept custom annotations
68+
template: deployments.yaml
69+
set:
70+
st2auth:
71+
annotations: &deployment_annotations
72+
foo: bar
73+
answer: "42"
74+
st2api:
75+
annotations: *deployment_annotations
76+
st2stream:
77+
annotations: *deployment_annotations
78+
st2web:
79+
annotations: *deployment_annotations
80+
st2rulesengine:
81+
annotations: *deployment_annotations
82+
st2timersengine:
83+
annotations: *deployment_annotations
84+
st2workflowengine:
85+
annotations: *deployment_annotations
86+
st2scheduler:
87+
annotations: *deployment_annotations
88+
st2notifier:
89+
annotations: *deployment_annotations
90+
st2sensorcontainer:
91+
annotations: *deployment_annotations
92+
st2: { packs: { sensors: [] } } # ensure only 1 sensor
93+
st2actionrunner:
94+
annotations: *deployment_annotations
95+
st2garbagecollector:
96+
annotations: *deployment_annotations
97+
st2client:
98+
annotations: *deployment_annotations
99+
st2chatops:
100+
enabled: true
101+
annotations: *deployment_annotations
102+
asserts:
103+
- hasDocuments:
104+
count: 14
105+
# st2auth, st2api,
106+
# st2stream, st2web,
107+
# st2rulesengine, st2timersengine,
108+
# st2workflowengine, st2scheduler,
109+
# st2notifier, (1) st2sensorcontainer,
110+
# st2actionrunner, st2garbagecollector,
111+
# st2client, st2chatops
112+
113+
# deployment annotations
114+
- isNotNull:
115+
path: metadata.annotations
116+
- equal:
117+
path: metadata.annotations.foo
118+
value: bar
119+
- equal:
120+
path: metadata.annotations.answer
121+
value: "42"
122+
123+
# pod annotations
124+
- isNotNull:
125+
path: spec.template.metadata.annotations
126+
- equal:
127+
path: spec.template.metadata.annotations.foo
128+
value: bar
129+
- equal:
130+
path: spec.template.metadata.annotations.answer
131+
value: "42"
132+
133+
- it: Jobs+Pods accept custom annotations
134+
template: jobs.yaml
135+
set:
136+
st2:
137+
rbac:
138+
enabled: true # enable rbac job
139+
jobs:
140+
annotations:
141+
foo: bar
142+
answer: "42"
143+
asserts:
144+
- hasDocuments:
145+
count: 4
146+
# job-st2-apply-rbac-defintions
147+
# job-st2-apikey-load
148+
# job-st2-key-load
149+
# job-st2-register-content
150+
151+
# job annotations
152+
- isNotNull:
153+
path: metadata.annotations
154+
- equal:
155+
path: metadata.annotations.foo
156+
value: bar
157+
- equal:
158+
path: metadata.annotations.answer
159+
value: "42"
160+
161+
# pod annotations
162+
- isNotNull:
163+
path: spec.template.metadata.annotations
164+
- equal:
165+
path: spec.template.metadata.annotations.foo
166+
value: bar
167+
- equal:
168+
path: spec.template.metadata.annotations.answer
169+
value: "42"

tests/unit/dns_test.yaml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
suite: DNS
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 and Jobs default to no dnsPolicy or dnsConfig
22+
templates:
23+
- deployments.yaml
24+
- jobs.yaml
25+
set:
26+
st2:
27+
packs: { sensors: [] } # ensure only 1 sensor
28+
rbac: { enabled: true } # enable rbac job
29+
asserts:
30+
- isNull:
31+
path: spec.template.spec.dnsPolicy
32+
- isNull:
33+
path: spec.template.spec.dnsConfig
34+
35+
- it: Deployments and Jobs accept custom dnsPolicy or dnsConfig
36+
templates:
37+
- deployments.yaml
38+
- jobs.yaml
39+
set:
40+
dnsPolicy: &dnsPolicy ClusterFirstWithHostNet
41+
dnsConfig: &dnsConfig
42+
nameservers:
43+
- 1.2.3.4
44+
searches:
45+
- ns1.svc.cluster-domain.example
46+
- my.dns.search.suffix
47+
options:
48+
- name: ndots
49+
value: "2"
50+
- name: edns0
51+
st2:
52+
packs: { sensors: [] } # ensure only 1 sensor
53+
rbac: { enabled: true } # enable rbac job
54+
asserts:
55+
- equal:
56+
path: spec.template.spec.dnsPolicy
57+
value: *dnsPolicy
58+
- equal:
59+
path: spec.template.spec.dnsConfig
60+
value: *dnsConfig

0 commit comments

Comments
 (0)