Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions frontend/csi/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package csi
import (
"context"
"fmt"
"net"
"os"
"runtime"
"strings"
Expand Down Expand Up @@ -42,6 +43,10 @@ const (
CSIAllInOne = "allInOne"
)

func controllerRestURL(host, port string) string {
return "https://" + net.JoinHostPort(host, port)
}

type Plugin struct {
orchestrator core.Orchestrator
activatedChan chan struct{}
Expand Down Expand Up @@ -262,7 +267,7 @@ func NewNodePlugin(
hostname = tridentconfig.ServerCertName
}

restURL := "https://" + hostname + ":" + port
restURL := controllerRestURL(hostname, port)
p.restClient, err = controllerAPI.CreateTLSRestClient(restURL, caCert, clientCert, clientKey)
if err != nil {
return nil, err
Expand Down Expand Up @@ -354,7 +359,7 @@ func NewAllInOnePlugin(
break
}
}
restURL := "https://" + tridentconfig.ServerCertName + ":" + port
restURL := controllerRestURL(tridentconfig.ServerCertName, port)
p.restClient, err = controllerAPI.CreateTLSRestClient(restURL, caCert, clientCert, clientKey)
if err != nil {
return nil, err
Expand Down
34 changes: 34 additions & 0 deletions frontend/csi/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,40 @@ import (
"github.com/netapp/trident/utils/osutils"
)

func TestControllerRestURL(t *testing.T) {
testCases := []struct {
name string
host string
port string
expected string
}{
{
name: "IPv6 address",
host: "2001:db8::1",
port: "34571",
expected: "https://[2001:db8::1]:34571",
},
{
name: "IPv4 address",
host: "192.0.2.10",
port: "34571",
expected: "https://192.0.2.10:34571",
},
{
name: "DNS name",
host: "trident-csi",
port: "34571",
expected: "https://trident-csi:34571",
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
assert.Equal(t, tc.expected, controllerRestURL(tc.host, tc.port))
})
}
}

func TestNewControllerPlugin(t *testing.T) {
testCases := []struct {
name string
Expand Down
Loading