Kubernetes cleanup6 (#887)
* mw/kubernetes: handle dns.TypeNS better. * mw/kubernetes: cleanup typeNS replies a bit.
This commit is contained in:
parent
ea77f2a2ca
commit
a38a34c7e0
3 changed files with 8 additions and 27 deletions
|
@ -25,7 +25,7 @@ func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M
|
|||
// otherwise delegate to the next in the pipeline.
|
||||
zone := middleware.Zones(k.Zones).Matches(state.Name())
|
||||
if zone == "" {
|
||||
if state.Type() != "PTR" {
|
||||
if state.QType() != dns.TypePTR {
|
||||
return middleware.NextOrFailure(k.Name(), k.Next, ctx, w, r)
|
||||
}
|
||||
// If this is a PTR request, and the request is in a defined
|
||||
|
|
|
@ -86,7 +86,6 @@ var (
|
|||
errNoItems = errors.New("no items found")
|
||||
errNsNotExposed = errors.New("namespace is not exposed")
|
||||
errInvalidRequest = errors.New("invalid query name")
|
||||
errZoneNotFound = errors.New("zone not found")
|
||||
errAPIBadPodType = errors.New("expected type *api.Pod")
|
||||
errPodsDisabled = errors.New("pod records disabled")
|
||||
)
|
||||
|
@ -97,7 +96,7 @@ func (k *Kubernetes) Services(state request.Request, exact bool, opt middleware.
|
|||
// We're looking again at types, which we've already done in ServeDNS, but there are some types k8s just can't answer.
|
||||
switch state.QType() {
|
||||
case dns.TypeTXT:
|
||||
// 1 label + zone, label must be "dns-version"
|
||||
// 1 label + zone, label must be "dns-version".
|
||||
t, err := dnsutil.TrimZone(state.Name(), state.Zone)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
@ -111,6 +110,11 @@ func (k *Kubernetes) Services(state request.Request, exact bool, opt middleware.
|
|||
}
|
||||
svc := msg.Service{Text: DNSSchemaVersion, TTL: 28800, Key: msg.Path(state.QName(), "coredns")}
|
||||
return []msg.Service{svc}, nil, nil
|
||||
case dns.TypeNS:
|
||||
// We can only get here if the qname equal the zone, see ServeDNS in handler.go.
|
||||
ns := k.coreDNSRecord()
|
||||
svc := msg.Service{Host: ns.A.String(), Key: msg.Path(state.QName(), "coredns")}
|
||||
return []msg.Service{svc}, nil, nil
|
||||
}
|
||||
|
||||
r, e := k.parseRequest(state.Name(), state.QType(), state.Zone)
|
||||
|
@ -142,20 +146,10 @@ func (k *Kubernetes) Services(state request.Request, exact bool, opt middleware.
|
|||
}
|
||||
}
|
||||
return noext, nil, e
|
||||
case dns.TypeNS:
|
||||
srv := k.recordsForNS(r)
|
||||
svcs = append(svcs, srv)
|
||||
return svcs, nil, err
|
||||
}
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
func (k *Kubernetes) recordsForNS(r recordRequest) msg.Service {
|
||||
ns := k.coreDNSRecord()
|
||||
return msg.Service{Host: ns.A.String(),
|
||||
Key: msg.Path(strings.Join([]string{ns.Hdr.Name, r.zone}, "."), "coredns")}
|
||||
}
|
||||
|
||||
// PrimaryZone will return the first non-reverse zone being handled by this middleware
|
||||
func (k *Kubernetes) PrimaryZone() string {
|
||||
return k.Zones[k.primaryZone]
|
||||
|
@ -168,7 +162,7 @@ func (k *Kubernetes) Lookup(state request.Request, name string, typ uint16) (*dn
|
|||
|
||||
// IsNameError implements the ServiceBackend interface.
|
||||
func (k *Kubernetes) IsNameError(err error) bool {
|
||||
return err == errNoItems || err == errNsNotExposed || err == errInvalidRequest || err == errZoneNotFound
|
||||
return err == errNoItems || err == errNsNotExposed || err == errInvalidRequest
|
||||
}
|
||||
|
||||
// Debug implements the ServiceBackend interface.
|
||||
|
|
|
@ -6,19 +6,6 @@ import "net"
|
|||
import "k8s.io/client-go/1.5/pkg/api"
|
||||
import "github.com/miekg/dns"
|
||||
|
||||
func TestRecordForNS(t *testing.T) {
|
||||
k := Kubernetes{Zones: []string{"inter.webs.test."}}
|
||||
corednsRecord.Hdr.Name = "coredns.kube-system."
|
||||
corednsRecord.A = net.IP("1.2.3.4")
|
||||
r, _ := k.parseRequest("inter.webs.test.", dns.TypeNS, "inter.webs.test.")
|
||||
|
||||
expected := "/coredns/test/webs/inter/kube-system/coredns"
|
||||
svc := k.recordsForNS(r)
|
||||
if svc.Key != expected {
|
||||
t.Errorf("Expected result '%v'. Instead got result '%v'.", expected, svc.Key)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefaultNSMsg(t *testing.T) {
|
||||
k := Kubernetes{Zones: []string{"inter.webs.test."}}
|
||||
corednsRecord.Hdr.Name = "coredns.kube-system."
|
||||
|
|
Loading…
Add table
Reference in a new issue