@@ -484,6 +484,118 @@ spec:
484484 {{- end }}
485485
486486{{- end }}
487+ {{- if $.Values.st2.packs.volumes.enabled }}
488+ ---
489+ apiVersion : batch/v1
490+ kind : Job
491+ metadata :
492+ name : {{ $.Release.Name }}-job-ensure-packs-volumes-are-writable
493+ labels : {{- include "stackstorm-ha.labels" (list $ "st2canary") | nindent 4 }}
494+ annotations :
495+ helm.sh/hook : pre-install, pre-upgrade, pre-rollback
496+ helm.sh/hook-weight : " -5" # fairly high priority
497+ helm.sh/hook-delete-policy : hook-succeeded
498+ {{- if $.Values.jobs.annotations }}
499+ {{- toYaml $.Values.jobs.annotations | nindent 4 }}
500+ {{- end }}
501+ spec :
502+ template :
503+ metadata :
504+ name : job-st2canary-for-writable-packs-volumes
505+ labels : {{- include "stackstorm-ha.labels" (list $ "st2canary") | nindent 8 }}
506+ annotations :
507+ {{- if $.Values.jobs.annotations }}
508+ {{- toYaml $.Values.jobs.annotations | nindent 8 }}
509+ {{- end }}
510+ spec :
511+ imagePullSecrets :
512+ {{- if $.Values.image.pullSecret }}
513+ - name : {{ $.Values.image.pullSecret }}
514+ {{- end }}
515+ initContainers : []
516+ containers :
517+ - name : st2canary-for-writable-packs-volumes
518+ image : ' {{ template "stackstorm-ha.imageRepository" $ }}/st2actionrunner:{{ tpl $.Values.image.tag $ }}'
519+ imagePullPolicy : {{ $.Values.image.pullPolicy }}
520+ {{- with $.Values.securityContext }}
521+ securityContext : {{- toYaml . | nindent 10 }}
522+ {{- end }}
523+ # TODO: maybe use kubectl to assert the volumes have RWX mode
524+ # If volume is a persistentVolumeClaim, then:
525+ # the PVC must only have ReadWriteMany in spec.accessModes
526+ # If volume is something else, then validating through metadata is iffy.
527+ # azureFile, cephfs, csi, glusterfs, nfs, pvc, quobyte, need at least:
528+ # readOnly: false
529+ # ephemeral volumes could also work, ... but that config is even deeper.
530+ command :
531+ - ' sh'
532+ # -e => exit on failure
533+ # -E => trap ERR is inherited in subfunctions
534+ - ' -eEc'
535+ - |
536+ cat << 'INTRO'
537+ Testing write permissions for packs volumes.
538+ If this passes, the pod will automatically be deleted.
539+ If this fails, inspect the pod for errors in kubernetes,
540+ and then delete this st2canary pod manually.
541+ INTRO
542+
543+ function __handle_error__(){
544+ cat <<- 'FAIL'
545+ ERROR: One or more volumes in st2.packs.volumes (from helm values) does not meet
546+ StackStorm's shared volumes requirements!
547+ see: https://github.com/StackStorm/stackstorm-k8s#method-2-shared-volumes
548+
549+ HINT: The volumes defined in st2.packs.volumes must use ReadWriteMany (RWX) access mode
550+ so StackStorm can dynamically install packs from any of the st2actionrunner pods
551+ and have those file changes available in all of the other StackStorm pods.
552+ see: https://kubernetes.io/docs/concepts/storage/persistent-volumes/#access-modes
553+ FAIL
554+ }
555+ trap __handle_error__ ERR
556+
557+ for volume in packs virtualenvs {{ if $.Values.st2.packs.volumes.configs }}configs{{ end }}; do
558+ echo Testing write permissions on ${volume} volume...
559+ touch /opt/stackstorm/${volume}/.write-test
560+ rm /opt/stackstorm/${volume}/.write-test
561+ echo
562+ done
563+ echo DONE
564+ volumeMounts :
565+ {{- include "stackstorm-ha.packs-volume-mounts" $ | nindent 8 }}
566+ {{/* do not include the pack-configs-volume-mount helper here */}}
567+ - name : st2-pack-configs-vol
568+ mountPath : /opt/stackstorm/configs/
569+ readOnly : false
570+ # TODO: Find out default resource limits for this specific job (#5)
571+ # resources:
572+ volumes :
573+ {{- include "stackstorm-ha.packs-volumes" $ | nindent 8 }}
574+ {{- if $.Values.st2.packs.volumes.configs }}
575+ {{/* do not include the pack-configs-volume helper here */}}
576+ - name : st2-pack-configs-vol
577+ {{- toYaml $.Values.st2.packs.volumes.configs | nindent 10 }}
578+ {{- end }}
579+ # st2canary job does not support extra_volumes. Let us know if you need this.
580+ {{- if $.Values.dnsPolicy }}
581+ dnsPolicy : {{ $.Values.dnsPolicy }}
582+ {{- end }}
583+ {{- with $.Values.dnsConfig }}
584+ dnsConfig : {{- toYaml . | nindent 8 }}
585+ {{- end }}
586+ {{- with $.Values.podSecurityContext }}
587+ securityContext : {{- toYaml . | nindent 8 }}
588+ {{- end }}
589+ {{- with $.Values.jobs.nodeSelector }}
590+ nodeSelector : {{- toYaml . | nindent 8 }}
591+ {{- end }}
592+ {{- with $.Values.jobs.affinity }}
593+ affinity : {{- toYaml . | nindent 8 }}
594+ {{- end }}
595+ {{- with $.Values.jobs.tolerations }}
596+ tolerations : {{- toYaml . | nindent 8 }}
597+ {{- end }}
598+ {{- end }}
487599{{- range .Values.jobs.extra_hooks -}}
488600 {{- $name := print "extra-helm-hook" (include "stackstorm-ha.hyphenPrefix" (required "You must name each entry in jobs.extra_hooks." .name)) }}
489601 {{- if not ($.Values.jobs.skip | has $name) }}
0 commit comments