Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
project: charts/redpanda
kind: Fixed
body: '`statefulset.podTemplate.spec.volumes` can now be used to override chart generated volumes.'
time: 2025-09-08T17:24:18.8483-04:00
4 changes: 3 additions & 1 deletion charts/redpanda/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,9 @@ func mergeEnvVar(original corev1.EnvVar, overrides applycorev1.EnvVarApplyConfig
}

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

func mergeVolumeMount(original corev1.VolumeMount, override applycorev1.VolumeMountApplyConfiguration) corev1.VolumeMount {
Expand Down
102 changes: 102 additions & 0 deletions charts/redpanda/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,108 @@ func TestStrategicMergePatch(t *testing.T) {
},
},
},
{
Name: "probes",
Override: redpanda.PodTemplate{
Spec: &applycorev1.PodSpecApplyConfiguration{
Containers: []applycorev1.ContainerApplyConfiguration{
{
Name: ptr.To("redpanda"),
StartupProbe: &applycorev1.ProbeApplyConfiguration{
FailureThreshold: ptr.To[int32](120),
},
},
},
},
},
Original: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "redpanda",
StartupProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
Exec: &corev1.ExecAction{
Command: []string{"rpk cluster health"},
},
},
},
},
},
},
},
Expected: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{},
Annotations: map[string]string{},
},
Spec: corev1.PodSpec{
NodeSelector: map[string]string{},
Tolerations: []corev1.Toleration{},
Containers: []corev1.Container{
{
Name: "redpanda",
StartupProbe: &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
Exec: &corev1.ExecAction{
Command: []string{"rpk cluster health"},
},
},
FailureThreshold: 120,
},
},
},
},
},
},
{
Name: "volumes",
Override: redpanda.PodTemplate{
Spec: &applycorev1.PodSpecApplyConfiguration{
Volumes: []applycorev1.VolumeApplyConfiguration{
{
Name: ptr.To("certs-volume-mount"),
VolumeSourceApplyConfiguration: applycorev1.VolumeSourceApplyConfiguration{
Secret: nil,
EmptyDir: &applycorev1.EmptyDirVolumeSourceApplyConfiguration{},
},
},
},
},
},
Original: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Volumes: []corev1.Volume{
{
Name: "certs-volume-mount",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: "some-secret",
},
},
},
},
},
},
Expected: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{},
Annotations: map[string]string{},
},
Spec: corev1.PodSpec{
NodeSelector: map[string]string{},
Tolerations: []corev1.Toleration{},
Volumes: []corev1.Volume{
{
Name: "certs-volume-mount",
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{},
},
},
},
},
},
},
}

for _, tc := range cases {
Expand Down
2 changes: 1 addition & 1 deletion charts/redpanda/templates/_helpers.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@
{{- range $_ := (list 1) -}}
{{- $_is_returning := false -}}
{{- $_is_returning = true -}}
{{- (dict "r" (merge (dict) $override $original)) | toJson -}}
{{- (dict "r" (merge (dict) $override)) | toJson -}}
{{- break -}}
{{- end -}}
{{- end -}}
Expand Down
56 changes: 56 additions & 0 deletions charts/redpanda/testdata/template-cases.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -1584,3 +1584,59 @@ statefulset:
enabled: false
pvcUnbinder:
enabled: false

-- jit-certificates --
# ASSERT-NO-ERROR
# ASSERT-FIELD-EQUALS ["apps/v1/StatefulSet", "default/redpanda", "{.spec.template.spec.volumes[?(@.name == \"redpanda-external-cert\")]}", {"name": "redpanda-external-cert", "emptyDir": {}}]
# This case demonstrates how to provide "Just In Time" certificates via an
# initContainer by using podTemplate to overwrite the auto generated volume.
tls:
certs:
external:
# Uncomment this block to disable the generation of cert-manager Certificates.
# secretRef:
# name: "set-to-disable-cert-manager"

# Controls whether or not the chart expects a ca.crt key to
# exist in the volume we create with the below init
# container. If set to false, the trustStore feature can
# continue to be used as is with the strategy.
caEnabled: true

statefulset:
podTemplate:
spec:
initContainers:
- name: cert-minter
image: debian:latest
command:
- bash
- -c
- 'cp -L -r /original/.'
# Provide the rest of your initContainer implementation here.
# This runs with the redpanda ServiceAccount.
volumeMounts:
# autoMountServiceAccountToken is set to false but we do mount it. To
# mount it to your init container, specify this volume:
- name: "kube-api-access"
readOnly: true
mountPath: "/var/run/secrets/kubernetes.io/serviceaccount"
# Mount the empty dir volume that will be used to pass certs through to redpanda.
- name: "redpanda-external-cert"
mountPath: "/certs"
# Unique to this example, we're just stealing the certs from the original.
- name: "3rd-party-certs"
mountPath: "/original"

volumes:
# Here's where the "magic" is. We're going to use podTemplate
# to override the standard certificate mount that the chart
# generates with an emptyDir. The initContainer will then
# populate it with a tls.crt, tls.key, and (optionally) ca.crt
# which makes it look like a standard TLS Secret mount.
- name: "redpanda-external-cert" # "{{ nameOverride }}-{{ cert }}-cert"
emptyDir: {}
# Unique to this example, we're just stealing the certs from the original.
- name: "3rd-party-certs"
secret:
secretName: "redpanda-external-cert"