Skip to content

Commit 1ef0e79

Browse files
committed
allow users to specify multiple URLs for external controllers
When a user has a HA LINSTOR Controller managed by drbd-reactor, they generally do not have a single service IP. Instead, the user usually specified all possible controller IPs. golinstor already supports this when using the "Controllers()" option, so make use of this here. LINSTOR CSI does not need to be updated, as this already works there. Signed-off-by: Moritz Wanzenböck <[email protected]>
1 parent e2e7edb commit 1ef0e79

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

docs/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Automatically set the LINSTOR Satellite image version when using an external LINSTOR Controller.
1313

1414
### Changed
15+
1516
- Disable debug logging by default for the Operator.
17+
- Allow specifying multiple controller URLs for external LINSTOR clusters.
1618

1719
## [v2.7.1] - 2024-11-25
1820

pkg/linstorhelper/client.go

+3-10
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,8 @@ func NewClientForCluster(ctx context.Context, cl client.Client, namespace string
6767
// of other goroutines.
6868
options = slices.Clone(options)
6969

70-
var clientUrl *url.URL
7170
if ref.ExternalController != nil {
72-
u, err := url.Parse(ref.ExternalController.URL)
73-
if err != nil {
74-
return nil, fmt.Errorf("failed to parse external controller URL: %w", err)
75-
}
76-
77-
clientUrl = u
71+
options = append(options, lapi.Controllers(strings.Split(ref.ExternalController.URL, ",")))
7872
} else {
7973
services := corev1.ServiceList{}
8074
err := cl.List(ctx, &services, client.InNamespace(namespace), client.MatchingLabels{
@@ -96,10 +90,10 @@ func NewClientForCluster(ctx context.Context, cl client.Client, namespace string
9690
return nil, nil
9791
}
9892

99-
clientUrl = &url.URL{
93+
options = append(options, lapi.BaseURL(&url.URL{
10094
Scheme: scheme,
10195
Host: fmt.Sprintf("%s.%s.svc:%d", s.Name, s.Namespace, port),
102-
}
96+
}))
10397
}
10498

10599
if ref.ClientSecretName != "" {
@@ -127,7 +121,6 @@ func NewClientForCluster(ctx context.Context, cl client.Client, namespace string
127121
}
128122

129123
options = append(options,
130-
lapi.BaseURL(clientUrl),
131124
lapi.UserAgent(vars.OperatorName+"/"+vars.Version),
132125
lapi.Log(&logrAdapter{log.FromContext(ctx)}),
133126
)

pkg/linstorhelper/client_test.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func TestNewClientForCluster(t *testing.T) {
8181
URL: "http://other-cluster.example.com:3370",
8282
},
8383
expectedOptions: []lapi.Option{
84-
lapi.BaseURL(&url.URL{Scheme: "http", Host: "other-cluster.example.com:3370"}),
84+
lapi.Controllers([]string{"http://other-cluster.example.com:3370"}),
8585
lapi.UserAgent(vars.OperatorName + "/" + vars.Version),
8686
},
8787
},
@@ -99,13 +99,26 @@ func TestNewClientForCluster(t *testing.T) {
9999
},
100100
existingSecret: "client-secret",
101101
expectedOptions: []lapi.Option{
102-
lapi.BaseURL(&url.URL{Scheme: "https", Host: "other-cluster.example.com:3371"}),
102+
lapi.Controllers([]string{"https://other-cluster.example.com:3371"}),
103103
lapi.HTTPClient(&http.Client{Transport: &http.Transport{
104104
TLSClientConfig: tlsConfig,
105105
}}),
106106
lapi.UserAgent(vars.OperatorName + "/" + vars.Version),
107107
},
108108
},
109+
{
110+
name: "cluster-external-controller-with-multiple-urls",
111+
externalRef: &piraeusv1.LinstorExternalControllerRef{
112+
URL: "http://other-cluster.example.com:3370,http://another-cluster.example.com:3370",
113+
},
114+
expectedOptions: []lapi.Option{
115+
lapi.Controllers([]string{
116+
"http://other-cluster.example.com:3370",
117+
"http://another-cluster.example.com:3370",
118+
}),
119+
lapi.UserAgent(vars.OperatorName + "/" + vars.Version),
120+
},
121+
},
109122
{
110123
name: "cluster-with-service-without-port-client-nil",
111124
existingObjs: []client.Object{

0 commit comments

Comments
 (0)