This repository was archived by the owner on Jun 13, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +17
-5
lines changed
pkg/service/scaleway/loadbalancer Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change 4
4
"context"
5
5
"errors"
6
6
"fmt"
7
+ "net/netip"
7
8
8
9
"github.com/Tomy2e/cluster-api-provider-scaleway/pkg/scope"
9
10
"github.com/Tomy2e/cluster-api-provider-scaleway/pkg/service/scaleway/client"
@@ -210,13 +211,24 @@ func (s *Service) Reconcile(ctx context.Context) error {
210
211
return err
211
212
}
212
213
213
- // TODO: verify that loadbalancer.IP[0] is an IPv4.
214
- if len (loadbalancer .IP ) == 0 {
215
- return errors .New ("loadbalancer has no IPs" )
214
+ var found bool
215
+ for _ , lbIP := range loadbalancer .IP {
216
+ ip , err := netip .ParseAddr (lbIP .IPAddress )
217
+ if err != nil {
218
+ return fmt .Errorf ("failed to parse loadbalancer IP %q: %w" , lbIP .IPAddress , err )
219
+ }
220
+
221
+ if ip .Is4 () {
222
+ s .ScalewayCluster .Spec .ControlPlaneEndpoint .Host = lbIP .IPAddress
223
+ s .ScalewayCluster .Spec .ControlPlaneEndpoint .Port = frontend .InboundPort
224
+ found = true
225
+ break
226
+ }
216
227
}
217
228
218
- s .ScalewayCluster .Spec .ControlPlaneEndpoint .Host = loadbalancer .IP [0 ].IPAddress
219
- s .ScalewayCluster .Spec .ControlPlaneEndpoint .Port = frontend .InboundPort
229
+ if ! found {
230
+ return errors .New ("loadbalancer has no IPs" )
231
+ }
220
232
221
233
return nil
222
234
}
You can’t perform that action at this time.
0 commit comments