parent
f77c6e55bf
commit
c9d567ab44
5 changed files with 9 additions and 9 deletions
|
@ -252,7 +252,7 @@ func (k *Kubernetes) InitKubeCache() (err error) {
|
|||
|
||||
// Records looks up services in kubernetes.
|
||||
func (k *Kubernetes) Records(ctx context.Context, state request.Request, exact bool) ([]msg.Service, error) {
|
||||
r, e := parseRequest(state)
|
||||
r, e := parseRequest(state.Name(), state.Zone)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
|
|
|
@ -3,14 +3,16 @@ package kubernetes
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/coredns/coredns/plugin"
|
||||
"github.com/coredns/coredns/plugin/metadata"
|
||||
"github.com/coredns/coredns/request"
|
||||
)
|
||||
|
||||
// Metadata implements the metadata.Provider interface.
|
||||
func (k *Kubernetes) Metadata(ctx context.Context, state request.Request) context.Context {
|
||||
zone := plugin.Zones(k.Zones).Matches(state.Name())
|
||||
// possible optimization: cache r so it doesn't need to be calculated again in ServeDNS
|
||||
r, err := parseRequest(state)
|
||||
r, err := parseRequest(state.Name(), zone)
|
||||
if err != nil {
|
||||
metadata.SetValueFunc(ctx, "kubernetes/parse-error", func() string {
|
||||
return err.Error()
|
||||
|
|
|
@ -109,7 +109,7 @@ func TestMetadata(t *testing.T) {
|
|||
ctx := metadata.ContextWithMetadata(context.Background())
|
||||
state := request.Request{
|
||||
Req: &dns.Msg{Question: []dns.Question{{Name: tc.Qname, Qtype: tc.Qtype}}},
|
||||
Zone: "cluster.local.",
|
||||
Zone: ".",
|
||||
W: &test.ResponseWriter{RemoteIP: tc.RemoteIP},
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,6 @@ package kubernetes
|
|||
|
||||
import (
|
||||
"github.com/coredns/coredns/plugin/pkg/dnsutil"
|
||||
"github.com/coredns/coredns/request"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
|
@ -26,7 +24,7 @@ type recordRequest struct {
|
|||
// parseRequest parses the qname to find all the elements we need for querying k8s. Anything
|
||||
// that is not parsed will have the wildcard "*" value (except r.endpoint).
|
||||
// Potential underscores are stripped from _port and _protocol.
|
||||
func parseRequest(state request.Request) (r recordRequest, err error) {
|
||||
func parseRequest(name, zone string) (r recordRequest, err error) {
|
||||
// 3 Possible cases:
|
||||
// 1. _port._protocol.service.namespace.pod|svc.zone
|
||||
// 2. (endpoint): endpoint.service.namespace.pod|svc.zone
|
||||
|
@ -34,7 +32,7 @@ func parseRequest(state request.Request) (r recordRequest, err error) {
|
|||
//
|
||||
// Federations are handled in the federation plugin. And aren't parsed here.
|
||||
|
||||
base, _ := dnsutil.TrimZone(state.Name(), state.Zone)
|
||||
base, _ := dnsutil.TrimZone(name, zone)
|
||||
// return NODATA for apex queries
|
||||
if base == "" || base == Svc || base == Pod {
|
||||
return r, nil
|
||||
|
|
|
@ -31,7 +31,7 @@ func TestParseRequest(t *testing.T) {
|
|||
m.SetQuestion(tc.query, dns.TypeA)
|
||||
state := request.Request{Zone: zone, Req: m}
|
||||
|
||||
r, e := parseRequest(state)
|
||||
r, e := parseRequest(state.Name(), state.Zone)
|
||||
if e != nil {
|
||||
t.Errorf("Test %d, expected no error, got '%v'.", i, e)
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ func TestParseInvalidRequest(t *testing.T) {
|
|||
m.SetQuestion(query, dns.TypeA)
|
||||
state := request.Request{Zone: zone, Req: m}
|
||||
|
||||
if _, e := parseRequest(state); e == nil {
|
||||
if _, e := parseRequest(state.Name(), state.Zone); e == nil {
|
||||
t.Errorf("Test %d: expected error from %s, got none", i, query)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue