From d54c4c8a7f7189ec9ac2ff4912c2b330f51acc40 Mon Sep 17 00:00:00 2001 From: Jordan Raychev Date: Mon, 27 Oct 2025 10:56:14 +0200 Subject: [PATCH] Fix cluster name parsing logic --- internal/controller/managedmetric_controller.go | 7 +------ internal/controller/metric_controller_helpers_test.go | 8 ++++---- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/internal/controller/managedmetric_controller.go b/internal/controller/managedmetric_controller.go index c1b4aed..1762017 100644 --- a/internal/controller/managedmetric_controller.go +++ b/internal/controller/managedmetric_controller.go @@ -20,7 +20,6 @@ import ( "context" "fmt" "net/url" - "strings" "time" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -309,11 +308,7 @@ func getClusterInfo(config *rest.Config) (string, error) { return "localhost", nil } - // Remove any prefix (like "kubernetes" or "kubernetes.default.svc") - parts := strings.Split(hostname, ".") - clusterName := parts[0] - - return clusterName, nil + return hostname, nil } // OrchestratorFactory is a function type for creating orchestrators diff --git a/internal/controller/metric_controller_helpers_test.go b/internal/controller/metric_controller_helpers_test.go index 6a776fa..a583749 100644 --- a/internal/controller/metric_controller_helpers_test.go +++ b/internal/controller/metric_controller_helpers_test.go @@ -45,22 +45,22 @@ func TestGetClusterInfo(t *testing.T) { { name: "KubernetesService", host: "https://kubernetes.default.svc:6443", - expectedName: "kubernetes", + expectedName: "kubernetes.default.svc", }, { name: "CustomClusterName", host: "https://my-cluster-api.example.com:6443", - expectedName: "my-cluster-api", + expectedName: "my-cluster-api.example.com", }, { name: "IPAddress", host: "https://192.168.1.1:6443", - expectedName: "192", // The function only extracts the first part of the IP address + expectedName: "192.168.1.1", // The function only extracts the first part of the IP address }, { name: "WithPath", host: "https://kubernetes.default.svc:6443/api", - expectedName: "kubernetes", + expectedName: "kubernetes.default.svc", }, }