Skip to content

✨ Make webhook and metrics ports configurable in Helm chart template #4890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions docs/book/src/cronjob-tutorial/testdata/project/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func main() {
var metricsAddr string
var metricsCertPath, metricsCertName, metricsCertKey string
var webhookCertPath, webhookCertName, webhookCertKey string
var webhookPort int
var enableLeaderElection bool
var probeAddr string
var secureMetrics bool
Expand All @@ -95,6 +96,7 @@ func main() {
flag.StringVar(&webhookCertPath, "webhook-cert-path", "", "The directory that contains the webhook certificate.")
flag.StringVar(&webhookCertName, "webhook-cert-name", "tls.crt", "The name of the webhook certificate file.")
flag.StringVar(&webhookCertKey, "webhook-cert-key", "tls.key", "The name of the webhook key file.")
flag.IntVar(&webhookPort, "webhook-port", 9443, "The port that the webhook endpoint binds to.")
flag.StringVar(&metricsCertPath, "metrics-cert-path", "",
"The directory that contains the metrics server certificate.")
flag.StringVar(&metricsCertName, "metrics-cert-name", "tls.crt", "The name of the metrics server certificate file.")
Expand Down Expand Up @@ -151,6 +153,7 @@ func main() {

webhookServer := webhook.NewServer(webhook.Options{
TLSOpts: webhookTLSOpts,
Port: webhookPort,
})

// Metrics endpoint is enabled in 'config/default/kustomization.yaml'. The Metrics options configure the server.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ spec:
{{- toYaml .Values.controllerManager.container.readinessProbe | nindent 12 }}
{{- if .Values.webhook.enable }}
ports:
- containerPort: 9443
- containerPort: {{ .Values.webhook.port }}
name: webhook-server
protocol: TCP
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ metadata:
control-plane: controller-manager
spec:
ports:
- port: 8443
targetPort: 8443
- port: {{ .Values.metrics.port }}
targetPort: {{ .Values.metrics.port }}
protocol: TCP
name: https
selector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spec:
ports:
- port: 443
protocol: TCP
targetPort: 9443
targetPort: {{ .Values.webhook.port }}
selector:
control-plane: controller-manager
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ controllerManager:
tag: latest
args:
- "--leader-elect"
- "--metrics-bind-address=:8443"
- "--metrics-bind-address=:{{ .Values.metrics.port }}"
- "--health-probe-bind-address=:8081"
- "--webhook-port={{ .Values.webhook.port }}"
resources:
limits:
cpu: 500m
Expand Down Expand Up @@ -62,13 +63,15 @@ crd:
# ControllerManager argument "--metrics-bind-address=:8443" is removed.
metrics:
enable: true
port: 8443

# [WEBHOOKS]: Webhooks configuration
# The following configuration is automatically generated from the manifests
# generated by controller-gen. To update run 'make manifests' and
# the edit command with the '--force' flag
webhook:
enable: true
port: 9443

# [PROMETHEUS]: To enable a ServiceMonitor to export metrics to Prometheus set true
prometheus:
Expand Down
3 changes: 3 additions & 0 deletions docs/book/src/getting-started/testdata/project/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func main() {
var metricsAddr string
var metricsCertPath, metricsCertName, metricsCertKey string
var webhookCertPath, webhookCertName, webhookCertKey string
var webhookPort int
var enableLeaderElection bool
var probeAddr string
var secureMetrics bool
Expand All @@ -75,6 +76,7 @@ func main() {
flag.StringVar(&webhookCertPath, "webhook-cert-path", "", "The directory that contains the webhook certificate.")
flag.StringVar(&webhookCertName, "webhook-cert-name", "tls.crt", "The name of the webhook certificate file.")
flag.StringVar(&webhookCertKey, "webhook-cert-key", "tls.key", "The name of the webhook key file.")
flag.IntVar(&webhookPort, "webhook-port", 9443, "The port that the webhook endpoint binds to.")
flag.StringVar(&metricsCertPath, "metrics-cert-path", "",
"The directory that contains the metrics server certificate.")
flag.StringVar(&metricsCertName, "metrics-cert-name", "tls.crt", "The name of the metrics server certificate file.")
Expand Down Expand Up @@ -131,6 +133,7 @@ func main() {

webhookServer := webhook.NewServer(webhook.Options{
TLSOpts: webhookTLSOpts,
Port: webhookPort,
})

// Metrics endpoint is enabled in 'config/default/kustomization.yaml'. The Metrics options configure the server.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ metadata:
control-plane: controller-manager
spec:
ports:
- port: 8443
targetPort: 8443
- port: {{ .Values.metrics.port }}
targetPort: {{ .Values.metrics.port }}
protocol: TCP
name: https
selector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ controllerManager:
tag: latest
args:
- "--leader-elect"
- "--metrics-bind-address=:8443"
- "--metrics-bind-address=:{{ .Values.metrics.port }}"
- "--health-probe-bind-address=:8081"
resources:
limits:
Expand Down Expand Up @@ -62,6 +62,7 @@ crd:
# ControllerManager argument "--metrics-bind-address=:8443" is removed.
metrics:
enable: true
port: 8443

# [PROMETHEUS]: To enable a ServiceMonitor to export metrics to Prometheus set true
prometheus:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func main() {
var metricsAddr string
var metricsCertPath, metricsCertName, metricsCertKey string
var webhookCertPath, webhookCertName, webhookCertKey string
var webhookPort int
var enableLeaderElection bool
var probeAddr string
var secureMetrics bool
Expand All @@ -94,6 +95,7 @@ func main() {
flag.StringVar(&webhookCertPath, "webhook-cert-path", "", "The directory that contains the webhook certificate.")
flag.StringVar(&webhookCertName, "webhook-cert-name", "tls.crt", "The name of the webhook certificate file.")
flag.StringVar(&webhookCertKey, "webhook-cert-key", "tls.key", "The name of the webhook key file.")
flag.IntVar(&webhookPort, "webhook-port", 9443, "The port that the webhook endpoint binds to.")
flag.StringVar(&metricsCertPath, "metrics-cert-path", "",
"The directory that contains the metrics server certificate.")
flag.StringVar(&metricsCertName, "metrics-cert-name", "tls.crt", "The name of the metrics server certificate file.")
Expand Down Expand Up @@ -150,6 +152,7 @@ func main() {

webhookServer := webhook.NewServer(webhook.Options{
TLSOpts: webhookTLSOpts,
Port: webhookPort,
})

// Metrics endpoint is enabled in 'config/default/kustomization.yaml'. The Metrics options configure the server.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ spec:
{{- toYaml .Values.controllerManager.container.readinessProbe | nindent 12 }}
{{- if .Values.webhook.enable }}
ports:
- containerPort: 9443
- containerPort: {{ .Values.webhook.port }}
name: webhook-server
protocol: TCP
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ metadata:
control-plane: controller-manager
spec:
ports:
- port: 8443
targetPort: 8443
- port: {{ .Values.metrics.port }}
targetPort: {{ .Values.metrics.port }}
protocol: TCP
name: https
selector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spec:
ports:
- port: 443
protocol: TCP
targetPort: 9443
targetPort: {{ .Values.webhook.port }}
selector:
control-plane: controller-manager
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ controllerManager:
tag: latest
args:
- "--leader-elect"
- "--metrics-bind-address=:8443"
- "--metrics-bind-address=:{{ .Values.metrics.port }}"
- "--health-probe-bind-address=:8081"
- "--webhook-port={{ .Values.webhook.port }}"
resources:
limits:
cpu: 500m
Expand Down Expand Up @@ -62,13 +63,15 @@ crd:
# ControllerManager argument "--metrics-bind-address=:8443" is removed.
metrics:
enable: true
port: 8443

# [WEBHOOKS]: Webhooks configuration
# The following configuration is automatically generated from the manifests
# generated by controller-gen. To update run 'make manifests' and
# the edit command with the '--force' flag
webhook:
enable: true
port: 9443

# [PROMETHEUS]: To enable a ServiceMonitor to export metrics to Prometheus set true
prometheus:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ func main() {
var metricsAddr string
var metricsCertPath, metricsCertName, metricsCertKey string
var webhookCertPath, webhookCertName, webhookCertKey string
var webhookPort int
var enableLeaderElection bool
var probeAddr string
var secureMetrics bool
Expand All @@ -283,6 +284,7 @@ func main() {
flag.StringVar(&webhookCertPath, "webhook-cert-path", "", "The directory that contains the webhook certificate.")
flag.StringVar(&webhookCertName, "webhook-cert-name", "tls.crt", "The name of the webhook certificate file.")
flag.StringVar(&webhookCertKey, "webhook-cert-key", "tls.key", "The name of the webhook key file.")
flag.IntVar(&webhookPort, "webhook-port", 9443, "The port that the webhook endpoint binds to.")
flag.StringVar(&metricsCertPath, "metrics-cert-path", "",
"The directory that contains the metrics server certificate.")
flag.StringVar(&metricsCertName, "metrics-cert-name", "tls.crt", "The name of the metrics server certificate file.")
Expand Down Expand Up @@ -339,6 +341,7 @@ func main() {

webhookServer := webhook.NewServer(webhook.Options{
TLSOpts: webhookTLSOpts,
Port: webhookPort,
})

// Metrics endpoint is enabled in 'config/default/kustomization.yaml'. The Metrics options configure the server.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ spec:
{{- if .HasWebhooks }}
{{ "{{- if .Values.webhook.enable }}" }}
ports:
- containerPort: 9443
- containerPort: {{ "{{ .Values.webhook.port }}" }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ports as fixed for golang in the scaffold.
We cannot change the port only for helm
That will not work if you add other port.
Also, see: #4802

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, ah... I see, Understood.
I'll think about it for a moment 🙇

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I finally understand how KubeBuilder's scaffold works.
I believe it's now configurable with this diff.

Could you please review it again? Thank you

name: webhook-server
protocol: TCP
{{ "{{- end }}" }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ metadata:
control-plane: controller-manager
spec:
ports:
- port: 8443
targetPort: 8443
- port: {{ "{{ .Values.metrics.port }}" }}
targetPort: {{ "{{ .Values.metrics.port }}" }}
protocol: TCP
name: https
selector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ spec:
ports:
- port: 443
protocol: TCP
targetPort: 9443
targetPort: {{ "{{ .Values.webhook.port }}" }}
selector:
control-plane: controller-manager
{{` + "`" + `{{- end }}` + "`" + `}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ controllerManager:
tag: latest
args:
- "--leader-elect"
- "--metrics-bind-address=:8443"
- "--health-probe-bind-address=:8081"
- "--metrics-bind-address=:{{ "{{" }} .Values.metrics.port {{ "}}" }}"
- "--health-probe-bind-address=:8081"{{ if .HasWebhooks }}
- "--webhook-port={{ "{{" }} .Values.webhook.port {{ "}}" }}"{{ end }}
resources:
limits:
cpu: 500m
Expand Down Expand Up @@ -122,13 +123,15 @@ crd:
# ControllerManager argument "--metrics-bind-address=:8443" is removed.
metrics:
enable: true
port: 8443
{{ if .HasWebhooks }}
# [WEBHOOKS]: Webhooks configuration
# The following configuration is automatically generated from the manifests
# generated by controller-gen. To update run 'make manifests' and
# the edit command with the '--force' flag
webhook:
enable: true
port: 9443
{{ end }}
# [PROMETHEUS]: To enable a ServiceMonitor to export metrics to Prometheus set true
prometheus:
Expand Down
3 changes: 3 additions & 0 deletions testdata/project-v4-multigroup/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func main() {
var metricsAddr string
var metricsCertPath, metricsCertName, metricsCertKey string
var webhookCertPath, webhookCertName, webhookCertKey string
var webhookPort int
var enableLeaderElection bool
var probeAddr string
var secureMetrics bool
Expand All @@ -116,6 +117,7 @@ func main() {
flag.StringVar(&webhookCertPath, "webhook-cert-path", "", "The directory that contains the webhook certificate.")
flag.StringVar(&webhookCertName, "webhook-cert-name", "tls.crt", "The name of the webhook certificate file.")
flag.StringVar(&webhookCertKey, "webhook-cert-key", "tls.key", "The name of the webhook key file.")
flag.IntVar(&webhookPort, "webhook-port", 9443, "The port that the webhook endpoint binds to.")
flag.StringVar(&metricsCertPath, "metrics-cert-path", "",
"The directory that contains the metrics server certificate.")
flag.StringVar(&metricsCertName, "metrics-cert-name", "tls.crt", "The name of the metrics server certificate file.")
Expand Down Expand Up @@ -172,6 +174,7 @@ func main() {

webhookServer := webhook.NewServer(webhook.Options{
TLSOpts: webhookTLSOpts,
Port: webhookPort,
})

// Metrics endpoint is enabled in 'config/default/kustomization.yaml'. The Metrics options configure the server.
Expand Down
3 changes: 3 additions & 0 deletions testdata/project-v4-with-plugins/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func main() {
var metricsAddr string
var metricsCertPath, metricsCertName, metricsCertKey string
var webhookCertPath, webhookCertName, webhookCertKey string
var webhookPort int
var enableLeaderElection bool
var probeAddr string
var secureMetrics bool
Expand All @@ -81,6 +82,7 @@ func main() {
flag.StringVar(&webhookCertPath, "webhook-cert-path", "", "The directory that contains the webhook certificate.")
flag.StringVar(&webhookCertName, "webhook-cert-name", "tls.crt", "The name of the webhook certificate file.")
flag.StringVar(&webhookCertKey, "webhook-cert-key", "tls.key", "The name of the webhook key file.")
flag.IntVar(&webhookPort, "webhook-port", 9443, "The port that the webhook endpoint binds to.")
flag.StringVar(&metricsCertPath, "metrics-cert-path", "",
"The directory that contains the metrics server certificate.")
flag.StringVar(&metricsCertName, "metrics-cert-name", "tls.crt", "The name of the metrics server certificate file.")
Expand Down Expand Up @@ -137,6 +139,7 @@ func main() {

webhookServer := webhook.NewServer(webhook.Options{
TLSOpts: webhookTLSOpts,
Port: webhookPort,
})

// Metrics endpoint is enabled in 'config/default/kustomization.yaml'. The Metrics options configure the server.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ spec:
{{- toYaml .Values.controllerManager.container.readinessProbe | nindent 12 }}
{{- if .Values.webhook.enable }}
ports:
- containerPort: 9443
- containerPort: {{ .Values.webhook.port }}
name: webhook-server
protocol: TCP
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ metadata:
control-plane: controller-manager
spec:
ports:
- port: 8443
targetPort: 8443
- port: {{ .Values.metrics.port }}
targetPort: {{ .Values.metrics.port }}
protocol: TCP
name: https
selector:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spec:
ports:
- port: 443
protocol: TCP
targetPort: 9443
targetPort: {{ .Values.webhook.port }}
selector:
control-plane: controller-manager
{{- end }}
5 changes: 4 additions & 1 deletion testdata/project-v4-with-plugins/dist/chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ controllerManager:
tag: latest
args:
- "--leader-elect"
- "--metrics-bind-address=:8443"
- "--metrics-bind-address=:{{ .Values.metrics.port }}"
- "--health-probe-bind-address=:8081"
- "--webhook-port={{ .Values.webhook.port }}"
resources:
limits:
cpu: 500m
Expand Down Expand Up @@ -65,13 +66,15 @@ crd:
# ControllerManager argument "--metrics-bind-address=:8443" is removed.
metrics:
enable: true
port: 8443

# [WEBHOOKS]: Webhooks configuration
# The following configuration is automatically generated from the manifests
# generated by controller-gen. To update run 'make manifests' and
# the edit command with the '--force' flag
webhook:
enable: true
port: 9443

# [PROMETHEUS]: To enable a ServiceMonitor to export metrics to Prometheus set true
prometheus:
Expand Down
Loading