Skip to content

Commit 0949c51

Browse files
committed
switch back to old hostname parsing logic
1 parent 46afdd1 commit 0949c51

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

internal/controller/managedmetric_controller.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222
"net/url"
23+
"strings"
2324
"time"
2425

2526
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -308,7 +309,12 @@ func getClusterInfo(config *rest.Config) (string, error) {
308309
return "localhost", nil
309310
}
310311

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

314320
// 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.default.svc",
48+
expectedName: "kubernetes",
4949
},
5050
{
5151
name: "CustomClusterName",
5252
host: "https://my-cluster-api.example.com:6443",
53-
expectedName: "my-cluster-api.example.com",
53+
expectedName: "my-cluster-api",
5454
},
5555
{
5656
name: "IPAddress",
5757
host: "https://192.168.1.1:6443",
58-
expectedName: "192.168.1.1", // The function only extracts the first part of the IP address
58+
expectedName: "192", // 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.default.svc",
63+
expectedName: "kubernetes",
6464
},
6565
}
6666

0 commit comments

Comments
 (0)