Skip to content

Commit

Permalink
Merge pull request #142 from MediaMarktSaturn/container-lifecycle
Browse files Browse the repository at this point in the history
[Application] Add Container lifecycle
  • Loading branch information
knabben-mms authored Aug 27, 2024
2 parents c174037 + c2ce164 commit ba1efac
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
23 changes: 23 additions & 0 deletions chart-tests/application/ci/test-image-lifecycle-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
resources:
requests:
cpu: 10m
memory: 50Mi
limits:
cpu: 100m
memory: 100Mi
image:
repository: busybox
tag: stable
container:
args: ["sleep", "2000"]
lifecycle:
postStart:
exec:
command: ["/bin/sh", "-c", "echo $(ls /)"]
preStop:
exec:
command: ["/bin/sh", "-c", "echo exiting"]
livenessProbe:
cmd: ['ls']
readinessProbe:
cmd: ['ls']
2 changes: 1 addition & 1 deletion charts/application/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ maintainers:
- name: MediaMarktSaturn
url: https://github.com/MediaMarktSaturn
appVersion: 1.0.0
version: 1.22.0
version: 1.23.0
22 changes: 22 additions & 0 deletions charts/application/templates/_podTemplate.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,17 @@ spec:
failureThreshold: {{ $.Values.readinessProbe.failureThreshold }}
timeoutSeconds: {{ $.Values.readinessProbe.timeoutSeconds }}
{{- end }}
{{- if and $s.lifecycle ( or $s.lifecycle.postStart $s.lifecycle.preStop ) }}
lifecycle:
{{- if $s.lifecycle.postStart }}
postStart:
{{- toYaml ($s.lifecycle.postStart) | nindent 10 }}
{{- end }}
{{- if $s.lifecycle.preStop }}
preStop:
{{- toYaml ($s.lifecycle.preStop) | nindent 10 }}
{{- end }}
{{- end }}
{{- end }}
- name: {{ .Release.Name }}
{{- if .Values.container.securityContext }}
Expand Down Expand Up @@ -305,6 +316,17 @@ spec:
- name: {{ .name }}
mountPath: {{ .mountPath }}
{{- end }}
{{- if or .Values.lifecycle.postStart .Values.lifecycle.preStop }}
lifecycle:
{{- if .Values.lifecycle.postStart }}
postStart:
{{- toYaml (.Values.lifecycle.postStart) | nindent 10 }}
{{- end }}
{{- if .Values.lifecycle.preStop }}
preStop:
{{- toYaml (.Values.lifecycle.preStop) | nindent 10 }}
{{- end }}
{{- end }}
{{ $hasSidecarVolume := 0 }}
{{ range .Values.sidecars }}{{ if .secretVolumes }}{{ $hasSidecarVolume = 1 }}{{ end }}{{ end }}
{{ $hasInitVolume := 0 }}
Expand Down
8 changes: 8 additions & 0 deletions charts/application/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ resources: {}
# cpu: 2
# memory: 3000Mi

# The lifecycle handlers for the pod: https://kubernetes.io/docs/tasks/configure-pod-container/attach-handler-lifecycle-event/#define-poststart-and-prestop-handlers
lifecycle:
postStart: {}
preStop: {}

podSecurityContext: {}
configuration: {}

Expand Down Expand Up @@ -333,6 +338,9 @@ sidecars: []
# # 'volumeMounts' names to be mounted in sidecar as well (under the same path); default: none
# volumeMountNames: []
# # - data
# lifecycle:
# postStart: {}
# preStop: {}

# default values that apply on sidecars if not explicit set
sidecarDefaults:
Expand Down

0 comments on commit ba1efac

Please sign in to comment.