Skip to content

Commit 591064b

Browse files
committed
Feature: jobs.extra_hooks to run custom helm.sh/hook jobs
Like other jobs, the extra_hooks jobs include: annotations, securityContext, pullSecrets, st2client config, envFromSecrets, resources, dnsPolicy/dnsConfig, nodeSelector, affinity, tolerations, init containers, and packs volumes. add securityContext to extra_hooks jobs
1 parent 270f358 commit 591064b

File tree

2 files changed

+155
-1
lines changed

2 files changed

+155
-1
lines changed

templates/jobs.yaml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,3 +504,132 @@ spec:
504504
{{- end }}
505505

506506
{{- end }}
507+
{{- range .Values.jobs.extra_hooks -}}
508+
{{- $name := print "extra-helm-hook" (include "stackstorm-ha.hyphenPrefix" (required "You must name each entry in jobs.extra_hooks." .name)) }}
509+
---
510+
apiVersion: batch/v1
511+
kind: Job
512+
metadata:
513+
name: {{ $.Release.Name }}-job-{{ $name }}
514+
labels:
515+
app: {{ $name }}
516+
tier: backend
517+
vendor: stackstorm
518+
chart: {{ $.Chart.Name }}-{{ $.Chart.Version }}
519+
release: {{ $.Release.Name }}
520+
heritage: {{ $.Release.Service }}
521+
annotations:
522+
helm.sh/hook: {{ required "Each entry in jobs.extra_hooks must include 'hook' (the helm.sh/hook value)" .hook }}
523+
helm.sh/hook-delete-policy: before-hook-creation
524+
helm.sh/hook-weight: {{ .hook_weight | default 10 | toString | quote }}
525+
{{- if $.Values.jobs.annotations }}
526+
{{- toYaml $.Values.jobs.annotations | nindent 4 }}
527+
{{- end }}
528+
spec:
529+
template:
530+
metadata:
531+
name: job-{{ $name }}
532+
labels:
533+
app: {{ $name }}
534+
tier: backend
535+
vendor: stackstorm
536+
chart: {{ $.Chart.Name }}-{{ $.Chart.Version }}
537+
release: {{ $.Release.Name }}
538+
heritage: {{ $.Release.Service }}
539+
annotations:
540+
checksum/config: {{ include (print $.Template.BasePath "/configmaps_st2-conf.yaml") $ | sha256sum }}
541+
checksum/packs: {{ include (print $.Template.BasePath "/configmaps_packs.yaml") $ | sha256sum }}
542+
{{- if $.Values.jobs.annotations }}
543+
{{- toYaml $.Values.jobs.annotations | nindent 8 }}
544+
{{- end }}
545+
spec:
546+
imagePullSecrets:
547+
{{- if $.Values.image.pullSecret }}
548+
- name: {{ $.Values.image.pullSecret }}
549+
{{- end }}
550+
{{- if $.Values.st2.packs.images -}}
551+
{{- include "stackstorm-ha.packs-pullSecrets" $ | nindent 6 }}
552+
{{- end }}
553+
initContainers:
554+
{{- include "stackstorm-ha.init-containers-wait-for-db" $ | nindent 6 }}
555+
{{- include "stackstorm-ha.packs-initContainers" $ | nindent 6 }}
556+
- name: generate-st2client-config
557+
image: '{{ template "stackstorm-ha.imageRepository" $ }}/st2actionrunner:{{ tpl ($.Values.jobs.image.tag | default ($.Values.st2actionrunner.image.tag | default $.Values.image.tag)) $ }}'
558+
imagePullPolicy: {{ $.Values.image.pullPolicy }}
559+
{{- with $.Values.securityContext }}
560+
securityContext: {{- toYaml . | nindent 10 }}
561+
{{- end }}
562+
envFrom:
563+
- configMapRef:
564+
name: {{ $.Release.Name }}-st2-urls
565+
- secretRef:
566+
name: {{ $.Release.Name }}-st2-auth
567+
{{- range $.Values.jobs.envFromSecrets }}
568+
- secretRef:
569+
name: {{ . }}
570+
{{- end }}
571+
volumeMounts:
572+
- name: st2client-config-vol
573+
mountPath: /root/.st2/
574+
# `st2 login` doesn't exit on failure correctly, use old methods instead. See bug: https://github.com/StackStorm/st2/issues/4338
575+
command:
576+
- 'sh'
577+
- '-ec'
578+
- |
579+
cat <<EOT > /root/.st2/config
580+
[credentials]
581+
{{- tpl $.Values.jobs.st2clientConfig $ | nindent 12 }}
582+
EOT
583+
containers:
584+
- name: {{ $name }}
585+
image: '{{ template "stackstorm-ha.imageRepository" $ }}/st2actionrunner:{{ tpl ($.Values.jobs.image.tag | default ($.Values.st2actionrunner.image.tag | default $.Values.image.tag)) $ }}'
586+
imagePullPolicy: {{ $.Values.image.pullPolicy }}
587+
{{- with $.Values.securityContext }}
588+
securityContext: {{- toYaml . | nindent 10 }}
589+
{{- end }}
590+
{{- if $.Values.jobs.env }}
591+
env: {{- include "stackstorm-ha.customEnv" $.Values.jobs | nindent 8 }}
592+
{{- end }}
593+
envFrom:
594+
{{- range $.Values.jobs.envFromSecrets }}
595+
- secretRef:
596+
name: {{ . }}
597+
{{- end }}
598+
command: {{- required "Each entry in jobs.extra_hooks must include the 'command' to run." .command | toYaml | nindent 10 }}
599+
volumeMounts:
600+
- name: st2client-config-vol
601+
mountPath: /root/.st2/
602+
{{- include "stackstorm-ha.st2-config-volume-mounts" $ | nindent 8 }}
603+
{{- include "stackstorm-ha.packs-volume-mounts-for-register-job" $ | nindent 8 }}
604+
{{- include "stackstorm-ha.pack-configs-volume-mount" $ | nindent 8 }}
605+
{{- if .resources }}
606+
resources: {{- toYaml .resources | nindent 10 }}
607+
{{- end }}
608+
volumes:
609+
- name: st2client-config-vol
610+
emptyDir:
611+
medium: Memory
612+
{{- include "stackstorm-ha.st2-config-volume" $ | nindent 8 }}
613+
{{- include "stackstorm-ha.packs-volumes" $ | nindent 8 }}
614+
{{- include "stackstorm-ha.pack-configs-volume" $ | nindent 8 }}
615+
restartPolicy: OnFailure
616+
{{- if $.Values.dnsPolicy }}
617+
dnsPolicy: {{ $.Values.dnsPolicy }}
618+
{{- end }}
619+
{{- with $.Values.dnsConfig }}
620+
dnsConfig: {{- toYaml . | nindent 8 }}
621+
{{- end }}
622+
{{- with $.Values.podSecurityContext }}
623+
securityContext: {{- toYaml . | nindent 8 }}
624+
{{- end }}
625+
{{- with $.Values.jobs.nodeSelector }}
626+
nodeSelector: {{- toYaml . | nindent 8 }}
627+
{{- end }}
628+
{{- with $.Values.jobs.affinity }}
629+
affinity: {{- toYaml . | nindent 8 }}
630+
{{- end }}
631+
{{- with $.Values.jobs.tolerations }}
632+
tolerations: {{- toYaml . | nindent 8 }}
633+
{{- end }}
634+
635+
{{- end }}

values.yaml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,32 @@ jobs:
895895
# For example, if an upgrade only touches RBAC config, use this to disable other jobs:
896896
# helm upgrade ... --set 'jobs.skip={apikey_load,key_load,register_content}'
897897
skip: []
898-
898+
#
899+
# Advanced: Add extra Helm hook Jobs
900+
# These hook jobs will use the same settings (eg image, annotations, pod placement) as the other jobs.
901+
# They will have st2 cli configured, st2.conf files, and packs volumes mounted.
902+
# See available hooks list: https://helm.sh/docs/topics/charts_hooks/#the-available-hooks
903+
extra_hooks: []
904+
# Each item in extra_hooks must define a 'name' and the "helm.sh/hook" value in 'hook'.
905+
#
906+
# - name: init-workflow # required name
907+
# hook: post-install # required "helm.sh/hook"
908+
# hook_weight: 10 # optional hook_weight (defaults to 10)
909+
# resources: {} # optional definition of resources to request
910+
# command: # required command to run
911+
# - st2
912+
# - run
913+
# - --tail
914+
# - custom_pack.init_stackstorm
915+
#
916+
# - name: upgrade-warning
917+
# hook: pre-upgrade, pre-rollback
918+
# hook_weight: -5
919+
# command:
920+
# - st2
921+
# - run
922+
# - --tail
923+
# - custom_pack.warn_about_upgrade
899924
##
900925
## MongoDB HA configuration (3rd party chart dependency)
901926
##

0 commit comments

Comments
 (0)