plugin/k8s_external: Fix rcode for headless services (#5657)

Signed-off-by: Miciah Masters <miciah.masters@gmail.com>

Signed-off-by: Miciah Masters <miciah.masters@gmail.com>
This commit is contained in:
Miciah Dashiel Butler Masters 2022-10-20 16:30:12 -04:00 committed by GitHub
parent 4e449b666a
commit 6cb5e10707
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View file

@ -116,6 +116,7 @@ func (k *Kubernetes) External(state request.Request, headless bool) ([]msg.Servi
if !(matchPortAndProtocol(port, p.Name, protocol, p.Protocol)) {
continue
}
rcode = dns.RcodeSuccess
s := msg.Service{Host: addr.IP, Port: int(p.Port), TTL: k.ttl}
s.Key = strings.Join([]string{zonePath, svc.Namespace, svc.Name, endpointHostname(addr, k.endpointNameMode)}, "/")

View file

@ -28,7 +28,7 @@ var extCases = []struct {
{
Qname: "svc6.testns.example.org.", Rcode: dns.RcodeSuccess,
Msg: []msg.Service{
{Host: "1:2::5", Port: 80, TTL: 5, Key: "/c/org/example/testns/svc1"},
{Host: "1:2::5", Port: 80, TTL: 5, Key: "/c/org/example/testns/svc6"},
},
},
{
@ -46,14 +46,14 @@ var extCases = []struct {
{
Qname: "svc-headless.testns.example.com.", Rcode: dns.RcodeSuccess,
Msg: []msg.Service{
{Host: "1.2.3.4", Port: 80, TTL: 5, Weight: 50, Key: "/c/org/example/testns/svc-headless"},
{Host: "1.2.3.5", Port: 80, TTL: 5, Weight: 50, Key: "/c/org/example/testns/svc-headless"},
{Host: "1.2.3.4", Port: 80, TTL: 5, Weight: 50, Key: "/c/org/example/testns/svc-headless/endpoint-svc-0"},
{Host: "1.2.3.5", Port: 80, TTL: 5, Weight: 50, Key: "/c/org/example/testns/svc-headless/endpoint-svc-1"},
},
},
{
Qname: "endpoint-0.svc-headless.testns.example.com.", Rcode: dns.RcodeSuccess,
Qname: "endpoint-svc-0.svc-headless.testns.example.com.", Rcode: dns.RcodeSuccess,
Msg: []msg.Service{
{Host: "1.2.3.4", Port: 80, TTL: 5, Weight: 100, Key: "/c/org/example/testns/svc-headless/endpoint-0"},
{Host: "1.2.3.4", Port: 80, TTL: 5, Weight: 100, Key: "/c/org/example/testns/svc-headless/endpoint-svc-0"},
},
},
{
@ -84,7 +84,6 @@ func TestExternal(t *testing.T) {
if x := tc.Msg[j].Key; x != s.Key {
t.Errorf("Test %d, expected key %s, got %s", i, x, s.Key)
}
return
}
}
}