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

Allow multiple packs images #166

Merged
merged 1 commit into from
Mar 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog

## In Development

* Change st2packs definition to a list, to support multiple st2packs containers (#166) (by @moonrail)

## v0.52.0
* Improve resource allocation and scheduling by adding resources requests cpu/memory values for st2 Pods (#179)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ See [K8s documentation](https://kubernetes.io/docs/tasks/configure-pod-container
# Create a Docker registry secret called 'st2packs-auth'
kubectl create secret docker-registry st2packs-auth --docker-server=<your-registry-server> --docker-username=<your-name> --docker-password=<your-password>
```
Once secret created, reference its name in helm value: `st2.packs.image.pullSecret`.
Once secret created, reference its name in helm value: `st2.packs.images[].pullSecret`.


## Tips & Tricks
Expand Down
64 changes: 61 additions & 3 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ Create the name of the stackstorm-ha service account to use
{{- end -}}

{{- define "init-containers-wait-for-mq" -}}
{{- if index .Values "rabbitmq" "enabled" }}
{{- $rabbitmq_port := (int (index .Values "rabbitmq" "service" "port")) }}
{{- if index .Values "rabbitmq" "enabled" }}
{{- $rabbitmq_port := (int (index .Values "rabbitmq" "service" "port")) }}
- name: wait-for-queue
image: busybox:1.28
command:
Expand All @@ -125,5 +125,63 @@ Create the name of the stackstorm-ha service account to use
echo 'Waiting for RabbitMQ Connection...'
sleep 2;
done
{{- end }}
{{- end }}
{{- end -}}

# For custom st2packs-Container reduce duplicity by defining it here once
{{- define "packs-volumes" -}}
{{- if .Values.st2.packs.images }}
- name: st2-packs-vol
emptyDir: {}
- name: st2-virtualenvs-vol
emptyDir: {}
{{- end }}
{{- end -}}

# For custom st2packs-initContainers reduce duplicity by defining them here once
# Merge packs and virtualenvs from st2 with those from st2packs images
{{- define "packs-initContainers" -}}
{{- if $.Values.st2.packs.images }}
{{- range $.Values.st2.packs.images }}
- name: 'st2-custom-pack-{{ printf "%s-%s-%s" .repository .name .tag | sha1sum }}'
image: "{{ .repository }}/{{ .name }}:{{ .tag }}"
imagePullPolicy: {{ .pullPolicy | quote }}
volumeMounts:
- name: st2-packs-vol
mountPath: /opt/stackstorm/packs-shared
- name: st2-virtualenvs-vol
mountPath: /opt/stackstorm/virtualenvs-shared
command:
- 'sh'
- '-ec'
- |
/bin/cp -aR /opt/stackstorm/packs/. /opt/stackstorm/packs-shared &&
/bin/cp -aR /opt/stackstorm/virtualenvs/. /opt/stackstorm/virtualenvs-shared
{{- end }}
# System packs
- name: st2-system-packs
image: "{{ template "imageRepository" . }}/st2actionrunner{{ template "enterpriseSuffix" . }}:{{ .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
volumeMounts:
- name: st2-packs-vol
mountPath: /opt/stackstorm/packs-shared
- name: st2-virtualenvs-vol
mountPath: /opt/stackstorm/virtualenvs-shared
command:
- 'sh'
- '-ec'
- |
/bin/cp -aR /opt/stackstorm/packs/. /opt/stackstorm/packs-shared &&
/bin/cp -aR /opt/stackstorm/virtualenvs/. /opt/stackstorm/virtualenvs-shared
{{- end }}
{{- end -}}


# For custom st2packs-pullSecrets reduce duplicity by defining them here once
{{- define "packs-pullSecrets" -}}
{{- range $.Values.st2.packs.images }}
{{- if .pullSecret }}
- name: {{ .pullSecret }}
{{- end }}
{{- end }}
{{- end -}}
193 changes: 36 additions & 157 deletions templates/deployments.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Notify users about breaking change regarding packs, to not destroy current installations
{{- if and .Values.st2.packs.image }}
{{- fail "Value st2.packs.image was renamed to st2.packs.images and is now a list of images" }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice idea here! 👍

{{- end }}

---
apiVersion: apps/v1
kind: Deployment
Expand Down Expand Up @@ -154,47 +159,17 @@ spec:
{{- if .Values.enterprise.enabled }}
- name: {{ .Release.Name }}-st2-license
{{- end }}
{{- if .Values.st2.packs.image.pullSecret }}
- name: {{ .Values.st2.packs.image.pullSecret }}
{{- end }}
{{- if .Values.image.pullSecret }}
- name: {{ .Values.image.pullSecret }}
{{- end }}
{{- if .Values.st2.packs.images }}
{{- include "packs-pullSecrets" . | indent 6 }}
{{- end }}
initContainers:
{{ include "init-containers-wait-for-db" . | indent 6 }}
{{ include "init-containers-wait-for-mq" . | indent 6 }}
{{- if .Values.st2.packs.image.repository }}
# Merge packs and virtualenvs from st2api with those from the st2.packs image
# Custom packs
- name: st2-custom-packs
image: "{{ .Values.st2.packs.image.repository }}/{{ .Values.st2.packs.image.name }}:{{ .Values.st2.packs.image.tag }}"
imagePullPolicy: {{ .Values.st2.packs.image.pullPolicy | quote }}
volumeMounts:
- name: st2-packs-vol
mountPath: /opt/stackstorm/packs-shared
- name: st2-virtualenvs-vol
mountPath: /opt/stackstorm/virtualenvs-shared
command:
- 'sh'
- '-ec'
- |
/bin/cp -aR /opt/stackstorm/packs/. /opt/stackstorm/packs-shared &&
/bin/cp -aR /opt/stackstorm/virtualenvs/. /opt/stackstorm/virtualenvs-shared
# System packs
- name: st2-system-packs
image: "{{ template "imageRepository" . }}/st2actionrunner{{ template "enterpriseSuffix" . }}:{{ .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
volumeMounts:
- name: st2-packs-vol
mountPath: /opt/stackstorm/packs-shared
- name: st2-virtualenvs-vol
mountPath: /opt/stackstorm/virtualenvs-shared
command:
- 'sh'
- '-ec'
- |
/bin/cp -aR /opt/stackstorm/packs/. /opt/stackstorm/packs-shared &&
/bin/cp -aR /opt/stackstorm/virtualenvs/. /opt/stackstorm/virtualenvs-shared
{{- if .Values.st2.packs.images }}
{{- include "packs-initContainers" . | indent 6 }}
{{- end }}
containers:
- name: st2api{{ template "enterpriseSuffix" . }}
Expand All @@ -220,7 +195,7 @@ spec:
mountPath: /etc/st2/keys
readOnly: true
{{- end }}
{{- if .Values.st2.packs.image.repository }}
{{- if .Values.st2.packs.images }}
- name: st2-packs-vol
mountPath: /opt/stackstorm/packs
readOnly: true
Expand All @@ -245,11 +220,8 @@ spec:
- name: st2-config-vol
configMap:
name: {{ .Release.Name }}-st2-config
{{- if .Values.st2.packs.image.repository }}
- name: st2-packs-vol
emptyDir: {}
- name: st2-virtualenvs-vol
emptyDir: {}
{{- if .Values.st2.packs.images }}
{{- include "packs-volumes" . | indent 8 }}
{{- end }}
{{- with .Values.st2api.nodeSelector }}
nodeSelector:
Expand Down Expand Up @@ -955,45 +927,17 @@ spec:
{{- if $.Values.enterprise.enabled }}
- name: {{ $.Release.Name }}-st2-license
{{- end }}
{{- if $.Values.st2.packs.image.pullSecret }}
- name: {{ $.Values.st2.packs.image.pullSecret }}
{{- end }}
{{- if $.Values.image.pullSecret }}
- name: {{ $.Values.image.pullSecret }}
{{- end }}
{{- if $.Values.st2.packs.images }}
{{- include "packs-pullSecrets" $ | indent 6 }}
{{- end }}
initContainers:
{{ include "init-containers-wait-for-db" $ | indent 6 }}
{{ include "init-containers-wait-for-mq" $ | indent 6 }}
{{- if $.Values.st2.packs.image.repository }}
# Merge packs and virtualenvs from st2sensorcontainer with those from the st2.packs image
# Custom packs
- name: st2-custom-packs
image: "{{ $.Values.st2.packs.image.repository }}/{{ $.Values.st2.packs.image.name }}:{{ $.Values.st2.packs.image.tag }}"
imagePullPolicy: {{ $.Values.st2.packs.image.pullPolicy | quote }}
volumeMounts:
- name: st2-packs-vol
mountPath: /opt/stackstorm/packs-shared
- name: st2-virtualenvs-vol
mountPath: /opt/stackstorm/virtualenvs-shared
command:
- 'sh'
- '-ec'
- |
/bin/cp -aR /opt/stackstorm/packs/. /opt/stackstorm/packs-shared &&
/bin/cp -aR /opt/stackstorm/virtualenvs/. /opt/stackstorm/virtualenvs-shared
# System packs
- name: st2-system-packs
image: "{{ template "imageRepository" $ }}/st2actionrunner{{ template "enterpriseSuffix" $ }}:{{ $.Chart.AppVersion }}"
imagePullPolicy: {{ $.Values.image.pullPolicy }}
volumeMounts:
- name: st2-packs-vol
mountPath: /opt/stackstorm/packs-shared
command:
- 'sh'
- '-ec'
- |
/bin/cp -aR /opt/stackstorm/packs/. /opt/stackstorm/packs-shared &&
/bin/cp -aR /opt/stackstorm/virtualenvs/. /opt/stackstorm/virtualenvs-shared
{{- if $.Values.st2.packs.images }}
{{- include "packs-initContainers" $ | indent 6 }}
{{- end }}
containers:
- name: st2sensorcontainer{{ template "hyphenPrefix" .name }}{{ template "enterpriseSuffix" $ }}
Expand Down Expand Up @@ -1027,7 +971,7 @@ spec:
- name: st2-config-vol
mountPath: /etc/st2/st2.user.conf
subPath: st2.user.conf
{{- if $.Values.st2.packs.image.repository }}
{{- if $.Values.st2.packs.images }}
- name: st2-packs-vol
mountPath: /opt/stackstorm/packs
readOnly: true
Expand Down Expand Up @@ -1057,11 +1001,8 @@ spec:
- name: st2-config-vol
configMap:
name: {{ $.Release.Name }}-st2-config
{{- if $.Values.st2.packs.image.repository }}
- name: st2-packs-vol
emptyDir: {}
- name: st2-virtualenvs-vol
emptyDir: {}
{{- if $.Values.st2.packs.images }}
{{- include "packs-volumes" $ | indent 8 }}
{{- end }}
{{- with .nodeSelector }}
nodeSelector:
Expand Down Expand Up @@ -1126,45 +1067,17 @@ spec:
{{- if .Values.enterprise.enabled }}
- name: {{ .Release.Name }}-st2-license
{{- end }}
{{- if .Values.st2.packs.image.pullSecret }}
- name: {{ .Values.st2.packs.image.pullSecret }}
{{- end }}
{{- if .Values.image.pullSecret }}
- name: {{ .Values.image.pullSecret }}
{{- end }}
{{- if .Values.st2.packs.images }}
{{- include "packs-pullSecrets" . | indent 6 }}
{{- end }}
initContainers:
{{ include "init-containers-wait-for-db" . | indent 6 }}
{{ include "init-containers-wait-for-mq" . | indent 6 }}
{{- if .Values.st2.packs.image.repository }}
# Merge packs and virtualenvs from st2actionrunner with those from the st2.packs image
# Custom packs
- name: st2-custom-packs
image: "{{ .Values.st2.packs.image.repository }}/{{ .Values.st2.packs.image.name }}:{{ .Values.st2.packs.image.tag }}"
imagePullPolicy: {{ .Values.st2.packs.image.pullPolicy | quote }}
volumeMounts:
- name: st2-packs-vol
mountPath: /opt/stackstorm/packs-shared
- name: st2-virtualenvs-vol
mountPath: /opt/stackstorm/virtualenvs-shared
command:
- 'sh'
- '-ec'
- |
/bin/cp -aR /opt/stackstorm/packs/. /opt/stackstorm/packs-shared &&
/bin/cp -aR /opt/stackstorm/virtualenvs/. /opt/stackstorm/virtualenvs-shared
# System packs
- name: st2-system-packs
image: "{{ template "imageRepository" . }}/st2actionrunner{{ template "enterpriseSuffix" . }}:{{ .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
volumeMounts:
- name: st2-packs-vol
mountPath: /opt/stackstorm/packs-shared
command:
- 'sh'
- '-ec'
- |
/bin/cp -aR /opt/stackstorm/packs/. /opt/stackstorm/packs-shared &&
/bin/cp -aR /opt/stackstorm/virtualenvs/. /opt/stackstorm/virtualenvs-shared
{{- if .Values.st2.packs.images }}
{{- include "packs-initContainers" . | indent 6 }}
{{- end }}
containers:
- name: st2actionrunner{{ template "enterpriseSuffix" . }}
Expand All @@ -1191,7 +1104,7 @@ spec:
mountPath: /etc/st2/keys
readOnly: true
{{- end }}
{{- if .Values.st2.packs.image.repository }}
{{- if .Values.st2.packs.images }}
- name: st2-packs-vol
mountPath: /opt/stackstorm/packs
readOnly: true
Expand Down Expand Up @@ -1224,11 +1137,8 @@ spec:
path: stanley_rsa
# 0400 file permission
mode: 256
{{- if .Values.st2.packs.image.repository }}
- name: st2-packs-vol
emptyDir: {}
- name: st2-virtualenvs-vol
emptyDir: {}
{{- if .Values.st2.packs.images }}
{{- include "packs-volumes" . | indent 8 }}
{{- end }}
{{- with .Values.st2actionrunner.nodeSelector }}
nodeSelector:
Expand Down Expand Up @@ -1371,43 +1281,15 @@ spec:
{{- if .Values.enterprise.enabled }}
- name: {{ .Release.Name }}-st2-license
{{- end }}
{{- if .Values.st2.packs.image.pullSecret }}
- name: {{ .Values.st2.packs.image.pullSecret }}
{{- if .Values.st2.packs.images }}
{{- include "packs-pullSecrets" . | indent 6 }}
{{- end }}
{{- if .Values.image.pullSecret }}
- name: {{ .Values.image.pullSecret }}
{{- end }}
initContainers:
{{- if .Values.st2.packs.image.repository }}
# Merge packs and virtualenvs from st2actionrunner with those from the st2.packs image
# Custom packs
- name: st2-custom-packs
image: "{{ .Values.st2.packs.image.repository }}/{{ .Values.st2.packs.image.name }}:{{ .Values.st2.packs.image.tag }}"
imagePullPolicy: {{ .Values.st2.packs.image.pullPolicy | quote }}
volumeMounts:
- name: st2-packs-vol
mountPath: /opt/stackstorm/packs-shared
- name: st2-virtualenvs-vol
mountPath: /opt/stackstorm/virtualenvs-shared
command:
- 'sh'
- '-ec'
- |
/bin/cp -aR /opt/stackstorm/packs/. /opt/stackstorm/packs-shared &&
/bin/cp -aR /opt/stackstorm/virtualenvs/. /opt/stackstorm/virtualenvs-shared
# System packs
- name: st2-system-packs
image: "{{ template "imageRepository" . }}/st2actionrunner{{ template "enterpriseSuffix" . }}:{{ .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
volumeMounts:
- name: st2-packs-vol
mountPath: /opt/stackstorm/packs-shared
command:
- 'sh'
- '-ec'
- |
/bin/cp -aR /opt/stackstorm/packs/. /opt/stackstorm/packs-shared &&
/bin/cp -aR /opt/stackstorm/virtualenvs/. /opt/stackstorm/virtualenvs-shared
{{- if .Values.st2.packs.images }}
{{- include "packs-initContainers" . | indent 6 }}
{{- end }}
# Sidecar container for generating st2client config with st2 username & password pair and sharing produced file with the main container
- name: generate-st2client-config
Expand Down Expand Up @@ -1477,7 +1359,7 @@ spec:
mountPath: /etc/st2/keys
readOnly: true
{{- end }}
{{- if .Values.st2.packs.image.repository }}
{{- if .Values.st2.packs.images }}
- name: st2-packs-vol
mountPath: /opt/stackstorm/packs
readOnly: true
Expand Down Expand Up @@ -1530,11 +1412,8 @@ spec:
path: stanley_rsa
# 0400 file permission
mode: 256
{{- if .Values.st2.packs.image.repository }}
- name: st2-packs-vol
emptyDir: {}
- name: st2-virtualenvs-vol
emptyDir: {}
{{- if .Values.st2.packs.images }}
{{- include "packs-volumes" . | indent 8 }}
{{- end }}

{{ if .Values.st2chatops.enabled -}}
Expand Down
Loading