mirror of
https://github.com/truecharts/library-charts.git
synced 2026-07-05 23:16:21 -03:00
lifecycle add some guardrails and add docs
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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 }}
|
||||
|
||||
75
library/common/_docs/values/lifecycle.md
Normal file
75
library/common/_docs/values/lifecycle.md
Normal 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)
|
||||
Reference in New Issue
Block a user