|
| 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