lifecycle add some guardrails and add docs

This commit is contained in:
Stavros kois
2022-11-29 13:04:35 +02:00
parent fc9bb625f0
commit b17fd5c22c
3 changed files with 91 additions and 0 deletions

View File

@@ -148,6 +148,15 @@ tests:
- /bin/bash
- some_value
- it: should fail with invalid key
set:
lifecycle:
preStart:
command: something
asserts:
- failedTemplate:
errorMessage: Invalid key (preStart) in lifecycle. Valid keys are preStop and postStart
- it: should fail with no command in preStop
set:
lifecycle:

View File

@@ -1,5 +1,12 @@
{{/* Returns the lifecycle for the container */}}
{{- define "ix.v1.common.container.lifecycle" -}}
{{- with .Values.lifecycle -}}
{{- range $k, $v := . -}}
{{- if not (has $k (list "preStop" "postStart")) -}}
{{- fail (printf "Invalid key (%s) in lifecycle. Valid keys are preStop and postStart" $k ) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if (hasKey .Values.lifecycle "preStop") -}}
{{- with .Values.lifecycle.preStop.command }}
{{- print "preStop:" | nindent 0 }}

View File

@@ -0,0 +1,75 @@
# Lifecycle
## Key: lifecycle
- Type: `dict`
- Default: `{}`
- Helm Template:
- lifecycle.preStop.command - String: ✅
- lifecycle.preStop.command - List entry: ✅
- lifecycle.postStart.command - String: ✅
- lifecycle.postStart.command - List entry: ✅
`lifecycle` key defines hooks that can run on the pod. Like `preStop` or `postStart`
Examples `preStop`:
```yaml
# String / Single command
lifecycle:
preStop:
command: ./custom-script.sh
# String / Single command (tpl)
lifecycle:
preStop:
command: "{{ .Values.customCommand }}"
# List
lifecycle:
preStop:
command:
- /bin/sh
- -c
- |
echo "Doing things..."
# List (tpl)
lifecycle:
preStop:
command:
- /path/to/executable
- --port
- "{{ .Values.service.main.ports.main.port }}"
```
Examples `postStart`:
```yaml
# String / Single command
lifecycle:
postStart:
command: ./custom-script.sh
# String / Single command (tpl)
lifecycle:
postStart:
command: "{{ .Values.customCommand }}"
# List
lifecycle:
postStart:
command:
- /bin/sh
- -c
- |
echo "Doing things..."
# List (tpl)
lifecycle:
postStart:
command:
- /path/to/executable
- --port
- "{{ .Values.service.main.ports.main.port }}"
```
Kubernetes Documentation:
- [lifecycle hooks](https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks)