Skip to content

Commit d5122fe

Browse files
DNS services are not resolving properly
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.
1 parent 0e08c78 commit d5122fe

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

pkg/dns/server.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import (
1212
// NewServerDefaults returns the default SkyDNS server configuration for a DNS server.
1313
func NewServerDefaults() (*server.Config, error) {
1414
config := &server.Config{
15-
Domain: "cluster.local.",
16-
Local: "openshift.default.svc.cluster.local.",
15+
Domain: "cluster.local.",
16+
Local: "openshift.default.svc.cluster.local.",
17+
Verbose: glog.V(4),
1718
}
1819
return config, server.SetDefaults(config)
1920
}

pkg/dns/serviceresolver.go

+12-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"fmt"
55
"strings"
66

7+
"github.com/golang/glog"
8+
79
kapi "k8s.io/kubernetes/pkg/api"
810
"k8s.io/kubernetes/pkg/api/errors"
911
kclient "k8s.io/kubernetes/pkg/client/unversioned"
@@ -60,19 +62,19 @@ func NewServiceResolver(config *server.Config, accessor ServiceAccessor, endpoin
6062
// * endpoint_id is "portal" when portalIP is set
6163
// * endpoints always returns each individual endpoint as A records
6264
//
63-
func (b *ServiceResolver) Records(name string, exact bool) ([]msg.Service, error) {
64-
if !strings.HasSuffix(name, b.base) {
65+
func (b *ServiceResolver) Records(dnsName string, exact bool) ([]msg.Service, error) {
66+
if !strings.HasSuffix(dnsName, b.base) {
6567
return nil, nil
6668
}
67-
prefix := strings.Trim(strings.TrimSuffix(name, b.base), ".")
69+
prefix := strings.Trim(strings.TrimSuffix(dnsName, b.base), ".")
6870
segments := strings.Split(prefix, ".")
6971
for i, j := 0, len(segments)-1; i < j; i, j = i+1, j-1 {
7072
segments[i], segments[j] = segments[j], segments[i]
7173
}
7274
if len(segments) == 0 {
7375
return nil, nil
7476
}
75-
77+
glog.V(4).Infof("Answering query %s:%t", dnsName, exact)
7678
switch segments[0] {
7779
case "svc", "endpoints":
7880
if len(segments) < 3 {
@@ -117,8 +119,8 @@ func (b *ServiceResolver) Records(name string, exact bool) ([]msg.Service, error
117119
if len(portName) == 0 {
118120
portName = fmt.Sprintf("unknown-port-%d", port)
119121
}
120-
srvName := fmt.Sprintf("%s.portal.%s", portName, name)
121-
keyName := fmt.Sprintf("_%s._%s.%s", portName, p.Protocol, name)
122+
srvName := fmt.Sprintf("%s.portal.%s.%s", portName, name, b.base)
123+
keyName := fmt.Sprintf("_%s._%s.%s.%s", portName, strings.ToLower(string(p.Protocol)), name, b.base)
122124
services = append(services,
123125
msg.Service{
124126
Host: svc.Spec.ClusterIP,
@@ -144,6 +146,7 @@ func (b *ServiceResolver) Records(name string, exact bool) ([]msg.Service, error
144146
},
145147
)
146148
}
149+
glog.V(4).Infof("Answered %s:%t with %#v", dnsName, exact, services)
147150
return services, nil
148151
}
149152

@@ -185,7 +188,7 @@ func (b *ServiceResolver) Records(name string, exact bool) ([]msg.Service, error
185188
if len(portName) == 0 {
186189
portName = fmt.Sprintf("unknown-port-%d", port)
187190
}
188-
srvName := fmt.Sprintf("%s.%s.%s", portName, shortName, name)
191+
srvName := fmt.Sprintf("%s.%s.%s.%s", portName, shortName, name, b.base)
189192
services = append(services, msg.Service{
190193
Host: a.IP,
191194
Port: port,
@@ -197,7 +200,7 @@ func (b *ServiceResolver) Records(name string, exact bool) ([]msg.Service, error
197200
Text: "",
198201
Key: msg.Path(srvName),
199202
})
200-
keyName := fmt.Sprintf("_%s._%s.%s", portName, p.Protocol, name)
203+
keyName := fmt.Sprintf("_%s._%s.%s.%s", portName, p.Protocol, name, b.base)
201204
services = append(services, msg.Service{
202205
Host: srvName,
203206
Port: port,
@@ -225,6 +228,7 @@ func (b *ServiceResolver) Records(name string, exact bool) ([]msg.Service, error
225228
}
226229
}
227230
}
231+
glog.V(4).Infof("Answered %s:%t with %#v", dnsName, exact, services)
228232
return services, nil
229233
}
230234
return nil, nil

0 commit comments

Comments
 (0)