Skip to content

Commit

Permalink
redpanda: values.statefulSet.initContainers.tuning.extraVolumeMounts …
Browse files Browse the repository at this point in the history
…is now an array, not a string template

This begins a conversion of statefulset.yaml init-containers to go.

As a part of this, the `values.yaml` type for `extraVolumeMounts` is refined to
take an explicit `corev1.VolumeMount` structure rather than a bare string that
was interpreted as templated yaml.
  • Loading branch information
jan-g committed Jul 3, 2024
1 parent 4275f32 commit 23dcc88
Show file tree
Hide file tree
Showing 81 changed files with 1,246 additions and 1,030 deletions.
2 changes: 1 addition & 1 deletion charts/redpanda/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ To create `Guaranteed` Pods for Redpanda brokers, provide both requests and limi

### [statefulset.initContainers.tuning.extraVolumeMounts](https://artifacthub.io/packages/helm/redpanda-data/redpanda?modal=values&path=statefulset.initContainers.tuning.extraVolumeMounts)

**Default:** `""`
**Default:** `[]`

### [statefulset.initContainers.tuning.resources](https://artifacthub.io/packages/helm/redpanda-data/redpanda?modal=values&path=statefulset.initContainers.tuning.resources)

Expand Down
2 changes: 1 addition & 1 deletion charts/redpanda/ci/09-initcontainers-resources-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ statefulset:
- name: test-extra-volume
mountPath: /fake/lifecycle
tuning:
extraVolumeMounts: |-
extraVolumeMounts:
- name: test-extra-volume
mountPath: /fake/lifecycle
setDataDirOwnership:
Expand Down
43 changes: 43 additions & 0 deletions charts/redpanda/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,46 @@ func StatefulSetVolumeMounts(dot *helmette.Dot) []corev1.VolumeMount {

return mounts
}

func StatefulSetInitContainers(dot *helmette.Dot) []corev1.Container {
// As init-containers are converted, return them here
var containers []corev1.Container
if c := statefulSetInitContainerTuning(dot); c != nil {
containers = append(containers, *c)
}
return containers
}

func statefulSetInitContainerTuning(dot *helmette.Dot) *corev1.Container {
values := helmette.Unwrap[Values](dot.Values)

if !values.Tuning.TuneAIOEvents {
return nil
}

return &corev1.Container{
Name: "tuning",
Image: fmt.Sprintf("%s:%s", values.Image.Repository, Tag(dot)),
Command: []string{
`/bin/bash`,
`-c`,
`rpk redpanda tune all`,
},
SecurityContext: &corev1.SecurityContext{
Capabilities: &corev1.Capabilities{
Add: []corev1.Capability{`SYS_RESOURCE`},
},
Privileged: ptr.To(true),
RunAsUser: ptr.To(int64(0)),
RunAsGroup: ptr.To(int64(0)),
},
VolumeMounts: append(append(CommonMounts(dot),
values.Statefulset.InitContainers.Tuning.ExtraVolumeMounts...),
corev1.VolumeMount{
Name: Fullname(dot),
MountPath: "/etc/redpanda",
},
),
Resources: helmette.UnmarshalInto[corev1.ResourceRequirements](values.Statefulset.InitContainers.Tuning.Resources),
}
}
26 changes: 26 additions & 0 deletions charts/redpanda/templates/_statefulset.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,29 @@
{{- end -}}
{{- end -}}

{{- define "redpanda.StatefulSetInitContainers" -}}
{{- $dot := (index .a 0) -}}
{{- range $_ := (list 1) -}}
{{- $containers := (coalesce nil) -}}
{{- $c_6 := (get (fromJson (include "redpanda.statefulSetInitContainerTuning" (dict "a" (list $dot) ))) "r") -}}
{{- if (ne $c_6 (coalesce nil)) -}}
{{- $containers = (concat (default (list ) $containers) (list $c_6)) -}}
{{- end -}}
{{- (dict "r" $containers) | toJson -}}
{{- break -}}
{{- end -}}
{{- end -}}

{{- define "redpanda.statefulSetInitContainerTuning" -}}
{{- $dot := (index .a 0) -}}
{{- range $_ := (list 1) -}}
{{- $values := $dot.Values.AsMap -}}
{{- if (not $values.tuning.tune_aio_events) -}}
{{- (dict "r" (coalesce nil)) | toJson -}}
{{- break -}}
{{- end -}}
{{- (dict "r" (mustMergeOverwrite (dict "name" "" "resources" (dict ) ) (dict "name" "tuning" "image" (printf "%s:%s" $values.image.repository (get (fromJson (include "redpanda.Tag" (dict "a" (list $dot) ))) "r")) "command" (list `/bin/bash` `-c` `rpk redpanda tune all`) "securityContext" (mustMergeOverwrite (dict ) (dict "capabilities" (mustMergeOverwrite (dict ) (dict "add" (list `SYS_RESOURCE`) )) "privileged" true "runAsUser" ((0 | int64) | int64) "runAsGroup" ((0 | int64) | int64) )) "volumeMounts" (concat (default (list ) (concat (default (list ) (get (fromJson (include "redpanda.CommonMounts" (dict "a" (list $dot) ))) "r")) (default (list ) $values.statefulset.initContainers.tuning.extraVolumeMounts))) (list (mustMergeOverwrite (dict "name" "" "mountPath" "" ) (dict "name" (get (fromJson (include "redpanda.Fullname" (dict "a" (list $dot) ))) "r") "mountPath" "/etc/redpanda" )))) "resources" $values.statefulset.initContainers.tuning.resources ))) | toJson -}}
{{- break -}}
{{- end -}}
{{- end -}}

26 changes: 4 additions & 22 deletions charts/redpanda/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ limitations under the License.
-}}
{{- end -}}
{{- end -}}

{{- $initContainers := (get ((include "redpanda.StatefulSetInitContainers" (dict "a" (list .))) | fromJson) "r") -}}
---
apiVersion: apps/v1
kind: StatefulSet
Expand Down Expand Up @@ -61,28 +63,8 @@ spec:
imagePullSecrets: {{- toYaml . | nindent 8 }}
{{- end }}
initContainers:
{{- if and (hasKey $values.tuning "tune_aio_events") $values.tuning.tune_aio_events }}
- name: tuning
image: {{ .Values.image.repository }}:{{ template "redpanda.tag" . }}
command:
- /bin/bash
- -c
- rpk redpanda tune all
securityContext:
capabilities:
add: ["SYS_RESOURCE"]
privileged: true
runAsUser: 0
runAsGroup: 0
volumeMounts: {{ include "common-mounts" . | nindent 12 }}
{{- if dig "initContainers" "tuning" "extraVolumeMounts" false .Values.statefulset -}}
{{ tpl .Values.statefulset.initContainers.tuning.extraVolumeMounts . | nindent 12 }}
{{- end }}
- name: {{ template "redpanda.fullname" . }}
mountPath: /etc/redpanda
{{- if get .Values.statefulset.initContainers.tuning "resources" }}
resources: {{- toYaml .Values.statefulset.initContainers.tuning.resources | nindent 12 }}
{{- end }}
{{- if not (empty $initContainers) }}
{{- toYaml $initContainers | nindent 8 }}
{{- end }}
{{- if .Values.statefulset.initContainers.setDataDirOwnership.enabled }}
- name: set-datadir-ownership
Expand Down
30 changes: 16 additions & 14 deletions charts/redpanda/testdata/ci/01-default-values.yaml.golden
Original file line number Diff line number Diff line change
Expand Up @@ -773,25 +773,27 @@ spec:
fsGroupChangePolicy: OnRootMismatch
serviceAccountName: default
initContainers:
- name: tuning
- command:
- /bin/bash
- -c
- rpk redpanda tune all
image: docker.redpanda.com/redpandadata/redpanda:v24.1.8
command:
- /bin/bash
- -c
- rpk redpanda tune all
name: tuning
resources: {}
securityContext:
capabilities:
add: ["SYS_RESOURCE"]
add:
- SYS_RESOURCE
privileged: true
runAsUser: 0
runAsGroup: 0
volumeMounts:
- mountPath: /etc/tls/certs/default
name: redpanda-default-cert
- mountPath: /etc/tls/certs/external
name: redpanda-external-cert
- name: redpanda
mountPath: /etc/redpanda
runAsUser: 0
volumeMounts:
- mountPath: /etc/tls/certs/default
name: redpanda-default-cert
- mountPath: /etc/tls/certs/external
name: redpanda-external-cert
- mountPath: /etc/redpanda
name: redpanda
- name: redpanda-configurator
image: docker.redpanda.com/redpandadata/redpanda:v24.1.8
command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,22 +640,23 @@ spec:
fsGroupChangePolicy: OnRootMismatch
serviceAccountName: default
initContainers:
- name: tuning
- command:
- /bin/bash
- -c
- rpk redpanda tune all
image: docker.redpanda.com/redpandadata/redpanda:v24.1.8
command:
- /bin/bash
- -c
- rpk redpanda tune all
name: tuning
resources: {}
securityContext:
capabilities:
add: ["SYS_RESOURCE"]
add:
- SYS_RESOURCE
privileged: true
runAsUser: 0
runAsGroup: 0
volumeMounts:
- name: redpanda
mountPath: /etc/redpanda
runAsUser: 0
volumeMounts:
- mountPath: /etc/redpanda
name: redpanda
- name: redpanda-configurator
image: docker.redpanda.com/redpandadata/redpanda:v24.1.8
command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,25 +736,27 @@ spec:
fsGroupChangePolicy: OnRootMismatch
serviceAccountName: default
initContainers:
- name: tuning
- command:
- /bin/bash
- -c
- rpk redpanda tune all
image: docker.redpanda.com/redpandadata/redpanda:v24.1.8
command:
- /bin/bash
- -c
- rpk redpanda tune all
name: tuning
resources: {}
securityContext:
capabilities:
add: ["SYS_RESOURCE"]
add:
- SYS_RESOURCE
privileged: true
runAsUser: 0
runAsGroup: 0
volumeMounts:
- mountPath: /etc/tls/certs/default
name: redpanda-default-cert
- mountPath: /etc/tls/certs/external
name: redpanda-external-cert
- name: redpanda
mountPath: /etc/redpanda
runAsUser: 0
volumeMounts:
- mountPath: /etc/tls/certs/default
name: redpanda-default-cert
- mountPath: /etc/tls/certs/external
name: redpanda-external-cert
- mountPath: /etc/redpanda
name: redpanda
- name: redpanda-configurator
image: docker.redpanda.com/redpandadata/redpanda:v24.1.8
command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -754,24 +754,26 @@ spec:
fsGroupChangePolicy: OnRootMismatch
serviceAccountName: default
initContainers:
- name: tuning
- command:
- /bin/bash
- -c
- rpk redpanda tune all
image: docker.redpanda.com/redpandadata/redpanda:v24.1.8
command:
- /bin/bash
- -c
- rpk redpanda tune all
name: tuning
resources: {}
securityContext:
capabilities:
add: ["SYS_RESOURCE"]
add:
- SYS_RESOURCE
privileged: true
runAsUser: 0
runAsGroup: 0
volumeMounts:
- mountPath: /etc/secrets/users
name: users
readOnly: true
- name: redpanda
mountPath: /etc/redpanda
runAsUser: 0
volumeMounts:
- mountPath: /etc/secrets/users
name: users
readOnly: true
- mountPath: /etc/redpanda
name: redpanda
- name: redpanda-configurator
image: docker.redpanda.com/redpandadata/redpanda:v24.1.8
command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -872,28 +872,30 @@ spec:
fsGroupChangePolicy: OnRootMismatch
serviceAccountName: default
initContainers:
- name: tuning
- command:
- /bin/bash
- -c
- rpk redpanda tune all
image: docker.redpanda.com/redpandadata/redpanda:v24.1.8
command:
- /bin/bash
- -c
- rpk redpanda tune all
name: tuning
resources: {}
securityContext:
capabilities:
add: ["SYS_RESOURCE"]
add:
- SYS_RESOURCE
privileged: true
runAsUser: 0
runAsGroup: 0
volumeMounts:
- mountPath: /etc/secrets/users
name: users
readOnly: true
- mountPath: /etc/tls/certs/default
name: redpanda-default-cert
- mountPath: /etc/tls/certs/external
name: redpanda-external-cert
- name: redpanda
mountPath: /etc/redpanda
runAsUser: 0
volumeMounts:
- mountPath: /etc/secrets/users
name: users
readOnly: true
- mountPath: /etc/tls/certs/default
name: redpanda-default-cert
- mountPath: /etc/tls/certs/external
name: redpanda-external-cert
- mountPath: /etc/redpanda
name: redpanda
- name: redpanda-configurator
image: docker.redpanda.com/redpandadata/redpanda:v24.1.8
command:
Expand Down
30 changes: 16 additions & 14 deletions charts/redpanda/testdata/ci/06-rack-awareness-values.yaml.golden
Original file line number Diff line number Diff line change
Expand Up @@ -893,25 +893,27 @@ spec:
fsGroupChangePolicy: OnRootMismatch
serviceAccountName: redpanda
initContainers:
- name: tuning
- command:
- /bin/bash
- -c
- rpk redpanda tune all
image: docker.redpanda.com/redpandadata/redpanda:v24.1.8
command:
- /bin/bash
- -c
- rpk redpanda tune all
name: tuning
resources: {}
securityContext:
capabilities:
add: ["SYS_RESOURCE"]
add:
- SYS_RESOURCE
privileged: true
runAsUser: 0
runAsGroup: 0
volumeMounts:
- mountPath: /etc/tls/certs/default
name: redpanda-default-cert
- mountPath: /etc/tls/certs/external
name: redpanda-external-cert
- name: redpanda
mountPath: /etc/redpanda
runAsUser: 0
volumeMounts:
- mountPath: /etc/tls/certs/default
name: redpanda-default-cert
- mountPath: /etc/tls/certs/external
name: redpanda-external-cert
- mountPath: /etc/redpanda
name: redpanda
- name: redpanda-configurator
image: docker.redpanda.com/redpandadata/redpanda:v24.1.8
command:
Expand Down
Loading

0 comments on commit 23dcc88

Please sign in to comment.