From 48482dbe0eeb26e627aa4d19632c95204221deb7 Mon Sep 17 00:00:00 2001 From: Cezary Stanislawski Date: Sun, 4 Oct 2026 19:55:17 +0200 Subject: [PATCH] fix(helm): align listener ports and metrics monitor protocol --- .../templates/_helpers.tpl | 22 +++++++++++++++++++ .../templates/deployment.yaml | 4 ++-- .../templates/servicemonitor.yaml | 4 ++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/charts/lifecycle-controller/templates/_helpers.tpl b/charts/lifecycle-controller/templates/_helpers.tpl index 6ee1c2c..d516491 100644 --- a/charts/lifecycle-controller/templates/_helpers.tpl +++ b/charts/lifecycle-controller/templates/_helpers.tpl @@ -61,3 +61,25 @@ Create the name of the service account to use {{- default "default" .Values.serviceAccount.name }} {{- end }} {{- end }} + +{{/* +Extract a numeric container port from a listener address. +*/}} +{{- define "lifecycle-controller.bindPort" -}} +{{- if not (kindIs "string" .address) -}} +{{- fail (printf "%s must be a string" .key) -}} +{{- end -}} +{{- if not (regexMatch `^(\[[^\[\][:space:]]+\]|[^:\[\][:space:]]*):[0-9]+$` .address) -}} +{{- fail (printf "%s must use :port, host:port, or [IPv6]:port with a numeric port" .key) -}} +{{- end -}} +{{- $digits := regexFind `[0-9]+$` .address -}} +{{- $digits = regexReplaceAll `^0+` $digits "" -}} +{{- if gt (len $digits) 5 -}} +{{- fail (printf "%s port must be between 1 and 65535" .key) -}} +{{- end -}} +{{- $port := int $digits -}} +{{- if or (lt $port 1) (gt $port 65535) -}} +{{- fail (printf "%s port must be between 1 and 65535" .key) -}} +{{- end -}} +{{- $port -}} +{{- end -}} diff --git a/charts/lifecycle-controller/templates/deployment.yaml b/charts/lifecycle-controller/templates/deployment.yaml index 381ec29..3065cb5 100644 --- a/charts/lifecycle-controller/templates/deployment.yaml +++ b/charts/lifecycle-controller/templates/deployment.yaml @@ -67,11 +67,11 @@ spec: - --ignore-namespace={{ . }} {{- end }} ports: - - containerPort: 8081 + - containerPort: {{ include "lifecycle-controller.bindPort" (dict "address" .Values.controllerManager.healthProbeBindAddress "key" "controllerManager.healthProbeBindAddress") }} name: healthz protocol: TCP {{- if .Values.metrics.enabled }} - - containerPort: {{ trimPrefix ":" .Values.metrics.bindAddress }} + - containerPort: {{ include "lifecycle-controller.bindPort" (dict "address" .Values.metrics.bindAddress "key" "metrics.bindAddress") }} name: metrics protocol: TCP {{- end }} diff --git a/charts/lifecycle-controller/templates/servicemonitor.yaml b/charts/lifecycle-controller/templates/servicemonitor.yaml index 320a58d..b89d36a 100644 --- a/charts/lifecycle-controller/templates/servicemonitor.yaml +++ b/charts/lifecycle-controller/templates/servicemonitor.yaml @@ -13,10 +13,14 @@ spec: endpoints: - path: /metrics port: https + {{- if .Values.metrics.secure }} scheme: https bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token tlsConfig: insecureSkipVerify: {{ .Values.metrics.serviceMonitor.insecureSkipVerify }} + {{- else }} + scheme: http + {{- end }} namespaceSelector: matchNames: - {{ .Release.Namespace }}