Skip to content

Commit

Permalink
Merge pull request #4671 from jacksontj/issue_4670
Browse files Browse the repository at this point in the history
Discontinue use of a single DNS query to validate an endpoint name
  • Loading branch information
k8s-ci-robot authored Oct 13, 2019
2 parents a1a2950 + 500b043 commit decc134
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions internal/ingress/controller/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"reflect"
"strconv"

"k8s.io/apimachinery/pkg/util/validation"
"k8s.io/klog"

corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -58,9 +59,8 @@ 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 net.ParseIP(s.Spec.ExternalName) == nil {
_, err := net.LookupHost(s.Spec.ExternalName)
if err != nil {
klog.Errorf("Error resolving host %q: %v", s.Spec.ExternalName, err)
if errs := validation.IsDNS1123Subdomain(s.Spec.ExternalName); len(errs) > 0 {
klog.Errorf("Invalid DNS name %s: %v", s.Spec.ExternalName, errs)
return upsServers
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/ingress/controller/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestGetEndpoints(t *testing.T) {
&corev1.Service{
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeExternalName,
ExternalName: "foo.bar",
ExternalName: "1#invalid.hostname",
Ports: []corev1.ServicePort{
{
Name: "default",
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/servicebackend/service_externalname.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ var _ = framework.IngressNginxDescribe("Service Type ExternalName", func() {
Expect(resp.StatusCode).Should(Equal(200))
})

It("should return status 503 for service type=ExternalName with an invalid host", func() {
It("should return status 502 for service type=ExternalName with an invalid host", func() {
host := "echo"

svc := &core.Service{
Expand Down Expand Up @@ -175,7 +175,7 @@ var _ = framework.IngressNginxDescribe("Service Type ExternalName", func() {
Set("Host", host).
End()
Expect(errs).Should(BeEmpty())
Expect(resp.StatusCode).Should(Equal(503))
Expect(resp.StatusCode).Should(Equal(502))
})

It("should return 200 for service type=ExternalName using a port name", func() {
Expand Down

0 comments on commit decc134

Please sign in to comment.