Skip to content

Commit 889d83f

Browse files
MaxRinkCopilot
andcommitted
Fix CSI controller URL for IPv6 service hosts
Build the CSI controller REST endpoint with net.JoinHostPort so IPv6 service hosts from Kubernetes environment variables are bracketed correctly while preserving IPv4 and DNS host behavior. Add unit coverage for IPv6, IPv4, and DNS controller hosts. Fixes #1164 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Maximilian Rink <github@maxrink.de>
1 parent aea926a commit 889d83f

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

frontend/csi/plugin.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package csi
55
import (
66
"context"
77
"fmt"
8+
"net"
89
"os"
910
"runtime"
1011
"strings"
@@ -42,6 +43,10 @@ const (
4243
CSIAllInOne = "allInOne"
4344
)
4445

46+
func controllerRestURL(host, port string) string {
47+
return "https://" + net.JoinHostPort(host, port)
48+
}
49+
4550
type Plugin struct {
4651
orchestrator core.Orchestrator
4752
activatedChan chan struct{}
@@ -262,7 +267,7 @@ func NewNodePlugin(
262267
hostname = tridentconfig.ServerCertName
263268
}
264269

265-
restURL := "https://" + hostname + ":" + port
270+
restURL := controllerRestURL(hostname, port)
266271
p.restClient, err = controllerAPI.CreateTLSRestClient(restURL, caCert, clientCert, clientKey)
267272
if err != nil {
268273
return nil, err
@@ -354,7 +359,7 @@ func NewAllInOnePlugin(
354359
break
355360
}
356361
}
357-
restURL := "https://" + tridentconfig.ServerCertName + ":" + port
362+
restURL := controllerRestURL(tridentconfig.ServerCertName, port)
358363
p.restClient, err = controllerAPI.CreateTLSRestClient(restURL, caCert, clientCert, clientKey)
359364
if err != nil {
360365
return nil, err

frontend/csi/plugin_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,40 @@ import (
3737
"github.com/netapp/trident/utils/osutils"
3838
)
3939

40+
func TestControllerRestURL(t *testing.T) {
41+
testCases := []struct {
42+
name string
43+
host string
44+
port string
45+
expected string
46+
}{
47+
{
48+
name: "IPv6 address",
49+
host: "2001:db8::1",
50+
port: "34571",
51+
expected: "https://[2001:db8::1]:34571",
52+
},
53+
{
54+
name: "IPv4 address",
55+
host: "192.0.2.10",
56+
port: "34571",
57+
expected: "https://192.0.2.10:34571",
58+
},
59+
{
60+
name: "DNS name",
61+
host: "trident-csi",
62+
port: "34571",
63+
expected: "https://trident-csi:34571",
64+
},
65+
}
66+
67+
for _, tc := range testCases {
68+
t.Run(tc.name, func(t *testing.T) {
69+
assert.Equal(t, tc.expected, controllerRestURL(tc.host, tc.port))
70+
})
71+
}
72+
}
73+
4074
func TestNewControllerPlugin(t *testing.T) {
4175
testCases := []struct {
4276
name string

0 commit comments

Comments
 (0)