Skip to content

Commit 2f27c36

Browse files
committed
fix(helm): make webhook and metrics ports configurable in Helm chart templates
1 parent f292f90 commit 2f27c36

File tree

5 files changed

+11
-5
lines changed

5 files changed

+11
-5
lines changed

pkg/plugins/golang/v4/scaffolds/internal/templates/cmd/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ func main() {
267267
var metricsAddr string
268268
var metricsCertPath, metricsCertName, metricsCertKey string
269269
var webhookCertPath, webhookCertName, webhookCertKey string
270+
var webhookPort int
270271
var enableLeaderElection bool
271272
var probeAddr string
272273
var secureMetrics bool
@@ -283,6 +284,7 @@ func main() {
283284
flag.StringVar(&webhookCertPath, "webhook-cert-path", "", "The directory that contains the webhook certificate.")
284285
flag.StringVar(&webhookCertName, "webhook-cert-name", "tls.crt", "The name of the webhook certificate file.")
285286
flag.StringVar(&webhookCertKey, "webhook-cert-key", "tls.key", "The name of the webhook key file.")
287+
flag.IntVar(&webhookPort, "webhook-port", 9443, "The port that the webhook endpoint binds to.")
286288
flag.StringVar(&metricsCertPath, "metrics-cert-path", "",
287289
"The directory that contains the metrics server certificate.")
288290
flag.StringVar(&metricsCertName, "metrics-cert-name", "tls.crt", "The name of the metrics server certificate file.")
@@ -339,6 +341,7 @@ func main() {
339341
340342
webhookServer := webhook.NewServer(webhook.Options{
341343
TLSOpts: webhookTLSOpts,
344+
Port: webhookPort,
342345
})
343346
344347
// Metrics endpoint is enabled in 'config/default/kustomization.yaml'. The Metrics options configure the server.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ spec:
105105
{{- if .HasWebhooks }}
106106
{{ "{{- if .Values.webhook.enable }}" }}
107107
ports:
108-
- containerPort: 9443
108+
- containerPort: {{ "{{ .Values.webhook.port }}" }}
109109
name: webhook-server
110110
protocol: TCP
111111
{{ "{{- end }}" }}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ metadata:
5353
control-plane: controller-manager
5454
spec:
5555
ports:
56-
- port: 8443
57-
targetPort: 8443
56+
- port: {{ "{{ .Values.metrics.port }}" }}
57+
targetPort: {{ "{{ .Values.metrics.port }}" }}
5858
protocol: TCP
5959
name: https
6060
selector:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ spec:
5757
ports:
5858
- port: 443
5959
protocol: TCP
60-
targetPort: 9443
60+
targetPort: {{ "{{ .Values.webhook.port }}" }}
6161
selector:
6262
control-plane: controller-manager
6363
{{` + "`" + `{{- end }}` + "`" + `}}

pkg/plugins/optional/helm/v1alpha/scaffolds/internal/templates/values.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ controllerManager:
6161
tag: latest
6262
args:
6363
- "--leader-elect"
64-
- "--metrics-bind-address=:8443"
64+
- "--metrics-bind-address=:{{ "{{" }} .Values.metrics.port {{ "}}" }}"
6565
- "--health-probe-bind-address=:8081"
66+
- "--webhook-port={{ "{{" }} .Values.webhook.port {{ "}}" }}"
6667
resources:
6768
limits:
6869
cpu: 500m
@@ -122,13 +123,15 @@ crd:
122123
# ControllerManager argument "--metrics-bind-address=:8443" is removed.
123124
metrics:
124125
enable: true
126+
port: 8443
125127
{{ if .HasWebhooks }}
126128
# [WEBHOOKS]: Webhooks configuration
127129
# The following configuration is automatically generated from the manifests
128130
# generated by controller-gen. To update run 'make manifests' and
129131
# the edit command with the '--force' flag
130132
webhook:
131133
enable: true
134+
port: 9443
132135
{{ end }}
133136
# [PROMETHEUS]: To enable a ServiceMonitor to export metrics to Prometheus set true
134137
prometheus:

0 commit comments

Comments
 (0)