diff --git a/pkg/operator/ceph/controller/spec.go b/pkg/operator/ceph/controller/spec.go index 38d72c209..3f616f510 100644 --- a/pkg/operator/ceph/controller/spec.go +++ b/pkg/operator/ceph/controller/spec.go @@ -21,6 +21,7 @@ import ( "context" "encoding/binary" "fmt" + "net" "os" "path" "reflect" @@ -954,7 +955,12 @@ func ConfigureExternalMetricsEndpoint(ctx *clusterd.Context, monitoringSpec ceph } func extractMgrIP(rawActiveAddr string) string { - return strings.Split(rawActiveAddr, ":")[0] + host, _, err := net.SplitHostPort(rawActiveAddr) + if err != nil { + // If there's no port, return as is + return rawActiveAddr + } + return host } func GetContainerImagePullPolicy(containerImagePullPolicy v1.PullPolicy) v1.PullPolicy { diff --git a/pkg/operator/ceph/controller/spec_test.go b/pkg/operator/ceph/controller/spec_test.go index d7341c73a..bf94583a3 100644 --- a/pkg/operator/ceph/controller/spec_test.go +++ b/pkg/operator/ceph/controller/spec_test.go @@ -259,6 +259,22 @@ func TestExtractMgrIP(t *testing.T) { activeMgrRaw := "172.17.0.12:6801/2535462469" ip := extractMgrIP(activeMgrRaw) assert.Equal(t, "172.17.0.12", ip) + + activeMgrRaw = "[2001:db8::1]:6801/2535462469" + ip = extractMgrIP(activeMgrRaw) + assert.Equal(t, "2001:db8::1", ip) + + activeMgrRaw = "invalid-address" + ip = extractMgrIP(activeMgrRaw) + assert.Equal(t, activeMgrRaw, ip) + + activeMgrRaw = "" + ip = extractMgrIP(activeMgrRaw) + assert.Equal(t, "", ip) + + activeMgrRaw = "172.17.0.12" + ip = extractMgrIP(activeMgrRaw) + assert.Equal(t, activeMgrRaw, ip) } func TestConfigureExternalMetricsEndpoint(t *testing.T) {