Skip to content

Commit d54c4c8

Browse files
authored
Fix cluster name parsing logic
1 parent f5ed664 commit d54c4c8

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

internal/controller/managedmetric_controller.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"fmt"
2222
"net/url"
23-
"strings"
2423
"time"
2524

2625
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -309,11 +308,7 @@ func getClusterInfo(config *rest.Config) (string, error) {
309308
return "localhost", nil
310309
}
311310

312-
// Remove any prefix (like "kubernetes" or "kubernetes.default.svc")
313-
parts := strings.Split(hostname, ".")
314-
clusterName := parts[0]
315-
316-
return clusterName, nil
311+
return hostname, nil
317312
}
318313

319314
// OrchestratorFactory is a function type for creating orchestrators

internal/controller/metric_controller_helpers_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,22 @@ func TestGetClusterInfo(t *testing.T) {
4545
{
4646
name: "KubernetesService",
4747
host: "https://kubernetes.default.svc:6443",
48-
expectedName: "kubernetes",
48+
expectedName: "kubernetes.default.svc",
4949
},
5050
{
5151
name: "CustomClusterName",
5252
host: "https://my-cluster-api.example.com:6443",
53-
expectedName: "my-cluster-api",
53+
expectedName: "my-cluster-api.example.com",
5454
},
5555
{
5656
name: "IPAddress",
5757
host: "https://192.168.1.1:6443",
58-
expectedName: "192", // The function only extracts the first part of the IP address
58+
expectedName: "192.168.1.1", // The function only extracts the first part of the IP address
5959
},
6060
{
6161
name: "WithPath",
6262
host: "https://kubernetes.default.svc:6443/api",
63-
expectedName: "kubernetes",
63+
expectedName: "kubernetes.default.svc",
6464
},
6565
}
6666

0 commit comments

Comments
 (0)