Add retry to LookupHost used to check the content of ExternalName
This commit is contained in:
parent
3e3e29b78f
commit
0baf75cd17
3 changed files with 25 additions and 4 deletions
|
|
@ -21,7 +21,9 @@ import (
|
|||
"net"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/klog"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
|
|
@ -56,10 +58,28 @@ func getEndpoints(s *corev1.Service, port *corev1.ServicePort, proto corev1.Prot
|
|||
return upsServers
|
||||
}
|
||||
|
||||
// if the externalName is not an IP address we need to validate is a valid FQDN
|
||||
if net.ParseIP(s.Spec.ExternalName) == nil {
|
||||
_, err := net.LookupHost(s.Spec.ExternalName)
|
||||
defaultRetry := wait.Backoff{
|
||||
Steps: 2,
|
||||
Duration: 1 * time.Second,
|
||||
Factor: 1.5,
|
||||
Jitter: 0.2,
|
||||
}
|
||||
|
||||
var lastErr error
|
||||
err := wait.ExponentialBackoff(defaultRetry, func() (bool, error) {
|
||||
_, err := net.LookupHost(s.Spec.ExternalName)
|
||||
if err == nil {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
lastErr = err
|
||||
return false, nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
klog.Errorf("Error resolving host %q: %v", s.Spec.ExternalName, err)
|
||||
klog.Errorf("Error resolving host %q: %v", s.Spec.ExternalName, lastErr)
|
||||
return upsServers
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue