Fix iSCSI over ipv6

Addresses in the Kubernetes API objects (PV, Pod) have `[]` around IPv6
addresses, while addresses in /dev/ and /sys/ have addresses without them.

Add/remove `[]` as needed.
This commit is contained in:
Jan Safranek
2022-06-21 10:44:42 +02:00
parent 8415ae647d
commit 2efe67e3a9
3 changed files with 17 additions and 6 deletions

View File

@@ -22,6 +22,7 @@ package util
import (
"errors"
"fmt"
"net"
"os"
"path/filepath"
"strconv"
@@ -199,12 +200,11 @@ func (handler *deviceHandler) GetISCSIPortalHostMapForTarget(targetIqn string) (
// Add entries to the map for both the current and persistent portals
// pointing to the SCSI host for those connections
portal := strings.TrimSpace(string(addr)) + ":" +
strings.TrimSpace(string(port))
// JoinHostPort will add `[]` around IPv6 addresses.
portal := net.JoinHostPort(strings.TrimSpace(string(addr)), strings.TrimSpace(string(port)))
portalHostMap[portal] = hostNumber
persistentPortal := strings.TrimSpace(string(persistentAddr)) + ":" +
strings.TrimSpace(string(persistentPort))
persistentPortal := net.JoinHostPort(strings.TrimSpace(string(persistentAddr)), strings.TrimSpace(string(persistentPort)))
portalHostMap[persistentPortal] = hostNumber
}
}