Skip to content

Commit 3ba85e6

Browse files
authored
Merge pull request #199 from cognifloyd/packs-volumes
Add custom packs volumes
2 parents fd2e6db + cde22a6 commit 3ba85e6

File tree

7 files changed

+259
-75
lines changed

7 files changed

+259
-75
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## In Development
4+
* New feature: Shared packs volumes `st2.packs.volumes`. Allow using cluster-specific persistent volumes to store packs, virtualenvs, and (optionally) configs. This enables using `st2 pack install`. It even works with `st2packs` images in `st2.packs.images`. (#199) (by @cognifloyd)
45
* Updated redis constant sentinel ID which will allow other sentinel peers to update to the new given IP in case of pod failure or worker node reboots. (#191) (by @manisha-tanwar)
56
* Removed reference to st2-license pullSecrets, which was missed when removing enterprise flags (#192) (by @cognifloyd)
67
* Add optional imagePullSecrets to ServiceAccount using `serviceAccount.pullSecret` from values.yaml. If pods do not have imagePullSecrets (eg without `image.pullSecret` in values.yaml), k8s populates them from the ServiceAccount. (#196) (by @cognifloyd)

README.md

Lines changed: 100 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ st2:
140140
- name: circleci
141141
ref: circle_ci.CircleCIWebhookSensor
142142
```
143-
143+
144144
### [st2actionrunner](https://docs.stackstorm.com/reference/ha.html#st2actionrunner)
145145
Stackstorm workers that actually execute actions.
146146
`5` replicas for K8s Deployment are configured by default to increase StackStorm ability to execute actions without excessive queuing.
@@ -181,15 +181,25 @@ StackStorm employs redis sentinel as a distributed coordination backend, require
181181
As any other Helm dependency, it's possible to further configure it for specific scaling needs via `values.yaml`.
182182

183183
## Install custom st2 packs in the cluster
184-
In distributed environment of the Kubernetes cluster `st2 pack install` won’t work.
184+
There are two ways to install st2 packs in the k8s cluster.
185+
186+
1. The `st2packs` method is the default. This method will work for practically all clusters, but `st2 pack install` does not work. The packs are injected via `st2packs` images instead.
187+
188+
2. The other method defines shared/writable `volumes`. This method allows `st2 pack install` to work, but requires a persistent storage backend to be available in the cluster. This chart will not configure a storage backend for you.
189+
190+
NOTE: In general, we recommend using only one of these methods. See the NOTE under Method 2 below about how both methods can be used together with care.
191+
192+
### Method 1: st2packs images (the default)
193+
The `st2packs` method is the default. `st2 pack install` does not work because this chart (by default) uses read-only `emptyDir` volumes for `/opt/stackstorm/{packs,virtualenvs}`.
185194
Instead, you need to bake the packs into a custom docker image, push it to a private or public docker registry and reference that image in Helm values.
186-
Helm chart will take it from there, sharing `/opt/stackstorm/{packs,virtualenvs}` via a sidecar container in pods which require access to the packs.
195+
Helm chart will take it from there, sharing `/opt/stackstorm/{packs,virtualenvs}` via a sidecar container in pods which require access to the packs
196+
(the sidecar is the only place where the volumes are writable).
187197

188-
### Building st2packs image
198+
#### Building st2packs image
189199
For your convenience, we created a new `st2-pack-install <pack1> <pack2> <pack3>` utility and included it in a container that will help to install custom packs during the Docker build process without relying on live DB and MQ connection.
190200
Please see https://github.com/StackStorm/st2packs-dockerfiles/ for instructions on how to build your custom `st2packs` image.
191201

192-
### How to provide custom pack configs
202+
#### How to provide custom pack configs
193203
Update the `st2.packs.configs` section of Helm values:
194204

195205
For example:
@@ -205,7 +215,9 @@ For example:
205215
```
206216
Don't forget running Helm upgrade to apply new changes.
207217

208-
### Pull st2packs from a private Docker registry
218+
NOTE: On `helm upgrade` any configs in `st2.packs.configs` will overwrite the contents of `st2.packs.volumes.configs` (optional part of Method 2, described below).
219+
220+
#### Pull st2packs from a private Docker registry
209221
If you need to pull your custom packs Docker image from a private repository, create a Kubernetes Docker registry secret and pass it to Helm values.
210222
See [K8s documentation](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/) for more info.
211223
```
@@ -214,6 +226,88 @@ kubectl create secret docker-registry st2packs-auth --docker-server=<your-regist
214226
```
215227
Once secret created, reference its name in helm value: `st2.packs.images[].pullSecret`.
216228

229+
### Method 2: Shared Volumes
230+
This method requires cluster-specific storage setup and configuration. As the storage volumes are both writable and shared, `st2 pack install` should work like it does for standalone StackStorm installations. The volumes get mounted at `/opt/stackstorm/{packs,virtualenvs}` in the containers that need read or write access to those directories. With this method, `/opt/stackstorm/configs` can also be mounted as a writable volume (in which case the contents of `st2.packs.configs` takes precedence on `helm upgrade`).
231+
232+
NOTE: With care, `st2packs` images can be used with `volumes`. Just make sure to keep the `st2packs` images up-to-date with any changes made via `st2 pack install`.
233+
If a pack is installed via an `st2packs` image and then it gets updated with `st2 pack install`, a subsequent `helm upgrade` will revert back to the version in the `st2packs` image.
234+
235+
#### Configure the storage volumes
236+
Enable the `st2.packs.voluems` section of Helm values and add volume definitions for both `packs` and `virtualenvs`.
237+
Each of the volume definitions should be customized for your cluster and storage solution.
238+
239+
For example, to use persistentVolumeClaims:
240+
```
241+
volumes:
242+
enabled: true
243+
packs:
244+
persistentVolumeClaim:
245+
claim-name: pvc-st2-packs
246+
virtualenvs:
247+
persistentVolumeClaim:
248+
claim-name: pvc-st2-virtualenvs
249+
```
250+
251+
Or, for example, to use NFS:
252+
```
253+
volumes:
254+
enabled: true
255+
packs:
256+
nfs:
257+
server: nfs.example.com
258+
path: /var/nfsshare/packs
259+
virtualenvs:
260+
nfs:
261+
server: nfs.example.com
262+
path: /var/nfsshare/virtualenvs
263+
```
264+
265+
Please consult the documentation for your cluster's storage solution to see how to add the storage backend to your cluster and how to define volumes that use your storage backend.
266+
267+
#### How to provide custom pack configs
268+
You may either use the `st2.packs.configs` section of Helm values (like Method 1, see above),
269+
or add another shared writable volume similar to `packs` and `virtualenvs`. This volume gets mounted
270+
to `/opt/stackstorm/configs` instead of the `st2.packs.config` values.
271+
272+
NOTE: If you define a configs volume and specify `st2.packs.configs`, anything in `st2.packs.configs` takes precdence during `helm upgrade`, overwriting config files already in the volume.
273+
274+
For example, to use persistentVolumeClaims:
275+
```
276+
volumes:
277+
enabled: true
278+
... # define packs and virtualenvs volumes as shown above
279+
configs:
280+
persistentVolumeClaim:
281+
claim-name: pvc-st2-pack-configs
282+
```
283+
284+
Or, for example, to use NFS:
285+
```
286+
volumes:
287+
enabled: true
288+
... # define packs and virtualenvs volumes as shown above
289+
configs:
290+
nfs:
291+
server: nfs.example.com
292+
path: /var/nfsshare/configs
293+
```
294+
295+
#### Caveat: Mounting and copying packs
296+
If you use something like NFS where you can mount the shares outside of the StackStorm pods, there are a couple of things to keep in mind.
297+
298+
Though you could manually copy packs into the `packs` shared volume, be aware that StackStorm does not automatically register any changed content.
299+
So, if you manually copy a pack into the `packs` shared volume, then you also need to trigger updating the virtualenv and registering the content,
300+
possibly using APIs like:
301+
[packs/install](https://api.stackstorm.com/api/v1/packs/#/packs_controller.install.post), and
302+
[packs/register](https://api.stackstorm.com/api/v1/packs/#/packs_controller.register.post)
303+
You will have to repeat the process each time the packs code is modified.
304+
305+
#### Caveat: System packs
306+
After Helm installs, upgrades, or rolls back a StackStorm install, it runs an `st2-register-content` batch job.
307+
This job will copy and register system packs. If you have made any changes (like disabling default aliases), those changes will be overwritten.
308+
309+
NOTE: Upgrades will not remove files (such as a renamed or removed action) if they were removed in newer StackStorm versions.
310+
This mirrors the how pack registration works. Make sure to review any upgrade notes and manually handle any removals.
217311

218312
## Tips & Tricks
219313
Grab all logs for entire StackStorm cluster with dependent services in Helm release:

templates/_helpers.tpl

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,69 @@ Create the name of the stackstorm-ha service account to use
120120
{{- end }}
121121
{{- end -}}
122122

123+
# consolidate pack-configs-volumes definitions
124+
{{- define "pack-configs-volume" -}}
125+
{{- if and .Values.st2.packs.volumes.enabled .Values.st2.packs.volumes.configs }}
126+
- name: st2-pack-configs-vol
127+
{{- toYaml .Values.st2.packs.volumes.configs | nindent 2 }}
128+
{{- if .Values.st2.packs.configs }}
129+
- name: st2-pack-configs-from-helm-vol
130+
configMap:
131+
name: {{ .Release.Name }}-st2-pack-configs
132+
{{- end }}
133+
{{- else }}
134+
- name: st2-pack-configs-vol
135+
configMap:
136+
name: {{ .Release.Name }}-st2-pack-configs
137+
{{- end }}
138+
{{- end -}}
139+
{{- define "pack-configs-volume-mount" -}}
140+
- name: st2-pack-configs-vol
141+
mountPath: /opt/stackstorm/configs/
142+
{{- if and .Values.st2.packs.volumes.enabled .Values.st2.packs.volumes.configs .Values.st2.packs.configs }}
143+
- name: st2-pack-configs-from-helm-vol
144+
mountPath: /opt/stackstorm/configs-helm/
145+
{{- end }}
146+
{{- end -}}
147+
123148
# For custom st2packs-Container reduce duplicity by defining it here once
124149
{{- define "packs-volumes" -}}
125-
{{- if .Values.st2.packs.images }}
150+
{{- if .Values.st2.packs.volumes.enabled }}
151+
- name: st2-packs-vol
152+
{{- toYaml .Values.st2.packs.volumes.packs | nindent 2 }}
153+
- name: st2-virtualenvs-vol
154+
{{- toYaml .Values.st2.packs.volumes.virtualenvs | nindent 2 }}
155+
{{- else if .Values.st2.packs.images }}
126156
- name: st2-packs-vol
127157
emptyDir: {}
128158
- name: st2-virtualenvs-vol
129159
emptyDir: {}
130160
{{- end }}
131161
{{- end -}}
162+
{{- define "packs-volume-mounts" -}}
163+
{{- if .Values.st2.packs.volumes.enabled }}
164+
- name: st2-packs-vol
165+
mountPath: /opt/stackstorm/packs
166+
- name: st2-virtualenvs-vol
167+
mountPath: /opt/stackstorm/virtualenvs
168+
{{- else if .Values.st2.packs.images }}
169+
- name: st2-packs-vol
170+
mountPath: /opt/stackstorm/packs
171+
readOnly: true
172+
- name: st2-virtualenvs-vol
173+
mountPath: /opt/stackstorm/virtualenvs
174+
readOnly: true
175+
{{- end }}
176+
{{- end -}}
177+
# define this here as well to simplify comparison with packs-volume-mounts
178+
{{- define "packs-volume-mounts-for-register-job" -}}
179+
{{- if or .Values.st2.packs.images .Values.st2.packs.volumes.enabled }}
180+
- name: st2-packs-vol
181+
mountPath: /opt/stackstorm/packs
182+
- name: st2-virtualenvs-vol
183+
mountPath: /opt/stackstorm/virtualenvs
184+
{{- end }}
185+
{{- end -}}
132186

133187
# For custom st2packs-initContainers reduce duplicity by defining them here once
134188
# Merge packs and virtualenvs from st2 with those from st2packs images
@@ -150,6 +204,8 @@ Create the name of the stackstorm-ha service account to use
150204
/bin/cp -aR /opt/stackstorm/packs/. /opt/stackstorm/packs-shared &&
151205
/bin/cp -aR /opt/stackstorm/virtualenvs/. /opt/stackstorm/virtualenvs-shared
152206
{{- end }}
207+
{{- end }}
208+
{{- if or $.Values.st2.packs.images $.Values.st2.packs.volumes.enabled }}
153209
# System packs
154210
- name: st2-system-packs
155211
image: '{{ template "imageRepository" . }}/st2actionrunner:{{ tpl (.Values.st2actionrunner.image.tag | default .Values.image.tag) . }}'
@@ -166,6 +222,22 @@ Create the name of the stackstorm-ha service account to use
166222
/bin/cp -aR /opt/stackstorm/packs/. /opt/stackstorm/packs-shared &&
167223
/bin/cp -aR /opt/stackstorm/virtualenvs/. /opt/stackstorm/virtualenvs-shared
168224
{{- end }}
225+
{{- if and $.Values.st2.packs.configs $.Values.st2.packs.volumes.enabled }}
226+
# Pack configs defined in helm values
227+
- name: st2-pack-configs-from-helm
228+
image: '{{ template "imageRepository" . }}/st2actionrunner:{{ tpl (.Values.st2actionrunner.image.tag | default .Values.image.tag) . }}'
229+
imagePullPolicy: {{ .Values.image.pullPolicy }}
230+
volumeMounts:
231+
- name: st2-pack-configs-vol
232+
mountPath: /opt/stackstorm/configs-shared
233+
- name: st2-pack-configs-from-helm-vol
234+
mountPath: /opt/stackstorm/configs
235+
command:
236+
- 'sh'
237+
- '-ec'
238+
- |
239+
/bin/cp -aR /opt/stackstorm/configs/. /opt/stackstorm/configs-shared
240+
{{- end }}
169241
{{- end -}}
170242

171243

templates/configmaps_packs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ kind: ConfigMap
44
metadata:
55
name: {{ .Release.Name }}-st2-pack-configs
66
annotations:
7-
description: Custom StackStorm pack configs, shipped in '/opt/stackstorm/configs/'
7+
description: StackStorm pack configs defined in helm values, shipped in (or copied to) '/opt/stackstorm/configs/'
88
labels:
99
app: st2
1010
tier: backend

0 commit comments

Comments
 (0)