Skip to content

Commit 8923244

Browse files
committed
charts/redpanda: allow overriding volumes
Previously it wasn't possible to use `podTemplate` to override the `VolumeSource`. Helm prevented explicitly null'ing out values due to the chart's schema and the go implementation has no concept of explicit nulls. This commit copies the precedent set in `mergeEnvVar` and simply elects the override if provided. Additionally this commit adds a test case showcasing how to use `podTemplate` to generate certificates from an initContainer. K8S-683 (cherry picked from commit 1f5dfc9)
1 parent 7a3b685 commit 8923244

File tree

5 files changed

+113
-2
lines changed

5 files changed

+113
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
project: charts/redpanda
2+
kind: Fixed
3+
body: '`statefulset.podTemplate.spec.volumes` can now be used to override chart generated volumes.'
4+
time: 2025-09-08T17:24:18.8483-04:00

charts/redpanda/helpers.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,9 @@ func mergeEnvVar(original corev1.EnvVar, overrides applycorev1.EnvVarApplyConfig
540540
}
541541

542542
func mergeVolume(original corev1.Volume, override applycorev1.VolumeApplyConfiguration) corev1.Volume {
543-
return helmette.MergeTo[corev1.Volume](override, original)
543+
// Similar to the above, if a volume is being overridden, it's likely to
544+
// change the VolumeSource. Don't merge, just accept the override.
545+
return helmette.MergeTo[corev1.Volume](override)
544546
}
545547

546548
func mergeVolumeMount(original corev1.VolumeMount, override applycorev1.VolumeMountApplyConfiguration) corev1.VolumeMount {

charts/redpanda/helpers_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,55 @@ func TestStrategicMergePatch(t *testing.T) {
247247
},
248248
},
249249
},
250+
{
251+
Name: "volumes",
252+
Override: redpanda.PodTemplate{
253+
Spec: &applycorev1.PodSpecApplyConfiguration{
254+
Volumes: []applycorev1.VolumeApplyConfiguration{
255+
{
256+
Name: ptr.To("certs-volume-mount"),
257+
VolumeSourceApplyConfiguration: applycorev1.VolumeSourceApplyConfiguration{
258+
Secret: nil,
259+
EmptyDir: &applycorev1.EmptyDirVolumeSourceApplyConfiguration{},
260+
},
261+
},
262+
},
263+
},
264+
},
265+
Original: corev1.PodTemplateSpec{
266+
Spec: corev1.PodSpec{
267+
Volumes: []corev1.Volume{
268+
{
269+
Name: "certs-volume-mount",
270+
VolumeSource: corev1.VolumeSource{
271+
Secret: &corev1.SecretVolumeSource{
272+
SecretName: "some-secret",
273+
},
274+
},
275+
},
276+
},
277+
},
278+
},
279+
Expected: corev1.PodTemplateSpec{
280+
ObjectMeta: metav1.ObjectMeta{
281+
Labels: map[string]string{},
282+
Annotations: map[string]string{},
283+
},
284+
Spec: corev1.PodSpec{
285+
NodeSelector: map[string]string{},
286+
Tolerations: []corev1.Toleration{},
287+
ImagePullSecrets: []corev1.LocalObjectReference{},
288+
Volumes: []corev1.Volume{
289+
{
290+
Name: "certs-volume-mount",
291+
VolumeSource: corev1.VolumeSource{
292+
EmptyDir: &corev1.EmptyDirVolumeSource{},
293+
},
294+
},
295+
},
296+
},
297+
},
298+
},
250299
}
251300

252301
for _, tc := range cases {

charts/redpanda/templates/_helpers.go.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@
568568
{{- range $_ := (list 1) -}}
569569
{{- $_is_returning := false -}}
570570
{{- $_is_returning = true -}}
571-
{{- (dict "r" (merge (dict) $override $original)) | toJson -}}
571+
{{- (dict "r" (merge (dict) $override)) | toJson -}}
572572
{{- break -}}
573573
{{- end -}}
574574
{{- end -}}

charts/redpanda/testdata/template-cases.txtar

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,3 +1163,59 @@ statefulset:
11631163
enabled: false
11641164
pvcUnbinder:
11651165
enabled: false
1166+
1167+
-- jit-certificates --
1168+
# ASSERT-NO-ERROR
1169+
# ASSERT-FIELD-EQUALS ["apps/v1/StatefulSet", "default/redpanda", "{.spec.template.spec.volumes[?(@.name == \"redpanda-external-cert\")]}", {"name": "redpanda-external-cert", "emptyDir": {}}]
1170+
# This case demonstrates how to provide "Just In Time" certificates via an
1171+
# initContainer by using podTemplate to overwrite the auto generated volume.
1172+
tls:
1173+
certs:
1174+
external:
1175+
# Uncomment this block to disable the generation of cert-manager Certificates.
1176+
# secretRef:
1177+
# name: "set-to-disable-cert-manager"
1178+
1179+
# Controls whether or not the chart expects a ca.crt key to
1180+
# exist in the volume we create with the below init
1181+
# container. If set to false, the trustStore feature can
1182+
# continue to be used as is with the strategy.
1183+
caEnabled: true
1184+
1185+
statefulset:
1186+
podTemplate:
1187+
spec:
1188+
initContainers:
1189+
- name: cert-minter
1190+
image: debian:latest
1191+
command:
1192+
- bash
1193+
- -c
1194+
- 'cp -L -r /original/.'
1195+
# Provide the rest of your initContainer implementation here.
1196+
# This runs with the redpanda ServiceAccount.
1197+
volumeMounts:
1198+
# autoMountServiceAccountToken is set to false but we do mount it. To
1199+
# mount it to your init container, specify this volume:
1200+
- name: "kube-api-access"
1201+
readOnly: true
1202+
mountPath: "/var/run/secrets/kubernetes.io/serviceaccount"
1203+
# Mount the empty dir volume that will be used to pass certs through to redpanda.
1204+
- name: "redpanda-external-cert"
1205+
mountPath: "/certs"
1206+
# Unique to this example, we're just stealing the certs from the original.
1207+
- name: "3rd-party-certs"
1208+
mountPath: "/original"
1209+
1210+
volumes:
1211+
# Here's where the "magic" is. We're going to use podTemplate
1212+
# to override the standard certificate mount that the chart
1213+
# generates with an emptyDir. The initContainer will then
1214+
# populate it with a tls.crt, tls.key, and (optionally) ca.crt
1215+
# which makes it look like a standard TLS Secret mount.
1216+
- name: "redpanda-external-cert" # "{{ nameOverride }}-{{ cert }}-cert"
1217+
emptyDir: {}
1218+
# Unique to this example, we're just stealing the certs from the original.
1219+
- name: "3rd-party-certs"
1220+
secret:
1221+
secretName: "redpanda-external-cert"

0 commit comments

Comments
 (0)