external: fix ipv6 monitoring endpoint reconcile

currently the extraction ipv6 was not correct
used the net package to extract the host ip from
the ipadress

Signed-off-by: parth-gr <partharora1010@gmail.com>
(cherry picked from commit e1873cb2e7)
This commit is contained in:
parth-gr authored and Mergify committed 2025-09-15 16:46:41 +00:00
1 parent 98ba1335cb
commit 0249d2b6a5
2 files changed
+23 -1

No files matched your search

+7 -1
View File
@@ -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 {
+16
View File
@@ -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) {