From 7a42c42f171528df7f064ab4f3e739fc8c2ec8b8 Mon Sep 17 00:00:00 2001 From: knabben-mms Date: Fri, 16 Aug 2024 13:52:41 +0200 Subject: [PATCH 1/7] add container lifecycle for main and sidecars --- charts/application/templates/_podTemplate.tpl | 22 +++++++++++++++++++ charts/application/values.yaml | 8 +++++++ 2 files changed, 30 insertions(+) diff --git a/charts/application/templates/_podTemplate.tpl b/charts/application/templates/_podTemplate.tpl index 88a2d96..409cac3 100644 --- a/charts/application/templates/_podTemplate.tpl +++ b/charts/application/templates/_podTemplate.tpl @@ -197,6 +197,17 @@ spec: failureThreshold: {{ $.Values.readinessProbe.failureThreshold }} timeoutSeconds: {{ $.Values.readinessProbe.timeoutSeconds }} {{- end }} + {{- if 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 }} @@ -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 $s.lifecycle.preStop }} + preStop: + {{- toYaml (.Values.lifecycle.preStop) | nindent 10 }} + {{- end }} + {{- end }} {{ $hasSidecarVolume := 0 }} {{ range .Values.sidecars }}{{ if .secretVolumes }}{{ $hasSidecarVolume = 1 }}{{ end }}{{ end }} {{ $hasInitVolume := 0 }} diff --git a/charts/application/values.yaml b/charts/application/values.yaml index c27c532..266a262 100644 --- a/charts/application/values.yaml +++ b/charts/application/values.yaml @@ -112,6 +112,11 @@ resources: {} # cpu: 2 # memory: 3000Mi +# The lifecycle handlers for the container +lifecycle: + postStart: {} + preStop: {} + podSecurityContext: {} configuration: {} @@ -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: From 11a936a38fc7def6bc72a0240bd8ac9e28f75393 Mon Sep 17 00:00:00 2001 From: knabben-mms Date: Tue, 27 Aug 2024 12:11:46 +0200 Subject: [PATCH 2/7] Bump Chart Version --- charts/application/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/application/Chart.yaml b/charts/application/Chart.yaml index a1554e9..aaefc7f 100644 --- a/charts/application/Chart.yaml +++ b/charts/application/Chart.yaml @@ -7,4 +7,4 @@ maintainers: - name: MediaMarktSaturn url: https://github.com/MediaMarktSaturn appVersion: 1.0.0 -version: 1.22.0 +version: 1.23.0 From 6d770eef514733a081fff11c082c98e20596573e Mon Sep 17 00:00:00 2001 From: knabben-mms Date: Tue, 27 Aug 2024 12:27:52 +0200 Subject: [PATCH 3/7] Fix template --- charts/application/templates/_podTemplate.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/application/templates/_podTemplate.tpl b/charts/application/templates/_podTemplate.tpl index 409cac3..84dd98b 100644 --- a/charts/application/templates/_podTemplate.tpl +++ b/charts/application/templates/_podTemplate.tpl @@ -322,7 +322,7 @@ spec: postStart: {{- toYaml (.Values.lifecycle.postStart) | nindent 10 }} {{- end }} - {{- if $s.lifecycle.preStop }} + {{- if .Values.lifecycle.preStop }} preStop: {{- toYaml (.Values.lifecycle.preStop) | nindent 10 }} {{- end }} From 03701e23ba36232a93f6d3f3f4fe3a06caad0180 Mon Sep 17 00:00:00 2001 From: knabben-mms Date: Tue, 27 Aug 2024 12:28:23 +0200 Subject: [PATCH 4/7] Add test for image lifecycle --- .../ci/test-image-lifecycle-values.yaml | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 chart-tests/application/ci/test-image-lifecycle-values.yaml diff --git a/chart-tests/application/ci/test-image-lifecycle-values.yaml b/chart-tests/application/ci/test-image-lifecycle-values.yaml new file mode 100644 index 0000000..2bd6fad --- /dev/null +++ b/chart-tests/application/ci/test-image-lifecycle-values.yaml @@ -0,0 +1,20 @@ +resources: + requests: + cpu: 10m + memory: 50Mi + limits: + cpu: 100m + memory: 100Mi +image: + repository: busybox + tag: latest +container: + args: ["sleep", "2000"] +lifecycle: + postStart: + exec: + command: ["/bin/sh", "-c", "echo $(ls /)"] + preStop: + exec: + command: ["/bin/sh", "-c", "echo exiting"] + From 5f2e0c92caa228af7a644dd98630b50fbbeb4e44 Mon Sep 17 00:00:00 2001 From: knabben-mms Date: Tue, 27 Aug 2024 12:37:06 +0200 Subject: [PATCH 5/7] fix test values --- .../application/ci/test-image-lifecycle-values.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/chart-tests/application/ci/test-image-lifecycle-values.yaml b/chart-tests/application/ci/test-image-lifecycle-values.yaml index 2bd6fad..6ac0535 100644 --- a/chart-tests/application/ci/test-image-lifecycle-values.yaml +++ b/chart-tests/application/ci/test-image-lifecycle-values.yaml @@ -7,7 +7,7 @@ resources: memory: 100Mi image: repository: busybox - tag: latest + tag: stable container: args: ["sleep", "2000"] lifecycle: @@ -17,4 +17,7 @@ lifecycle: preStop: exec: command: ["/bin/sh", "-c", "echo exiting"] - +livenessProbe: + cmd: ['ls'] +readinessProbe: + cmd: ['ls'] From 3f3f9e1ef2a3ac70f44aa77d76882575871a17a5 Mon Sep 17 00:00:00 2001 From: knabben-mms Date: Tue, 27 Aug 2024 13:16:56 +0200 Subject: [PATCH 6/7] Fix pod template --- charts/application/templates/_podTemplate.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/application/templates/_podTemplate.tpl b/charts/application/templates/_podTemplate.tpl index 84dd98b..dd8eb06 100644 --- a/charts/application/templates/_podTemplate.tpl +++ b/charts/application/templates/_podTemplate.tpl @@ -197,7 +197,7 @@ spec: failureThreshold: {{ $.Values.readinessProbe.failureThreshold }} timeoutSeconds: {{ $.Values.readinessProbe.timeoutSeconds }} {{- end }} - {{- if or $s.lifecycle.postStart $s.lifecycle.preStop }} + {{- if or $s.lifecycle $s.lifecycle.postStart $s.lifecycle.preStop }} lifecycle: {{- if $s.lifecycle.postStart }} postStart: From 57215a9f18ed2963db83c5122f58063a060219e9 Mon Sep 17 00:00:00 2001 From: knabben-mms Date: Tue, 27 Aug 2024 13:37:06 +0200 Subject: [PATCH 7/7] Fix doku and podTemplate --- charts/application/templates/_podTemplate.tpl | 2 +- charts/application/values.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/application/templates/_podTemplate.tpl b/charts/application/templates/_podTemplate.tpl index dd8eb06..2436275 100644 --- a/charts/application/templates/_podTemplate.tpl +++ b/charts/application/templates/_podTemplate.tpl @@ -197,7 +197,7 @@ spec: failureThreshold: {{ $.Values.readinessProbe.failureThreshold }} timeoutSeconds: {{ $.Values.readinessProbe.timeoutSeconds }} {{- end }} - {{- if or $s.lifecycle $s.lifecycle.postStart $s.lifecycle.preStop }} + {{- if and $s.lifecycle ( or $s.lifecycle.postStart $s.lifecycle.preStop ) }} lifecycle: {{- if $s.lifecycle.postStart }} postStart: diff --git a/charts/application/values.yaml b/charts/application/values.yaml index 266a262..92b9f03 100644 --- a/charts/application/values.yaml +++ b/charts/application/values.yaml @@ -112,7 +112,7 @@ resources: {} # cpu: 2 # memory: 3000Mi -# The lifecycle handlers for the container +# 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: {}