Skip to content

Commit 1ba7fa4

Browse files
committed
feat: use port 8080 defaultwise for operator metrics
Signed-off-by: Karsten Ludwig Hauser <KHauser@intershop.com>
1 parent 61f28c6 commit 1ba7fa4

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

config/operator/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ spec:
3838
value: ""
3939
ports:
4040
- name: metrics
41+
containerPort: 8080
42+
- name: https
4143
containerPort: 8443
4244
- name: probes
4345
containerPort: 8081

config/operator/metrics_service.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ spec:
66
type: ClusterIP
77
ports:
88
- name: metrics
9+
protocol: TCP
10+
port: 8080
11+
targetPort: 8080
12+
- name: https
913
protocol: TCP
1014
port: 8443
1115
targetPort: 8443

operator/main.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ func main() {
6363
var enableLeaderElection bool
6464
var probeAddr string
6565
var profilingAddr string
66-
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8443", "The address the metric endpoint binds to.")
67-
flag.BoolVar(&metricsSecure, "metrics-secure", true, "Enable secure serving for metrics endpoint.")
68-
flag.BoolVar(&metricsAuth, "metrics-auth", true, "Enable authentication and authorization for metrics endpoint.")
66+
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
67+
flag.BoolVar(&metricsSecure, "metrics-secure", false, "Enable secure serving for metrics endpoint.")
68+
flag.BoolVar(&metricsAuth, "metrics-auth", false, "Enable authentication and authorization for metrics endpoint.")
6969
flag.StringVar(&metricsCertDir, "metrics-cert-dir", "", "The directory that contains the server certificate and key (tls.crt and tls.key) for the metrics endpoint.")
7070
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
7171
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
@@ -124,6 +124,13 @@ func main() {
124124
}
125125
}
126126

127+
// Switch between HTTP (8080) and HTTPS (8443) based on metricsSecure flag
128+
if metricsSecure {
129+
metricsAddr = ":8443"
130+
} else {
131+
metricsAddr = ":8080"
132+
}
133+
127134
metricsOpts := server.Options{
128135
BindAddress: metricsAddr,
129136
SecureServing: metricsSecure,

tests/checks/operator_metrics/operator_metrics_test.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const (
2020
var (
2121
testNamespace = fmt.Sprintf("%s-ns", testName)
2222
clientName = fmt.Sprintf("%s-client", testName)
23-
kedaOperatorMetricsURL = "https://keda-add-ons-http-operator-metrics.keda:8443/metrics"
23+
kedaOperatorMetricsURL = "http://keda-add-ons-http-operator-metrics.keda:8080/metrics"
2424
operatorPodSelector = "app.kubernetes.io/instance=operator"
2525
)
2626

@@ -83,8 +83,8 @@ func TestOperatorMetrics(t *testing.T) {
8383
t.Log("--- testing operator metrics endpoint ---")
8484

8585
// Test 1: HTTPS endpoint should be accessible (will fail cert validation but should return metrics)
86-
t.Log("Test 1: Verify HTTPS endpoint is available")
87-
testHTTPSEndpoint(t)
86+
t.Log("Test 1: Verify HTTP endpoint is available")
87+
testHTTPEndpoint(t)
8888

8989
// Test 2: Verify metrics are returned
9090
t.Log("Test 2: Verify metrics content")
@@ -94,19 +94,13 @@ func TestOperatorMetrics(t *testing.T) {
9494
DeleteKubernetesResources(t, testNamespace, data, templates)
9595
}
9696

97-
func testHTTPSEndpoint(t *testing.T) {
98-
// Use curl with -k to skip certificate validation (self-signed cert)
99-
cmd := fmt.Sprintf("curl -k --max-time 10 %s", kedaOperatorMetricsURL)
97+
func testHTTPEndpoint(t *testing.T) {
98+
cmd := fmt.Sprintf("curl --max-time 10 %s", kedaOperatorMetricsURL)
10099
out, errOut, err := ExecCommandOnSpecificPod(t, clientName, testNamespace, cmd)
101100

102-
// We expect this to succeed with a self-signed certificate
103-
if err != nil {
104-
t.Logf("HTTPS endpoint test - Output: %s, Error output: %s, Error: %v", out, errOut, err)
105-
}
106-
107101
// The endpoint should return something (even if authentication fails, it should respond)
108102
assert.True(t, err == nil || strings.Contains(errOut, "Forbidden") || strings.Contains(out, "Forbidden"),
109-
"HTTPS endpoint should respond (either with metrics or authentication error)")
103+
"HTTP endpoint should respond (either with metrics or authentication error)")
110104
}
111105

112106
func testMetricsContent(t *testing.T) {
@@ -115,7 +109,7 @@ func testMetricsContent(t *testing.T) {
115109
// This allows it to access the metrics endpoint with proper RBAC permissions
116110

117111
// Get the ServiceAccount token to authenticate
118-
cmd := fmt.Sprintf("curl -k -H \"Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)\" --max-time 10 %s", kedaOperatorMetricsURL)
112+
cmd := fmt.Sprintf("curl -H \"Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)\" --max-time 10 %s", kedaOperatorMetricsURL)
119113
out, errOut, err := ExecCommandOnSpecificPod(t, clientName, testNamespace, cmd)
120114

121115
if err != nil {

0 commit comments

Comments
 (0)