Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit a51d507

Browse files
committed
Use loadbalancer IPv4
1 parent 7fe5514 commit a51d507

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

pkg/service/scaleway/loadbalancer/loadbalancer.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"net/netip"
78

89
"github.com/Tomy2e/cluster-api-provider-scaleway/pkg/scope"
910
"github.com/Tomy2e/cluster-api-provider-scaleway/pkg/service/scaleway/client"
@@ -210,13 +211,24 @@ func (s *Service) Reconcile(ctx context.Context) error {
210211
return err
211212
}
212213

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+
}
216227
}
217228

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+
}
220232

221233
return nil
222234
}

0 commit comments

Comments
 (0)