Remove retries to ExternalName (#4584)
This commit is contained in:
parent
189e742685
commit
624ce0857a
4 changed files with 9 additions and 28 deletions
|
@ -28,7 +28,7 @@ if [ -z "${PKG}" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
export CGO_ENABLED=1
|
export CGO_ENABLED=1
|
||||||
export GODEBUG=netdns=go+2
|
export GODEBUG=netdns=cgo+2
|
||||||
# use vendor directory instead of go modules https://github.com/golang/go/wiki/Modules
|
# use vendor directory instead of go modules https://github.com/golang/go/wiki/Modules
|
||||||
export GO111MODULE=off
|
export GO111MODULE=off
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ fi
|
||||||
|
|
||||||
# enabled to use host dns resolver
|
# enabled to use host dns resolver
|
||||||
export CGO_ENABLED=1
|
export CGO_ENABLED=1
|
||||||
export GODEBUG=netdns=go+2
|
export GODEBUG=netdns=cgo+2
|
||||||
# use vendor directory instead of go modules https://github.com/golang/go/wiki/Modules
|
# use vendor directory instead of go modules https://github.com/golang/go/wiki/Modules
|
||||||
export GO111MODULE=off
|
export GO111MODULE=off
|
||||||
|
|
||||||
|
|
|
@ -21,9 +21,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
@ -60,26 +58,9 @@ func getEndpoints(s *corev1.Service, port *corev1.ServicePort, proto corev1.Prot
|
||||||
|
|
||||||
// if the externalName is not an IP address we need to validate is a valid FQDN
|
// if the externalName is not an IP address we need to validate is a valid FQDN
|
||||||
if net.ParseIP(s.Spec.ExternalName) == nil {
|
if net.ParseIP(s.Spec.ExternalName) == nil {
|
||||||
defaultRetry := wait.Backoff{
|
_, err := net.LookupHost(s.Spec.ExternalName)
|
||||||
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 {
|
if err != nil {
|
||||||
klog.Errorf("Error resolving host %q: %v", s.Spec.ExternalName, lastErr)
|
klog.Errorf("Error resolving host %q: %v", s.Spec.ExternalName, err)
|
||||||
return upsServers
|
return upsServers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,11 +83,11 @@ func TestGetEndpoints(t *testing.T) {
|
||||||
&corev1.Service{
|
&corev1.Service{
|
||||||
Spec: corev1.ServiceSpec{
|
Spec: corev1.ServiceSpec{
|
||||||
Type: corev1.ServiceTypeExternalName,
|
Type: corev1.ServiceTypeExternalName,
|
||||||
ExternalName: "www.10.0.0.1.xip.io",
|
ExternalName: "www.google.com",
|
||||||
Ports: []corev1.ServicePort{
|
Ports: []corev1.ServicePort{
|
||||||
{
|
{
|
||||||
Name: "default",
|
Name: "default",
|
||||||
TargetPort: intstr.FromInt(80),
|
TargetPort: intstr.FromInt(443),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -102,13 +102,13 @@ func TestGetEndpoints(t *testing.T) {
|
||||||
},
|
},
|
||||||
[]ingress.Endpoint{
|
[]ingress.Endpoint{
|
||||||
{
|
{
|
||||||
Address: "www.10.0.0.1.xip.io",
|
Address: "www.google.com",
|
||||||
Port: "80",
|
Port: "443",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"a service type ServiceTypeExternalName with an invalid ExternalName value should return one endpoint",
|
"a service type ServiceTypeExternalName with an invalid ExternalName value should no return endpoints",
|
||||||
&corev1.Service{
|
&corev1.Service{
|
||||||
Spec: corev1.ServiceSpec{
|
Spec: corev1.ServiceSpec{
|
||||||
Type: corev1.ServiceTypeExternalName,
|
Type: corev1.ServiceTypeExternalName,
|
||||||
|
|
Loading…
Reference in a new issue