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

Standardize helper comments and names (prefix all helper names with stackstorm-ha) #272

Merged
merged 12 commits into from
Jan 12, 2022
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## In Development
* 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)
* Prefix template helpers with chart name and format helper comments as template comments. (#272) (by @cognifloyd)

## v0.80.0
* Switch st2 to `v3.6` as a new default stable version (#274)
Expand Down
94 changes: 59 additions & 35 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Expand the name of the chart.
{{/*
Expand the name of the chart.
*/}}
{{- define "stackstorm-ha.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}

# Generate Docker image repository: Public Docker Hub 'stackstorm' for FOSS version
{{- define "imageRepository" -}}
{{/*
Generate Docker image repository: Public Docker Hub 'stackstorm' for FOSS version
*/}}
{{- define "stackstorm-ha.imageRepository" -}}
{{- if .Values.image.repository -}}
{{ .Values.image.repository }}
{{- else -}}
Expand All @@ -19,16 +23,20 @@ Create the name of the stackstorm-ha service account to use
{{- default .Chart.Name .Values.serviceAccount.serviceAccountName -}}
{{- end -}}

# Generate '-' prefix only when the variable is defined
{{- define "hyphenPrefix" -}}
{{/*
Generate '-' prefix only when the variable is defined
*/}}
{{- define "stackstorm-ha.hyphenPrefix" -}}
{{ if . }}-{{ . }}{{end}}
{{- end -}}

# Allow calling helpers from nested sub-chart
# https://stackoverflow.com/a/52024583/4533625
# https://github.com/helm/helm/issues/4535#issuecomment-477778391
# Usage: "{{ include "nested" (list . "mongodb" "mongodb.fullname") }}"
{{- define "nested" }}
{{/*
Allow calling helpers from nested sub-chart
https://stackoverflow.com/a/52024583/4533625
https://github.com/helm/helm/issues/4535#issuecomment-477778391
Usage: "{{ include "stackstorm-ha.nested" (list . "mongodb" "mongodb.fullname") }}"
*/}}
{{- define "stackstorm-ha.nested" }}
{{- $dot := index . 0 }}
{{- $subchart := index . 1 | splitList "." }}
{{- $template := index . 2 }}
Expand All @@ -39,11 +47,13 @@ Create the name of the stackstorm-ha service account to use
{{- include $template (dict "Chart" (dict "Name" (last $subchart)) "Values" $values "Release" $dot.Release "Capabilities" $dot.Capabilities) }}
{{- end }}

# Generate comma-separated list of nodes for MongoDB-HA connection string, based on number of replicas and service name
{{- define "mongodb-nodes" -}}
{{/*
Generate comma-separated list of nodes for MongoDB-HA connection string, based on number of replicas and service name
*/}}
{{- define "stackstorm-ha.mongodb-nodes" -}}
{{- $replicas := (int (index .Values "mongodb" "replicaCount")) }}
{{- $architecture := (index .Values "mongodb" "architecture" ) }}
{{- $mongo_fullname := include "nested" (list $ "mongodb" "mongodb.fullname") }}
{{- $mongo_fullname := include "stackstorm-ha.nested" (list $ "mongodb" "mongodb.fullname") }}
{{- range $index0 := until $replicas -}}
{{- $index1 := $index0 | add1 -}}
{{- if eq $architecture "replicaset" }}
Expand All @@ -54,8 +64,10 @@ Create the name of the stackstorm-ha service account to use
{{- end -}}
{{- end -}}

# Generate list of nodes for Redis with Sentinel connection string, based on number of replicas and service name
{{- define "redis-nodes" -}}
{{/*
Generate list of nodes for Redis with Sentinel connection string, based on number of replicas and service name
*/}}
{{- define "stackstorm-ha.redis-nodes" -}}
{{- if not .Values.redis.sentinel.enabled }}
{{- fail "value for redis.sentinel.enabled MUST be true" }}
{{- end }}
Expand All @@ -71,22 +83,24 @@ Create the name of the stackstorm-ha service account to use
{{- end -}}
{{- end -}}

# Reduce duplication of the st2.*.conf volume details
{{- define "st2-config-volume-mounts" -}}
{{/*
Reduce duplication of the st2.*.conf volume details
*/}}
{{- define "stackstorm-ha.st2-config-volume-mounts" -}}
- name: st2-config-vol
mountPath: /etc/st2/st2.docker.conf
subPath: st2.docker.conf
- name: st2-config-vol
mountPath: /etc/st2/st2.user.conf
subPath: st2.user.conf
{{- end -}}
{{- define "st2-config-volume" -}}
{{- define "stackstorm-ha.st2-config-volume" -}}
- name: st2-config-vol
configMap:
name: {{ $.Release.Name }}-st2-config
{{- end -}}

{{- define "init-containers-wait-for-db" -}}
{{- define "stackstorm-ha.init-containers-wait-for-db" -}}
{{- if index .Values "mongodb" "enabled" }}
{{- $mongodb_port := (int (index .Values "mongodb" "service" "port")) }}
- name: wait-for-db
Expand All @@ -106,7 +120,7 @@ Create the name of the stackstorm-ha service account to use
{{- end }}
{{- end -}}

{{- define "init-containers-wait-for-mq" -}}
{{- define "stackstorm-ha.init-containers-wait-for-mq" -}}
{{- if index .Values "rabbitmq" "enabled" }}
{{- $rabbitmq_port := (int (index .Values "rabbitmq" "service" "port")) }}
- name: wait-for-queue
Expand All @@ -126,8 +140,10 @@ Create the name of the stackstorm-ha service account to use
{{- end }}
{{- end -}}

# consolidate pack-configs-volumes definitions
{{- define "pack-configs-volume" -}}
{{/*
consolidate pack-configs-volumes definitions
*/}}
{{- define "stackstorm-ha.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 }}
Expand All @@ -142,7 +158,7 @@ Create the name of the stackstorm-ha service account to use
name: {{ .Release.Name }}-st2-pack-configs
{{- end }}
{{- end -}}
{{- define "pack-configs-volume-mount" -}}
{{- define "stackstorm-ha.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 }}
Expand All @@ -151,8 +167,10 @@ Create the name of the stackstorm-ha service account to use
{{- end }}
{{- end -}}

# For custom st2packs-Container reduce duplicity by defining it here once
{{- define "packs-volumes" -}}
{{/*
For custom st2packs-Container reduce duplicity by defining it here once
*/}}
{{- define "stackstorm-ha.packs-volumes" -}}
{{- if .Values.st2.packs.volumes.enabled }}
- name: st2-packs-vol
{{- toYaml .Values.st2.packs.volumes.packs | nindent 2 }}
Expand All @@ -165,7 +183,7 @@ Create the name of the stackstorm-ha service account to use
emptyDir: {}
{{- end }}
{{- end -}}
{{- define "packs-volume-mounts" -}}
{{- define "stackstorm-ha.packs-volume-mounts" -}}
{{- if .Values.st2.packs.volumes.enabled }}
- name: st2-packs-vol
mountPath: /opt/stackstorm/packs
Expand All @@ -180,8 +198,10 @@ Create the name of the stackstorm-ha service account to use
readOnly: true
{{- end }}
{{- end -}}
# define this here as well to simplify comparison with packs-volume-mounts
{{- define "packs-volume-mounts-for-register-job" -}}
{{/*
define this here as well to simplify comparison with packs-volume-mounts
*/}}
{{- define "stackstorm-ha.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
Expand All @@ -190,9 +210,11 @@ Create the name of the stackstorm-ha service account to use
{{- 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" -}}
{{/*
For custom st2packs-initContainers reduce duplicity by defining them here once
Merge packs and virtualenvs from st2 with those from st2packs images
*/}}
{{- define "stackstorm-ha.packs-initContainers" -}}
{{- if $.Values.st2.packs.images }}
{{- range $.Values.st2.packs.images }}
- name: 'st2-custom-pack-{{ printf "%s-%s-%s" .repository .name .tag | sha1sum }}'
Expand All @@ -217,7 +239,7 @@ Create the name of the stackstorm-ha service account to use
{{- 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) . }}'
image: '{{ template "stackstorm-ha.imageRepository" . }}/st2actionrunner:{{ tpl (.Values.st2actionrunner.image.tag | default .Values.image.tag) . }}'
imagePullPolicy: {{ .Values.image.pullPolicy }}
volumeMounts:
- name: st2-packs-vol
Expand All @@ -237,7 +259,7 @@ Create the name of the stackstorm-ha service account to use
{{- 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) . }}'
image: '{{ template "stackstorm-ha.imageRepository" . }}/st2actionrunner:{{ tpl (.Values.st2actionrunner.image.tag | default .Values.image.tag) . }}'
imagePullPolicy: {{ .Values.image.pullPolicy }}
volumeMounts:
- name: st2-pack-configs-vol
Expand All @@ -256,8 +278,10 @@ Create the name of the stackstorm-ha service account to use
{{- end -}}


# For custom st2packs-pullSecrets reduce duplicity by defining them here once
{{- define "packs-pullSecrets" -}}
{{/*
For custom st2packs-pullSecrets reduce duplicity by defining them here once
*/}}
{{- define "stackstorm-ha.packs-pullSecrets" -}}
{{- range $.Values.st2.packs.images }}
{{- if .pullSecret }}
- name: {{ .pullSecret }}
Expand Down
6 changes: 3 additions & 3 deletions templates/configmaps_st2-conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ data:
ssh_key_file = {{ tpl .Values.st2.system_user.ssh_key_file . }}
{{- if index .Values "redis" "enabled" }}
[coordination]
url = redis://{{ template "redis-nodes" $ }}
url = redis://{{ template "stackstorm-ha.redis-nodes" $ }}
{{- end }}
{{- if index .Values "rabbitmq" "enabled" }}
[messaging]
Expand All @@ -33,12 +33,12 @@ data:
{{- if index .Values "mongodb" "enabled" }}
[database]
{{- if index .Values "mongodb" "auth" "enabled" }}
host = mongodb://{{ template "mongodb-nodes" $ }}/{{ required "mongodb.auth.database is required!" (index .Values "mongodb" "auth" "database") }}?authSource={{ required "mongodb.auth.database is required!" (index .Values "mongodb" "auth" "database") }}&replicaSet={{ index .Values "mongodb" "replicaSetName" }}
host = mongodb://{{ template "stackstorm-ha.mongodb-nodes" $ }}/{{ required "mongodb.auth.database is required!" (index .Values "mongodb" "auth" "database") }}?authSource={{ required "mongodb.auth.database is required!" (index .Values "mongodb" "auth" "database") }}&replicaSet={{ index .Values "mongodb" "replicaSetName" }}
username = {{ required "mongodb.auth.username is required!" (index .Values "mongodb" "auth" "username") }}
password = {{ required "mongodb.auth.password is required!" (index .Values "mongodb" "auth" "password") }}
db_name = {{ required "mongodb.auth.database is required!" (index .Values "mongodb" "auth" "database") }}
{{- else }}
host = mongodb://{{ template "mongodb-nodes" $ }}/?replicaSet={{ index .Values "mongodb" "replicaSetName" }}
host = mongodb://{{ template "stackstorm-ha.mongodb-nodes" $ }}/?replicaSet={{ index .Values "mongodb" "replicaSetName" }}
{{- end }}
port = {{ index .Values "mongodb" "service" "port" }}
{{- end }}
Expand Down
Loading