Skip to content

Commit

Permalink
Merge pull request #206 from cognifloyd/lifecycle-hooks
Browse files Browse the repository at this point in the history
Allow adding postStartScript lifecycle hook to all deployments
  • Loading branch information
arm4b authored Jul 13, 2021
2 parents 1ff6e36 + 746845e commit 494096a
Show file tree
Hide file tree
Showing 4 changed files with 311 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* Move st2-config-vol volume definition and list of st2-config-vol volumeMounts to helpers to reduce duplication (#198) (by @cognifloyd)
* Fix permissions for /home/stanley/.ssh/stanley_rsa using the postStart lifecycle hook (#219) (by @cognifloyd)
* Make system_user configurable when using custom st2actionrunner images that do not provide stanley (#220) (by @cognifloyd)
* Allow providing scripts in values for use in lifecycle postStart hooks of all deployments. (#206) (by @cognifloyd)

## v0.60.0
* Switch st2 version to `v3.5dev` as a new latest development version (#187)
Expand Down
14 changes: 11 additions & 3 deletions templates/configmaps_post-start-script.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{{- range tuple "st2auth" "st2api" "st2stream" "st2web" "st2rulesengine" "st2timersengine" "st2workflowengine" "st2scheduler" "st2notifier" "st2sensorcontainer" "st2actionrunner" "st2garbagecollector" "st2client" "st2chatops" -}}
{{- if or (index $.Values . "postStartScript") (eq . "st2actionrunner") (eq . "st2client") }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ $.Release.Name }}-st2actionrunner-post-start-script
name: {{ $.Release.Name }}-{{ . }}-post-start-script
annotations:
description: Custom postStart lifecycle event handler script for st2actionrunner
description: Custom postStart lifecycle event handler script for {{ . }}
labels:
app: st2
tier: backend
Expand All @@ -13,11 +15,12 @@ metadata:
release: {{ $.Release.Name }}
heritage: {{ $.Release.Service }}
data:
# k8s calls this script in parallel with starting st2actionrunner (ie the same time as ENTRYPOINT)
# k8s calls this script in parallel with starting {{ . }} (ie the same time as ENTRYPOINT)
# The pod will not be marked as "running" until this script completes successfully.
# see: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/
post-start.sh: |
#!/bin/bash
{{- if or (eq . "st2actionrunner") (eq . "st2client") }}
{{- $system_user := $.Values.st2.system_user.user }}
{{- $ssh_key_file := tpl $.Values.st2.system_user.ssh_key_file $ }}
{{- $ssh_key_file_name := base $ssh_key_file }}
Expand All @@ -27,3 +30,8 @@ data:
chown -R {{ $system_user }}:{{ $system_user }} {{ $ssh_key_file_dir }}
chmod 400 {{ $ssh_key_file }}
chmod 500 {{ $ssh_key_file_dir }}
{{- end }}
{{- index $.Values . "postStartScript" | nindent 4 }}
{{- end }}
{{- end -}}
Loading

0 comments on commit 494096a

Please sign in to comment.