Skip to content

Commit 7df59e3

Browse files
authored
Merge pull request #5678 from felix-kaestner/master
🐛 fix(helm/v2-alpha): correct indentation of conditional volume mounts
2 parents c753553 + 90501bd commit 7df59e3

5 files changed

Lines changed: 86 additions & 78 deletions

File tree

  • docs/book/src
    • cronjob-tutorial/testdata/project/dist/chart/templates/manager
    • multiversion-tutorial/testdata/project/dist/chart/templates/manager
  • pkg/plugins/optional/helm/v2alpha/scaffolds/internal/kustomize/templater/appliers
  • testdata/project-v4-with-plugins/dist/chart/templates/manager

docs/book/src/cronjob-tutorial/testdata/project/dist/chart/templates/manager/manager.yaml

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,16 @@ spec:
135135
{{- if .Values.manager.extraVolumeMounts }}
136136
{{- toYaml .Values.manager.extraVolumeMounts | nindent 10 }}
137137
{{- end }}
138-
{{- if and .Values.certManager.enable .Values.metrics.enable }}
139-
- mountPath: /tmp/k8s-metrics-server/metrics-certs
140-
name: metrics-certs
141-
readOnly: true
142-
{{- end }}
143-
{{- if .Values.certManager.enable }}
144-
- mountPath: /tmp/k8s-webhook-server/serving-certs
145-
name: webhook-certs
146-
readOnly: true
147-
{{- end }}
138+
{{- if and .Values.certManager.enable .Values.metrics.enable }}
139+
- mountPath: /tmp/k8s-metrics-server/metrics-certs
140+
name: metrics-certs
141+
readOnly: true
142+
{{- end }}
143+
{{- if .Values.certManager.enable }}
144+
- mountPath: /tmp/k8s-webhook-server/serving-certs
145+
name: webhook-certs
146+
readOnly: true
147+
{{- end }}
148148
securityContext:
149149
{{- if .Values.manager.podSecurityContext }}
150150
{{- toYaml .Values.manager.podSecurityContext | nindent 8 }}
@@ -159,22 +159,22 @@ spec:
159159
{{- if .Values.manager.extraVolumes }}
160160
{{- toYaml .Values.manager.extraVolumes | nindent 8 }}
161161
{{- end }}
162-
{{- if and .Values.certManager.enable .Values.metrics.enable }}
163-
- name: metrics-certs
164-
secret:
165-
items:
166-
- key: ca.crt
167-
path: ca.crt
168-
- key: tls.crt
169-
path: tls.crt
170-
- key: tls.key
171-
path: tls.key
172-
optional: false
173-
secretName: metrics-server-cert
174-
{{- end }}
175-
{{- if .Values.certManager.enable }}
176-
- name: webhook-certs
177-
secret:
178-
secretName: webhook-server-cert
179-
{{- end }}
162+
{{- if and .Values.certManager.enable .Values.metrics.enable }}
163+
- name: metrics-certs
164+
secret:
165+
items:
166+
- key: ca.crt
167+
path: ca.crt
168+
- key: tls.crt
169+
path: tls.crt
170+
- key: tls.key
171+
path: tls.key
172+
optional: false
173+
secretName: metrics-server-cert
174+
{{- end }}
175+
{{- if .Values.certManager.enable }}
176+
- name: webhook-certs
177+
secret:
178+
secretName: webhook-server-cert
179+
{{- end }}
180180
{{- end }}

docs/book/src/multiversion-tutorial/testdata/project/dist/chart/templates/manager/manager.yaml

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,16 @@ spec:
135135
{{- if .Values.manager.extraVolumeMounts }}
136136
{{- toYaml .Values.manager.extraVolumeMounts | nindent 10 }}
137137
{{- end }}
138-
{{- if and .Values.certManager.enable .Values.metrics.enable }}
139-
- mountPath: /tmp/k8s-metrics-server/metrics-certs
140-
name: metrics-certs
141-
readOnly: true
142-
{{- end }}
143-
{{- if .Values.certManager.enable }}
144-
- mountPath: /tmp/k8s-webhook-server/serving-certs
145-
name: webhook-certs
146-
readOnly: true
147-
{{- end }}
138+
{{- if and .Values.certManager.enable .Values.metrics.enable }}
139+
- mountPath: /tmp/k8s-metrics-server/metrics-certs
140+
name: metrics-certs
141+
readOnly: true
142+
{{- end }}
143+
{{- if .Values.certManager.enable }}
144+
- mountPath: /tmp/k8s-webhook-server/serving-certs
145+
name: webhook-certs
146+
readOnly: true
147+
{{- end }}
148148
securityContext:
149149
{{- if .Values.manager.podSecurityContext }}
150150
{{- toYaml .Values.manager.podSecurityContext | nindent 8 }}
@@ -159,22 +159,22 @@ spec:
159159
{{- if .Values.manager.extraVolumes }}
160160
{{- toYaml .Values.manager.extraVolumes | nindent 8 }}
161161
{{- end }}
162-
{{- if and .Values.certManager.enable .Values.metrics.enable }}
163-
- name: metrics-certs
164-
secret:
165-
items:
166-
- key: ca.crt
167-
path: ca.crt
168-
- key: tls.crt
169-
path: tls.crt
170-
- key: tls.key
171-
path: tls.key
172-
optional: false
173-
secretName: metrics-server-cert
174-
{{- end }}
175-
{{- if .Values.certManager.enable }}
176-
- name: webhook-certs
177-
secret:
178-
secretName: webhook-server-cert
179-
{{- end }}
162+
{{- if and .Values.certManager.enable .Values.metrics.enable }}
163+
- name: metrics-certs
164+
secret:
165+
items:
166+
- key: ca.crt
167+
path: ca.crt
168+
- key: tls.crt
169+
path: tls.crt
170+
- key: tls.key
171+
path: tls.key
172+
optional: false
173+
secretName: metrics-server-cert
174+
{{- end }}
175+
{{- if .Values.certManager.enable }}
176+
- name: webhook-certs
177+
secret:
178+
secretName: webhook-server-cert
179+
{{- end }}
180180
{{- end }}

pkg/plugins/optional/helm/v2alpha/scaffolds/internal/kustomize/templater/appliers/helpers.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ func IsManagerDeployment(resource *unstructured.Unstructured) bool {
5858

5959
// MakeYamlContent wraps YAML content with conditional cert-manager wrappers.
6060
// This function is used as a callback for regexp.ReplaceAllStringFunc.
61+
// It shifts the block by 2 additional spaces so that items align with the
62+
// child indent used by appendToListFromValues for extraVolumes/extraVolumeMounts.
6163
func MakeYamlContent(match string) string {
6264
lines := strings.Split(match, "\n")
6365
if len(lines) > 0 {
@@ -73,13 +75,15 @@ func MakeYamlContent(match string) string {
7375
}
7476
}
7577

76-
// Reconstruct the block with conditional wrapper
78+
childIndent := indent.String() + " "
79+
80+
// Reconstruct the block with conditional wrapper at child indent
7781
var result strings.Builder
78-
fmt.Fprintf(&result, "%s{{- if .Values.certManager.enable }}\n", indent.String())
82+
fmt.Fprintf(&result, "%s{{- if .Values.certManager.enable }}\n", childIndent)
7983
for _, line := range lines {
80-
result.WriteString(line + "\n")
84+
result.WriteString(" " + line + "\n")
8185
}
82-
fmt.Fprintf(&result, "%s{{- end }}", indent.String())
86+
fmt.Fprintf(&result, "%s{{- end }}", childIndent)
8387
return result.String()
8488
}
8589
return match

pkg/plugins/optional/helm/v2alpha/scaffolds/internal/kustomize/templater/appliers/manager.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,13 +1452,15 @@ func MakeMetricsVolumesConditional(yamlContent string) string {
14521452
}
14531453
}
14541454

1455-
// Reconstruct the block with conditional wrapper
1455+
childIndent := indent.String() + " "
1456+
1457+
// Reconstruct the block with conditional wrapper at child indent
14561458
var result strings.Builder
1457-
fmt.Fprintf(&result, "%s{{- if and .Values.certManager.enable .Values.metrics.enable }}\n", indent.String())
1459+
fmt.Fprintf(&result, "%s{{- if and .Values.certManager.enable .Values.metrics.enable }}\n", childIndent)
14581460
for _, line := range lines {
1459-
result.WriteString(line + "\n")
1461+
result.WriteString(" " + line + "\n")
14601462
}
1461-
fmt.Fprintf(&result, "%s{{- end }}", indent.String())
1463+
fmt.Fprintf(&result, "%s{{- end }}", childIndent)
14621464
return result.String()
14631465
}
14641466
return match
@@ -1491,13 +1493,15 @@ func MakeMetricsVolumeMountsConditional(yamlContent string) string {
14911493
}
14921494
}
14931495

1494-
// Reconstruct the block with conditional wrapper
1496+
childIndent := indent.String() + " "
1497+
1498+
// Reconstruct the block with conditional wrapper at child indent
14951499
var result strings.Builder
1496-
fmt.Fprintf(&result, "%s{{- if and .Values.certManager.enable .Values.metrics.enable }}\n", indent.String())
1500+
fmt.Fprintf(&result, "%s{{- if and .Values.certManager.enable .Values.metrics.enable }}\n", childIndent)
14971501
for _, line := range lines {
1498-
result.WriteString(line + "\n")
1502+
result.WriteString(" " + line + "\n")
14991503
}
1500-
fmt.Fprintf(&result, "%s{{- end }}", indent.String())
1504+
fmt.Fprintf(&result, "%s{{- end }}", childIndent)
15011505
return result.String()
15021506
}
15031507
return match

testdata/project-v4-with-plugins/dist/chart/templates/manager/manager.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ spec:
146146
{{- if .Values.manager.extraVolumeMounts }}
147147
{{- toYaml .Values.manager.extraVolumeMounts | nindent 10 }}
148148
{{- end }}
149-
{{- if .Values.certManager.enable }}
150-
- mountPath: /tmp/k8s-webhook-server/serving-certs
151-
name: webhook-certs
152-
readOnly: true
153-
{{- end }}
149+
{{- if .Values.certManager.enable }}
150+
- mountPath: /tmp/k8s-webhook-server/serving-certs
151+
name: webhook-certs
152+
readOnly: true
153+
{{- end }}
154154
securityContext:
155155
{{- if .Values.manager.podSecurityContext }}
156156
{{- toYaml .Values.manager.podSecurityContext | nindent 8 }}
@@ -165,9 +165,9 @@ spec:
165165
{{- if .Values.manager.extraVolumes }}
166166
{{- toYaml .Values.manager.extraVolumes | nindent 8 }}
167167
{{- end }}
168-
{{- if .Values.certManager.enable }}
169-
- name: webhook-certs
170-
secret:
171-
secretName: webhook-server-cert
172-
{{- end }}
168+
{{- if .Values.certManager.enable }}
169+
- name: webhook-certs
170+
secret:
171+
secretName: webhook-server-cert
172+
{{- end }}
173173
{{- end }}

0 commit comments

Comments
 (0)