Skip to content

Commit 2532ad1

Browse files
(helm/v1-alpha): Fix helm-chart scaffold by not scaffolding manifests with webhook conditions when webhooks are not used
1 parent 8c817f5 commit 2532ad1

File tree

5 files changed

+17
-28
lines changed

5 files changed

+17
-28
lines changed

docs/book/src/getting-started/testdata/project/dist/chart/templates/certmanager/certificate.yaml

-24
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,6 @@ metadata:
99
namespace: {{ .Release.Namespace }}
1010
spec:
1111
selfSigned: {}
12-
{{- if .Values.webhook.enable }}
13-
---
14-
# Certificate for the webhook
15-
apiVersion: cert-manager.io/v1
16-
kind: Certificate
17-
metadata:
18-
annotations:
19-
{{- if .Values.crd.keep }}
20-
"helm.sh/resource-policy": keep
21-
{{- end }}
22-
name: serving-cert
23-
namespace: {{ .Release.Namespace }}
24-
labels:
25-
{{- include "chart.labels" . | nindent 4 }}
26-
spec:
27-
dnsNames:
28-
- project.{{ .Release.Namespace }}.svc
29-
- project.{{ .Release.Namespace }}.svc.cluster.local
30-
- project-webhook-service.{{ .Release.Namespace }}.svc
31-
issuerRef:
32-
kind: Issuer
33-
name: selfsigned-issuer
34-
secretName: webhook-server-cert
35-
{{- end }}
3612
{{- if .Values.metrics.enable }}
3713
---
3814
# Certificate for the metrics

docs/book/src/getting-started/testdata/project/dist/chart/templates/manager/manager.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ spec:
4949
{{- toYaml .Values.controllerManager.container.resources | nindent 12 }}
5050
securityContext:
5151
{{- toYaml .Values.controllerManager.container.securityContext | nindent 12 }}
52-
{{- if and .Values.certmanager.enable (or .Values.webhook.enable .Values.metrics.enable) }}
52+
{{- if and .Values.certmanager.enable .Values.metrics.enable }}
5353
volumeMounts:
5454
{{- if and .Values.metrics.enable .Values.certmanager.enable }}
5555
- name: metrics-certs
@@ -61,7 +61,7 @@ spec:
6161
{{- toYaml .Values.controllerManager.securityContext | nindent 8 }}
6262
serviceAccountName: {{ .Values.controllerManager.serviceAccountName }}
6363
terminationGracePeriodSeconds: {{ .Values.controllerManager.terminationGracePeriodSeconds }}
64-
{{- if and .Values.certmanager.enable (or .Values.webhook.enable .Values.metrics.enable) }}
64+
{{- if and .Values.certmanager.enable .Values.metrics.enable }}
6565
volumes:
6666
{{- if and .Values.metrics.enable .Values.certmanager.enable }}
6767
- name: metrics-certs

pkg/plugins/optional/helm/v1alpha/scaffolds/init.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ func (s *initScaffolder) Scaffold() error {
9696
DeployImages: len(imagesEnvVars) > 0,
9797
HasWebhooks: hasWebhooks,
9898
},
99-
&templatescertmanager.Certificate{},
99+
&templatescertmanager.Certificate{HasWebhooks: hasWebhooks},
100100
&templatesmetrics.Service{},
101101
&prometheus.Monitor{},
102102
}
103103

104-
if len(mutatingWebhooks) > 0 || len(validatingWebhooks) > 0 {
104+
if hasWebhooks && (len(mutatingWebhooks) > 0 || len(validatingWebhooks) > 0) {
105105
buildScaffold = append(buildScaffold,
106106
&templateswebhooks.Template{
107107
MutatingWebhooks: mutatingWebhooks,

pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates/chart-templates/cert-manager/certificate.go

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ var _ machinery.Template = &Certificate{}
2727
type Certificate struct {
2828
machinery.TemplateMixin
2929
machinery.ProjectNameMixin
30+
31+
// HasWebhooks is true when webhooks were found in the config
32+
HasWebhooks bool
3033
}
3134

3235
// SetTemplateDefaults sets the default template configuration
@@ -53,6 +56,7 @@ metadata:
5356
namespace: {{ "{{ .Release.Namespace }}" }}
5457
spec:
5558
selfSigned: {}
59+
{{- if .HasWebhooks }}
5660
{{ "{{- if .Values.webhook.enable }}" }}
5761
---
5862
# Certificate for the webhook
@@ -77,6 +81,7 @@ spec:
7781
name: selfsigned-issuer
7882
secretName: webhook-server-cert
7983
{{` + "`" + `{{- end }}` + "`" + `}}
84+
{{- end }}
8085
{{ "{{- if .Values.metrics.enable }}" }}
8186
---
8287
# Certificate for the metrics

pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates/chart-templates/manager/manager.go

+8
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ spec:
114114
{{ "{{- toYaml .Values.controllerManager.container.resources | nindent 12 }}" }}
115115
securityContext:
116116
{{ "{{- toYaml .Values.controllerManager.container.securityContext | nindent 12 }}" }}
117+
{{- if .HasWebhooks }}
117118
{{ "{{- if and .Values.certmanager.enable (or .Values.webhook.enable .Values.metrics.enable) }}" }}
119+
{{- else }}
120+
{{ "{{- if and .Values.certmanager.enable .Values.metrics.enable }}" }}
121+
{{- end }}
118122
volumeMounts:
119123
{{- if .HasWebhooks }}
120124
{{ "{{- if and .Values.webhook.enable .Values.certmanager.enable }}" }}
@@ -133,7 +137,11 @@ spec:
133137
{{ "{{- toYaml .Values.controllerManager.securityContext | nindent 8 }}" }}
134138
serviceAccountName: {{ "{{ .Values.controllerManager.serviceAccountName }}" }}
135139
terminationGracePeriodSeconds: {{ "{{ .Values.controllerManager.terminationGracePeriodSeconds }}" }}
140+
{{- if .HasWebhooks }}
136141
{{ "{{- if and .Values.certmanager.enable (or .Values.webhook.enable .Values.metrics.enable) }}" }}
142+
{{- else }}
143+
{{ "{{- if and .Values.certmanager.enable .Values.metrics.enable }}" }}
144+
{{- end }}
137145
volumes:
138146
{{- if .HasWebhooks }}
139147
{{ "{{- if and .Values.webhook.enable .Values.certmanager.enable }}" }}

0 commit comments

Comments
 (0)