Skip to content

Commit

Permalink
service-mirror: support gateway resolving to multiple addresses (#11499)
Browse files Browse the repository at this point in the history
If the gateway address was a name resolving to multiple addresses,
previously service-mirror took only one of those address. This behavior
could led to downtime in case the gateway behind the IP picked by service-mirror
is down. This commit fix this behavior by considering all the IPs
resolved. 

Now that we consider all the IPs resolved by the DNS, we make sure they
are sorted lexicographically so that resolveGatewayAddress answer a
stable output.

Signed-off-by: Arthur Outhenin-Chalandre <[email protected]>
  • Loading branch information
MrFreezeex authored Nov 3, 2023
1 parent 111155c commit cef1b58
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions multicluster/service-mirror/cluster_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -984,22 +985,29 @@ func (rcsw *RemoteClusterServiceWatcher) resolveGatewayAddress() ([]corev1.Endpo
var gatewayEndpoints []corev1.EndpointAddress
var errors []error
for _, addr := range strings.Split(rcsw.link.GatewayAddress, ",") {
ipAddr, err := net.ResolveIPAddr("ip", addr)
if err == nil {
gatewayEndpoints = append(gatewayEndpoints, corev1.EndpointAddress{
IP: ipAddr.String(),
})
} else {
ipAddrs, err := net.LookupIP(addr)
if err != nil {
err = fmt.Errorf("Error resolving '%s': %w", addr, err)
rcsw.log.Warn(err)
errors = append(errors, err)
continue
}

for _, ipAddr := range ipAddrs {
gatewayEndpoints = append(gatewayEndpoints, corev1.EndpointAddress{
IP: ipAddr.String(),
})
}
}
// one resolved address is enough
if len(gatewayEndpoints) > 0 {
return gatewayEndpoints, nil

if len(gatewayEndpoints) == 0 {
return nil, RetryableError{errors}
}
return nil, RetryableError{errors}

sort.SliceStable(gatewayEndpoints, func(i, j int) bool {
return gatewayEndpoints[i].IP < gatewayEndpoints[j].IP
})
return gatewayEndpoints, nil
}

func (rcsw *RemoteClusterServiceWatcher) repairEndpoints(ctx context.Context) error {
Expand Down

0 comments on commit cef1b58

Please sign in to comment.