Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom packs volumes #199

Merged
merged 23 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a961ad5
add st2.packs.volumes section to volumes.yaml
cognifloyd Jun 17, 2021
51960b2
consolidate packs-volume-mounts into templates
cognifloyd Jun 17, 2021
7ac2ed5
add st2.packs.volumes definitions to packs-volumes templates
cognifloyd Jun 17, 2021
0e603ad
consolidate pack-configs-volume into templates
cognifloyd Jun 17, 2021
c7f50cd
add pack-configs-volume to more pods when st2.packs.volumes.enabled
cognifloyd Jun 17, 2021
e0ae60a
add error messages if st2.packs.volumes config is incomplete
cognifloyd Jun 17, 2021
86d4793
When st2.packs.volumes.enabled, make register-content packs-initConta…
cognifloyd Jun 17, 2021
bd72f51
disable packs.configs ConfigMap if it is not needed/used
cognifloyd Jun 17, 2021
0f1c9c3
add instructions for st2.packs.volumes values
cognifloyd Jun 17, 2021
2e2b7e9
add st2.packs.volumes caveats similar to those documented in #118
cognifloyd Jun 17, 2021
808a7d6
Populate default empty maps for st2.packs.images, st2.packs.volumes.(…
ericreeves Jun 19, 2021
6e638d0
st2.packs.images is an array
cognifloyd Jun 20, 2021
b80a058
add changelog entry
cognifloyd Jun 17, 2021
4887361
allow using st2.packs.volumes with st2.packs.images
cognifloyd Jul 10, 2021
1bf2ae9
update changelog entry
cognifloyd Jul 10, 2021
7be8ebc
explain using volumes with st2packs images in README
cognifloyd Jul 10, 2021
938ee9e
Check for volumes.enabled before checking for images
ericreeves Jul 10, 2021
a9e582f
Allow st2.packs.configs to work with st2.packs.volumes.configs
cognifloyd Jul 10, 2021
f1a3970
improve spacing in templates
cognifloyd Jul 10, 2021
2110818
The trailing '&&' without a second command is bad syntax.
ericreeves Jul 14, 2021
aedf6cf
fix rook-ceph volume example
cognifloyd Jul 23, 2021
5456f40
Merge branch 'master' into packs-volumes
cognifloyd Jul 27, 2021
cde22a6
Merge branch 'master' into packs-volumes
arm4b Aug 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## In Development
* 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)
* 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)
* Removed reference to st2-license pullSecrets, which was missed when removing enterprise flags (#192) (by @cognifloyd)
* 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)
Expand Down
106 changes: 100 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ st2:
- name: circleci
ref: circle_ci.CircleCIWebhookSensor
```

### [st2actionrunner](https://docs.stackstorm.com/reference/ha.html#st2actionrunner)
Stackstorm workers that actually execute actions.
`5` replicas for K8s Deployment are configured by default to increase StackStorm ability to execute actions without excessive queuing.
Expand Down Expand Up @@ -181,15 +181,25 @@ StackStorm employs redis sentinel as a distributed coordination backend, require
As any other Helm dependency, it's possible to further configure it for specific scaling needs via `values.yaml`.

## Install custom st2 packs in the cluster
In distributed environment of the Kubernetes cluster `st2 pack install` won’t work.
There are two ways to install st2 packs in the k8s cluster.

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.

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.

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.

### Method 1: st2packs images (the default)
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}`.
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.
Helm chart will take it from there, sharing `/opt/stackstorm/{packs,virtualenvs}` via a sidecar container in pods which require access to the packs.
Helm chart will take it from there, sharing `/opt/stackstorm/{packs,virtualenvs}` via a sidecar container in pods which require access to the packs
(the sidecar is the only place where the volumes are writable).

### Building st2packs image
#### Building st2packs image
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.
Please see https://github.com/StackStorm/st2packs-dockerfiles/ for instructions on how to build your custom `st2packs` image.

### How to provide custom pack configs
#### How to provide custom pack configs
Update the `st2.packs.configs` section of Helm values:

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

### Pull st2packs from a private Docker registry
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).

#### Pull st2packs from a private Docker registry
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.
See [K8s documentation](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/) for more info.
```
Expand All @@ -214,6 +226,88 @@ kubectl create secret docker-registry st2packs-auth --docker-server=<your-regist
```
Once secret created, reference its name in helm value: `st2.packs.images[].pullSecret`.

### Method 2: Shared Volumes
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`).

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`.
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.

#### Configure the storage volumes
Enable the `st2.packs.voluems` section of Helm values and add volume definitions for both `packs` and `virtualenvs`.
Each of the volume definitions should be customized for your cluster and storage solution.

For example, to use persistentVolumeClaims:
```
volumes:
enabled: true
packs:
persistentVolumeClaim:
claim-name: pvc-st2-packs
virtualenvs:
persistentVolumeClaim:
claim-name: pvc-st2-virtualenvs
```

Or, for example, to use NFS:
```
volumes:
enabled: true
packs:
nfs:
server: nfs.example.com
path: /var/nfsshare/packs
virtualenvs:
nfs:
server: nfs.example.com
path: /var/nfsshare/virtualenvs
```

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.

#### How to provide custom pack configs
You may either use the `st2.packs.configs` section of Helm values (like Method 1, see above),
or add another shared writable volume similar to `packs` and `virtualenvs`. This volume gets mounted
to `/opt/stackstorm/configs` instead of the `st2.packs.config` values.

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.

For example, to use persistentVolumeClaims:
```
volumes:
enabled: true
... # define packs and virtualenvs volumes as shown above
configs:
persistentVolumeClaim:
claim-name: pvc-st2-pack-configs
```

Or, for example, to use NFS:
```
volumes:
enabled: true
... # define packs and virtualenvs volumes as shown above
configs:
nfs:
server: nfs.example.com
path: /var/nfsshare/configs
```

#### Caveat: Mounting and copying packs
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.

Though you could manually copy packs into the `packs` shared volume, be aware that StackStorm does not automatically register any changed content.
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,
possibly using APIs like:
[packs/install](https://api.stackstorm.com/api/v1/packs/#/packs_controller.install.post), and
[packs/register](https://api.stackstorm.com/api/v1/packs/#/packs_controller.register.post)
You will have to repeat the process each time the packs code is modified.

#### Caveat: System packs
After Helm installs, upgrades, or rolls back a StackStorm install, it runs an `st2-register-content` batch job.
This job will copy and register system packs. If you have made any changes (like disabling default aliases), those changes will be overwritten.

NOTE: Upgrades will not remove files (such as a renamed or removed action) if they were removed in newer StackStorm versions.
This mirrors the how pack registration works. Make sure to review any upgrade notes and manually handle any removals.

## Tips & Tricks
Grab all logs for entire StackStorm cluster with dependent services in Helm release:
Expand Down
74 changes: 73 additions & 1 deletion templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,69 @@ Create the name of the stackstorm-ha service account to use
{{- end }}
{{- end -}}

# consolidate pack-configs-volumes definitions
{{- define "pack-configs-volume" -}}
{{- if and .Values.st2.packs.volumes.enabled .Values.st2.packs.volumes.configs }}
- name: st2-pack-configs-vol
{{- toYaml .Values.st2.packs.volumes.configs | nindent 2 }}
{{- if .Values.st2.packs.configs }}
- name: st2-pack-configs-from-helm-vol
configMap:
name: {{ .Release.Name }}-st2-pack-configs
{{- end }}
{{- else }}
- name: st2-pack-configs-vol
configMap:
name: {{ .Release.Name }}-st2-pack-configs
{{- end }}
{{- end -}}
{{- define "pack-configs-volume-mount" -}}
- name: st2-pack-configs-vol
mountPath: /opt/stackstorm/configs/
{{- if and .Values.st2.packs.volumes.enabled .Values.st2.packs.volumes.configs .Values.st2.packs.configs }}
- name: st2-pack-configs-from-helm-vol
mountPath: /opt/stackstorm/configs-helm/
{{- end }}
{{- end -}}

# For custom st2packs-Container reduce duplicity by defining it here once
{{- define "packs-volumes" -}}
{{- if .Values.st2.packs.images }}
{{- if .Values.st2.packs.volumes.enabled }}
- name: st2-packs-vol
{{- toYaml .Values.st2.packs.volumes.packs | nindent 2 }}
- name: st2-virtualenvs-vol
{{- toYaml .Values.st2.packs.volumes.virtualenvs | nindent 2 }}
{{- else if .Values.st2.packs.images }}
- name: st2-packs-vol
emptyDir: {}
- name: st2-virtualenvs-vol
emptyDir: {}
{{- end }}
{{- end -}}
{{- define "packs-volume-mounts" -}}
{{- if .Values.st2.packs.volumes.enabled }}
- name: st2-packs-vol
mountPath: /opt/stackstorm/packs
- name: st2-virtualenvs-vol
mountPath: /opt/stackstorm/virtualenvs
{{- else if .Values.st2.packs.images }}
- name: st2-packs-vol
mountPath: /opt/stackstorm/packs
readOnly: true
- name: st2-virtualenvs-vol
mountPath: /opt/stackstorm/virtualenvs
readOnly: true
{{- end }}
{{- end -}}
# define this here as well to simplify comparison with packs-volume-mounts
{{- define "packs-volume-mounts-for-register-job" -}}
{{- if or .Values.st2.packs.images .Values.st2.packs.volumes.enabled }}
- name: st2-packs-vol
mountPath: /opt/stackstorm/packs
- name: st2-virtualenvs-vol
mountPath: /opt/stackstorm/virtualenvs
{{- end }}
{{- end -}}

# For custom st2packs-initContainers reduce duplicity by defining them here once
# Merge packs and virtualenvs from st2 with those from st2packs images
Expand All @@ -150,6 +204,8 @@ Create the name of the stackstorm-ha service account to use
/bin/cp -aR /opt/stackstorm/packs/. /opt/stackstorm/packs-shared &&
/bin/cp -aR /opt/stackstorm/virtualenvs/. /opt/stackstorm/virtualenvs-shared
{{- end }}
{{- end }}
{{- if or $.Values.st2.packs.images $.Values.st2.packs.volumes.enabled }}
# System packs
- name: st2-system-packs
image: '{{ template "imageRepository" . }}/st2actionrunner:{{ tpl (.Values.st2actionrunner.image.tag | default .Values.image.tag) . }}'
Expand All @@ -166,6 +222,22 @@ Create the name of the stackstorm-ha service account to use
/bin/cp -aR /opt/stackstorm/packs/. /opt/stackstorm/packs-shared &&
/bin/cp -aR /opt/stackstorm/virtualenvs/. /opt/stackstorm/virtualenvs-shared
{{- end }}
{{- if and $.Values.st2.packs.configs $.Values.st2.packs.volumes.enabled }}
# Pack configs defined in helm values
- name: st2-pack-configs-from-helm
image: '{{ template "imageRepository" . }}/st2actionrunner:{{ tpl (.Values.st2actionrunner.image.tag | default .Values.image.tag) . }}'
imagePullPolicy: {{ .Values.image.pullPolicy }}
volumeMounts:
- name: st2-pack-configs-vol
mountPath: /opt/stackstorm/configs-shared
- name: st2-pack-configs-from-helm-vol
mountPath: /opt/stackstorm/configs
command:
- 'sh'
- '-ec'
- |
/bin/cp -aR /opt/stackstorm/configs/. /opt/stackstorm/configs-shared
{{- end }}
{{- end -}}


Expand Down
2 changes: 1 addition & 1 deletion templates/configmaps_packs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: ConfigMap
metadata:
name: {{ .Release.Name }}-st2-pack-configs
annotations:
description: Custom StackStorm pack configs, shipped in '/opt/stackstorm/configs/'
description: StackStorm pack configs defined in helm values, shipped in (or copied to) '/opt/stackstorm/configs/'
labels:
app: st2
tier: backend
Expand Down
Loading