From 0631c150259a5ab98e0ffcd0f0b5afc5c3b71a42 Mon Sep 17 00:00:00 2001 From: Riya Singhal Date: Mon, 6 Nov 2023 11:54:47 +0530 Subject: [PATCH] cephfs: update fetchIP to support ipv6 addresses Signed-off-by: Riya Singhal --- internal/csi-addons/networkfence/fencing.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/csi-addons/networkfence/fencing.go b/internal/csi-addons/networkfence/fencing.go index 3f7725cab..d8361e55c 100644 --- a/internal/csi-addons/networkfence/fencing.go +++ b/internal/csi-addons/networkfence/fencing.go @@ -212,9 +212,12 @@ func (ac *activeClient) fetchIP() (string, error) { clientInfo := ac.Inst parts := strings.Fields(clientInfo) if len(parts) >= 2 { - ip := strings.Split(parts[1], ":")[0] - - return ip, nil + lastColonIndex := strings.LastIndex(parts[1], ":") + firstPart := parts[1][:lastColonIndex] + ip := net.ParseIP(firstPart) + if ip != nil { + return ip.String(), nil + } } return "", fmt.Errorf("failed to extract IP address, incorrect format: %s", clientInfo)