Fix k8s chaining (#510)
* fix k8s next middleware chaining * add chain to integration tests * if nit
This commit is contained in:
parent
fa1c90a479
commit
353c1c6487
2 changed files with 40 additions and 9 deletions
|
@ -26,8 +26,10 @@ func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M
|
||||||
// otherwise delegate to the next in the pipeline.
|
// otherwise delegate to the next in the pipeline.
|
||||||
zone := middleware.Zones(k.Zones).Matches(state.Name())
|
zone := middleware.Zones(k.Zones).Matches(state.Name())
|
||||||
if zone == "" {
|
if zone == "" {
|
||||||
if state.Type() == "PTR" {
|
if state.Type() != "PTR" {
|
||||||
// If this is a PTR request, and a the request is in a defined
|
return middleware.NextOrFailure(k.Name(), k.Next, ctx, w, r)
|
||||||
|
}
|
||||||
|
// If this is a PTR request, and the request is in a defined
|
||||||
// pod/service cidr range, process the request in this middleware,
|
// pod/service cidr range, process the request in this middleware,
|
||||||
// otherwise pass to next middleware.
|
// otherwise pass to next middleware.
|
||||||
if !k.IsRequestInReverseRange(state) {
|
if !k.IsRequestInReverseRange(state) {
|
||||||
|
@ -36,7 +38,6 @@ func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M
|
||||||
// Set the zone to this specific request.
|
// Set the zone to this specific request.
|
||||||
zone = state.Name()
|
zone = state.Name()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
records, extra []dns.RR
|
records, extra []dns.RR
|
||||||
|
|
|
@ -225,6 +225,13 @@ var dnsTestCases = []test.Case{
|
||||||
test.TXT("dns-version.cluster.local. 28800 IN TXT \"1.0.0\""),
|
test.TXT("dns-version.cluster.local. 28800 IN TXT \"1.0.0\""),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Qname: "next-in-chain.", Qtype: dns.TypeA,
|
||||||
|
Rcode: dns.RcodeSuccess,
|
||||||
|
Answer: []dns.RR{
|
||||||
|
test.A("next-in-chain. 0 IN A 192.0.2.53"),
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var dnsTestCasesPodsInsecure = []test.Case{
|
var dnsTestCasesPodsInsecure = []test.Case{
|
||||||
|
@ -282,6 +289,13 @@ var dnsTestCasesCidrReverseZone = []test.Case{
|
||||||
test.PTR("115.0.0.10.in-addr.arpa. 303 IN PTR svc-c.test-1.svc.cluster.local."),
|
test.PTR("115.0.0.10.in-addr.arpa. 303 IN PTR svc-c.test-1.svc.cluster.local."),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Qname: "next-in-chain.", Qtype: dns.TypeA,
|
||||||
|
Rcode: dns.RcodeSuccess,
|
||||||
|
Answer: []dns.RR{
|
||||||
|
test.A("next-in-chain. 0 IN A 192.0.2.53"),
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var dnsTestCasesPartialCidrReverseZone = []test.Case{
|
var dnsTestCasesPartialCidrReverseZone = []test.Case{
|
||||||
|
@ -313,6 +327,13 @@ var dnsTestCasesPartialCidrReverseZone = []test.Case{
|
||||||
Rcode: dns.RcodeServerFailure,
|
Rcode: dns.RcodeServerFailure,
|
||||||
Answer: []dns.RR{},
|
Answer: []dns.RR{},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Qname: "next-in-chain.", Qtype: dns.TypeA,
|
||||||
|
Rcode: dns.RcodeSuccess,
|
||||||
|
Answer: []dns.RR{
|
||||||
|
test.A("next-in-chain. 0 IN A 192.0.2.53"),
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var dnsTestCasesAllNSExposed = []test.Case{
|
var dnsTestCasesAllNSExposed = []test.Case{
|
||||||
|
@ -409,6 +430,9 @@ func TestKubernetesIntegration(t *testing.T) {
|
||||||
namespaces test-1
|
namespaces test-1
|
||||||
pods disabled
|
pods disabled
|
||||||
}
|
}
|
||||||
|
erratic . {
|
||||||
|
drop 0
|
||||||
|
}
|
||||||
`
|
`
|
||||||
doIntegrationTests(t, corefile, dnsTestCases)
|
doIntegrationTests(t, corefile, dnsTestCases)
|
||||||
}
|
}
|
||||||
|
@ -445,6 +469,9 @@ func TestKubernetesIntegrationCidrReverseZone(t *testing.T) {
|
||||||
namespaces test-1
|
namespaces test-1
|
||||||
cidrs 10.0.0.0/24
|
cidrs 10.0.0.0/24
|
||||||
}
|
}
|
||||||
|
erratic . {
|
||||||
|
drop 0
|
||||||
|
}
|
||||||
`
|
`
|
||||||
doIntegrationTests(t, corefile, dnsTestCasesCidrReverseZone)
|
doIntegrationTests(t, corefile, dnsTestCasesCidrReverseZone)
|
||||||
}
|
}
|
||||||
|
@ -457,6 +484,9 @@ func TestKubernetesIntegrationPartialCidrReverseZone(t *testing.T) {
|
||||||
namespaces test-1
|
namespaces test-1
|
||||||
cidrs 10.0.0.96/28 10.0.0.120/32
|
cidrs 10.0.0.96/28 10.0.0.120/32
|
||||||
}
|
}
|
||||||
|
erratic . {
|
||||||
|
drop 0
|
||||||
|
}
|
||||||
`
|
`
|
||||||
doIntegrationTests(t, corefile, dnsTestCasesPartialCidrReverseZone)
|
doIntegrationTests(t, corefile, dnsTestCasesPartialCidrReverseZone)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue