Skip to content

Commit

Permalink
DNS services are not resolving properly
Browse files Browse the repository at this point in the history
The change on Sept 15th changed how services resolved in the absence
of search paths, which resulted in very long times to resolve DNS in
some cases.
  • Loading branch information
smarterclayton committed Nov 2, 2015
1 parent 0e08c78 commit d5122fe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions pkg/dns/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (
// NewServerDefaults returns the default SkyDNS server configuration for a DNS server.
func NewServerDefaults() (*server.Config, error) {
config := &server.Config{
Domain: "cluster.local.",
Local: "openshift.default.svc.cluster.local.",
Domain: "cluster.local.",
Local: "openshift.default.svc.cluster.local.",
Verbose: glog.V(4),
}
return config, server.SetDefaults(config)
}
Expand Down
20 changes: 12 additions & 8 deletions pkg/dns/serviceresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"strings"

"github.com/golang/glog"

kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
kclient "k8s.io/kubernetes/pkg/client/unversioned"
Expand Down Expand Up @@ -60,19 +62,19 @@ func NewServiceResolver(config *server.Config, accessor ServiceAccessor, endpoin
// * endpoint_id is "portal" when portalIP is set
// * endpoints always returns each individual endpoint as A records
//
func (b *ServiceResolver) Records(name string, exact bool) ([]msg.Service, error) {
if !strings.HasSuffix(name, b.base) {
func (b *ServiceResolver) Records(dnsName string, exact bool) ([]msg.Service, error) {
if !strings.HasSuffix(dnsName, b.base) {
return nil, nil
}
prefix := strings.Trim(strings.TrimSuffix(name, b.base), ".")
prefix := strings.Trim(strings.TrimSuffix(dnsName, b.base), ".")
segments := strings.Split(prefix, ".")
for i, j := 0, len(segments)-1; i < j; i, j = i+1, j-1 {
segments[i], segments[j] = segments[j], segments[i]
}
if len(segments) == 0 {
return nil, nil
}

glog.V(4).Infof("Answering query %s:%t", dnsName, exact)
switch segments[0] {
case "svc", "endpoints":
if len(segments) < 3 {
Expand Down Expand Up @@ -117,8 +119,8 @@ func (b *ServiceResolver) Records(name string, exact bool) ([]msg.Service, error
if len(portName) == 0 {
portName = fmt.Sprintf("unknown-port-%d", port)
}
srvName := fmt.Sprintf("%s.portal.%s", portName, name)
keyName := fmt.Sprintf("_%s._%s.%s", portName, p.Protocol, name)
srvName := fmt.Sprintf("%s.portal.%s.%s", portName, name, b.base)
keyName := fmt.Sprintf("_%s._%s.%s.%s", portName, strings.ToLower(string(p.Protocol)), name, b.base)
services = append(services,
msg.Service{
Host: svc.Spec.ClusterIP,
Expand All @@ -144,6 +146,7 @@ func (b *ServiceResolver) Records(name string, exact bool) ([]msg.Service, error
},
)
}
glog.V(4).Infof("Answered %s:%t with %#v", dnsName, exact, services)
return services, nil
}

Expand Down Expand Up @@ -185,7 +188,7 @@ func (b *ServiceResolver) Records(name string, exact bool) ([]msg.Service, error
if len(portName) == 0 {
portName = fmt.Sprintf("unknown-port-%d", port)
}
srvName := fmt.Sprintf("%s.%s.%s", portName, shortName, name)
srvName := fmt.Sprintf("%s.%s.%s.%s", portName, shortName, name, b.base)
services = append(services, msg.Service{
Host: a.IP,
Port: port,
Expand All @@ -197,7 +200,7 @@ func (b *ServiceResolver) Records(name string, exact bool) ([]msg.Service, error
Text: "",
Key: msg.Path(srvName),
})
keyName := fmt.Sprintf("_%s._%s.%s", portName, p.Protocol, name)
keyName := fmt.Sprintf("_%s._%s.%s.%s", portName, p.Protocol, name, b.base)
services = append(services, msg.Service{
Host: srvName,
Port: port,
Expand Down Expand Up @@ -225,6 +228,7 @@ func (b *ServiceResolver) Records(name string, exact bool) ([]msg.Service, error
}
}
}
glog.V(4).Infof("Answered %s:%t with %#v", dnsName, exact, services)
return services, nil
}
return nil, nil
Expand Down

0 comments on commit d5122fe

Please sign in to comment.