Skip to content

Commit e520c3a

Browse files
mhaxpmhaxpheubeck
authored
[Application]: add command to container and sidecars and fix security context (again) (#164)
We trapped into helm/helm#5238 with the merge of default security context with specific ones in sidecar or initcontainer. objects seem to be merged by using the `or` operation - effectively making `true` always the result for bool properties. with this change, behavior changes, but as it was already wrong in the past it just can get better. --------- Co-authored-by: mhaxp <hartkopf@xplace.de> Co-authored-by: Florian Heubeck <40993644+heubeck@users.noreply.github.com> Co-authored-by: Florian Heubeck <heubeck@mediamarktsaturn.com>
1 parent f586829 commit e520c3a

File tree

7 files changed

+46
-17
lines changed

7 files changed

+46
-17
lines changed

chart-tests/application/ci/test-image-lifecycle-values.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ image:
99
repository: busybox
1010
tag: stable
1111
container:
12-
args: ["sleep", "2000"]
12+
command: ["sh", "-c"]
13+
args: ["sleep 2000"]
1314
lifecycle:
1415
postStart:
1516
exec:

chart-tests/application/ci/test-init-container-values.yaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ initContainers:
3232
command: ['ls', '-lah', '/']
3333
env: {}
3434
restartPolicy: Never
35-
securityContext:
36-
runAsNonRoot: true
37-
allowPrivilegeEscalation: false
38-
runAsUser: 65534
39-
runAsGroup: 65534
35+
36+
37+
initDefaults:
38+
securityContext:
39+
runAsNonRoot: true
40+
allowPrivilegeEscalation: false
41+
runAsUser: 65534
42+
runAsGroup: 65534

chart-tests/application/ci/test-sidecar-values.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ sidecars:
3030
port: 9090
3131
securityContext:
3232
runAsUser: 65532
33+
allowPrivilegeEscalation: false
3334
volumeMountNames:
3435
- share
3536
ports:
@@ -55,6 +56,17 @@ sidecars:
5556
port: 7070
5657
securityContext:
5758
runAsUser: 65532
59+
allowPrivilegeEscalation: false
60+
- name: commandtest
61+
image:
62+
repository: busybox
63+
tag: stable
64+
command: ["sh", "-c"]
65+
args: ["sleep 2000"]
66+
livenessProbe:
67+
cmd: ['ls']
68+
readinessProbe:
69+
cmd: ['ls']
5870

5971
sidecarDefaults:
6072
resources:
@@ -64,3 +76,6 @@ sidecarDefaults:
6476
limits:
6577
cpu: 100m
6678
memory: 100Mi
79+
securityContext:
80+
runAsNonRoot: false
81+
allowPrivilegeEscalation: false

chart-tests/application/ci/test-statefulset-sidecar-values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ sidecars:
3333
port: 9090
3434
securityContext:
3535
runAsUser: 65532
36+
allowPrivilegeEscalation: false
3637
volumeMountNames:
3738
- share
3839
- name: kickback
@@ -54,6 +55,7 @@ sidecars:
5455
port: 7070
5556
securityContext:
5657
runAsUser: 65532
58+
allowPrivilegeEscalation: false
5759

5860
sidecarDefaults:
5961
resources:

charts/application/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ maintainers:
77
- name: MediaMarktSaturn
88
url: https://github.com/MediaMarktSaturn
99
appVersion: 1.0.0
10-
version: 1.29.1
10+
version: 1.30.0

charts/application/templates/_podTemplate.tpl

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,7 @@ spec:
6262
- {{ . | quote }}
6363
{{- end }}
6464
securityContext:
65-
{{- if and $i.securityContext $.Values.initDefaults.securityContext }}
66-
{{- toYaml (merge $i.securityContext $.Values.initDefaults.securityContext) | nindent 8 }}
67-
{{- else }}
68-
{{- toYaml (or $i.securityContext $.Values.initDefaults.securityContext) | nindent 8 }}
69-
{{- end }}
65+
{{- toYaml (default $.Values.initDefaults.securityContext $i.securityContext ) | nindent 8 }}
7066
resources:
7167
{{- toYaml (or $i.resources $.Values.initDefaults.resources) | nindent 8 }}
7268
env:
@@ -121,16 +117,18 @@ spec:
121117
image: "{{ .image.repository }}:{{ .image.tag }}"
122118
{{- end }}
123119
imagePullPolicy: {{ or $s.image.pullPolicy $.Values.sidecarDefaults.image.pullPolicy }}
120+
{{- if $s.command }}
121+
command:
122+
{{- range $s.command }}
123+
- {{ . | quote }}
124+
{{- end }}
125+
{{- end }}
124126
args: {{ if not $s.args }}[]{{ end }}
125127
{{- range $s.args }}
126128
- {{ . | quote }}
127129
{{- end }}
128130
securityContext:
129-
{{- if and $s.securityContext $.Values.sidecarDefaults.securityContext }}
130-
{{- toYaml (merge $s.securityContext $.Values.sidecarDefaults.securityContext) | nindent 8 }}
131-
{{- else }}
132-
{{- toYaml (or $s.securityContext $.Values.sidecarDefaults.securityContext) | nindent 8 }}
133-
{{- end }}
131+
{{- toYaml (default $.Values.sidecarDefaults.securityContext $s.securityContext) | nindent 8 }}
134132
resources:
135133
{{- toYaml (or $s.resources $.Values.sidecarDefaults.resources) | nindent 8 }}
136134
env:
@@ -254,6 +252,12 @@ spec:
254252
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
255253
{{- end }}
256254
imagePullPolicy: {{ .Values.image.pullPolicy }}
255+
{{- if .Values.container.command }}
256+
command:
257+
{{- range .Values.container.command }}
258+
- {{ . | quote }}
259+
{{- end }}
260+
{{- end }}
257261
args: {{ if not .Values.container.args }}[]{{ end }}
258262
{{- range .Values.container.args }}
259263
- {{ . | quote }}

charts/application/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ container:
1212
# annotations to be added to the pod template
1313
annotations:
1414
"cluster-autoscaler.kubernetes.io/safe-to-evict": "true"
15+
# command line given to the container; []string
16+
command: []
1517
# arguments given to the container; []string
1618
args: []
1719

@@ -342,6 +344,7 @@ sidecars: []
342344
# image:
343345
# repository: quay.io/heubeck/examiner
344346
# tag: 1.13.3
347+
# command: []
345348
# args: []
346349
# env: {}
347350
# configEnvFrom: []
@@ -425,6 +428,7 @@ initDefaults:
425428
cpu: 500m
426429
memory: 100Mi
427430
restartPolicy: Always
431+
# securityContext: {}
428432

429433
# List of tolerations, will be taken over like-for-like to pod-spec
430434
tolerations: []

0 commit comments

Comments
 (0)