Skip to content

Commit 644a660

Browse files
committed
fix(chart): use the configured Pod metrics port
1 parent e158b24 commit 644a660

2 files changed

Lines changed: 56 additions & 5 deletions

File tree

‎charts/kafka-operator/templates/operator-deployment-with-webhook.yaml‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{- $metricsPort := (.Values.metricEndpoint).port | default 8080 }}
12
{{- $tlsCrt := "" }}
23
{{- $tlsKey := "" }}
34
{{- $caCrt := "" }}
@@ -157,7 +158,7 @@ spec:
157158
imagePullPolicy: {{ .Values.prometheusMetrics.authProxy.image.pullPolicy }}
158159
args:
159160
- "--secure-listen-address=0.0.0.0:8443"
160-
- "--upstream=http://127.0.0.1:8080/"
161+
- "--upstream=http://127.0.0.1:{{ $metricsPort }}/"
161162
- "--v=10"
162163
ports:
163164
- containerPort: 8443
@@ -192,9 +193,7 @@ spec:
192193
{{- if .Values.operator.developmentLogging }}
193194
- --development
194195
{{- end }}
195-
{{- if (.Values.metricEndpoint).port }}
196-
- --metrics-addr=":{{ .Values.metricEndpoint.port }}"
197-
{{- end }}
196+
- --metrics-addr=:{{ $metricsPort }}
198197
{{- if .Values.healthProbes.port }}
199198
- --health-probes-addr=:{{ .Values.healthProbes.port }}
200199
{{- end }}
@@ -230,7 +229,7 @@ spec:
230229
name: webhook-server
231230
protocol: TCP
232231
{{- end}}
233-
- containerPort: {{ (.Values.metricEndpoint).port | default 8080 }}
232+
- containerPort: {{ $metricsPort }}
234233
name: metrics
235234
protocol: TCP
236235
- containerPort: {{ .Values.alertManager.port }}

‎scripts/test-chart-metrics-port.sh‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2026 Adobe. All rights reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# Run from the repository root with Helm and yq v4 on PATH.
17+
set -euo pipefail
18+
19+
expect() {
20+
local expected=$1 query=$2 actual
21+
actual=$(yq eval-all "$query" - <<< "$rendered")
22+
if [[ "$actual" != "$expected" ]]; then
23+
printf 'proxy=%s port=%s: %s\nexpected %s, got %s\n' "$proxy" "$port" "$query" "$expected" "$actual" >&2
24+
exit 1
25+
fi
26+
}
27+
28+
containers='select(.kind == "Deployment") | .spec.template.spec.containers[]'
29+
manager="$containers | select(.name == \"manager\")"
30+
monitor='select(.kind == "PodMonitor") | .spec.podMetricsEndpoints[0]'
31+
raw_service='select(.kind == "Service" and .metadata.name == "kafka-operator-operator")'
32+
33+
for proxy in true false; do
34+
for port in 9090 8080; do
35+
args=(--set prometheusMetrics.podMonitor.enabled=true --set prometheusMetrics.authProxy.enabled="$proxy")
36+
if [[ "$port" != 8080 ]]; then args+=(--set metricEndpoint.port="$port"); fi
37+
rendered=$(helm template kafka-operator charts/kafka-operator "${args[@]}" "$@")
38+
39+
expect "--metrics-addr=:$port" "$manager | .args[] | select(. == \"--metrics-addr=*\")"
40+
expect "$port" "$manager | .ports[] | select(.name == \"metrics\") | .containerPort"
41+
expect metrics "$monitor | .port"
42+
expect http "$monitor | .scheme // \"http\""
43+
if [[ "$proxy" == true ]]; then
44+
expect "--upstream=http://127.0.0.1:$port/" "$containers | select(.name == \"kube-rbac-proxy\") | .args[] | select(. == \"--upstream=*\")"
45+
else
46+
expect 8080 "$raw_service | .metadata.annotations[\"prometheus.io/port\"]"
47+
expect 8080 "$raw_service | .spec.ports[] | select(.targetPort == \"metrics\") | .port"
48+
fi
49+
done
50+
done
51+
52+
echo "chart metrics port checks passed"

0 commit comments

Comments
 (0)