mw/kubernetes: split integration tests (#1004)
* mw/kubernetes: split integration tests * separate file and test for api fallthrough, does not need all other servers to be started. * more split ups: make it clear when or when not we need an upstream server, as just needlessly start it in doIntegrationTests. * use identifiers from dns package -> "TypeSRV" -> dns.TypeSRV, as there is no need to reinvent these. * updates * deploy work-around * re-add weird sleep
This commit is contained in:
parent
7b8cf9df90
commit
3974071f48
4 changed files with 265 additions and 194 deletions
51
test/kubernetes_api_fallthrough.go
Normal file
51
test/kubernetes_api_fallthrough.go
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/coredns/coredns/middleware/test"
|
||||||
|
|
||||||
|
"github.com/miekg/dns"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestKubernetesAPIFallthrough(t *testing.T) {
|
||||||
|
tests := []test.Case{
|
||||||
|
{
|
||||||
|
Qname: "svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeA,
|
||||||
|
Rcode: dns.RcodeSuccess,
|
||||||
|
Answer: []dns.RR{
|
||||||
|
test.A("svc-1-a.test-1.svc.cluster.local. 303 IN A 10.0.0.100"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
corefile :=
|
||||||
|
`.:0 {
|
||||||
|
kubernetes cluster.local {
|
||||||
|
endpoint http://nonexistance:8080,http://invalidip:8080,http://localhost:8080
|
||||||
|
namespaces test-1
|
||||||
|
pods disabled
|
||||||
|
}`
|
||||||
|
|
||||||
|
server, udp, _, err := CoreDNSServerAndPorts(corefile)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
|
||||||
|
}
|
||||||
|
defer server.Stop()
|
||||||
|
|
||||||
|
// Work-around for timing condition that results in no-data being returned in test environment.
|
||||||
|
time.Sleep(3 * time.Second)
|
||||||
|
|
||||||
|
for _, tc := range tests {
|
||||||
|
|
||||||
|
c := new(dns.Client)
|
||||||
|
m := tc.Msg()
|
||||||
|
|
||||||
|
res, _, err := c.Exchange(m, udp)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Could not send query: %s", err)
|
||||||
|
}
|
||||||
|
test.SortAndCheck(t, res, tc)
|
||||||
|
}
|
||||||
|
}
|
58
test/kubernetes_nsexposed_test.go
Normal file
58
test/kubernetes_nsexposed_test.go
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/coredns/coredns/middleware/test"
|
||||||
|
|
||||||
|
"github.com/miekg/dns"
|
||||||
|
)
|
||||||
|
|
||||||
|
var dnsTestCasesAllNSExposed = []test.Case{
|
||||||
|
{
|
||||||
|
Qname: "svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeA,
|
||||||
|
Rcode: dns.RcodeSuccess,
|
||||||
|
Answer: []dns.RR{
|
||||||
|
test.A("svc-1-a.test-1.svc.cluster.local. 303 IN A 10.0.0.100"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Qname: "svc-c.test-2.svc.cluster.local.", Qtype: dns.TypeA,
|
||||||
|
Rcode: dns.RcodeSuccess,
|
||||||
|
Answer: []dns.RR{
|
||||||
|
test.A("svc-c.test-2.svc.cluster.local. 303 IN A 10.0.0.120"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestKubernetesNSExposed(t *testing.T) {
|
||||||
|
corefile :=
|
||||||
|
`.:0 {
|
||||||
|
kubernetes cluster.local {
|
||||||
|
endpoint http://localhost:8080
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
server, udp, _, err := CoreDNSServerAndPorts(corefile)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
|
||||||
|
}
|
||||||
|
defer server.Stop()
|
||||||
|
|
||||||
|
// Work-around for timing condition that results in no-data being returned in test environment.
|
||||||
|
time.Sleep(3 * time.Second)
|
||||||
|
|
||||||
|
for _, tc := range dnsTestCasesAllNSExposed {
|
||||||
|
|
||||||
|
c := new(dns.Client)
|
||||||
|
m := tc.Msg()
|
||||||
|
|
||||||
|
res, _, err := c.Exchange(m, udp)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Could not send query: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
test.SortAndCheck(t, res, tc)
|
||||||
|
}
|
||||||
|
}
|
108
test/kubernetes_pods_test.go
Normal file
108
test/kubernetes_pods_test.go
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
package test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/coredns/coredns/middleware/test"
|
||||||
|
|
||||||
|
"github.com/miekg/dns"
|
||||||
|
)
|
||||||
|
|
||||||
|
var dnsTestCasesPodsInsecure = []test.Case{
|
||||||
|
{
|
||||||
|
Qname: "10-20-0-101.test-1.pod.cluster.local.", Qtype: dns.TypeA,
|
||||||
|
Rcode: dns.RcodeSuccess,
|
||||||
|
Answer: []dns.RR{
|
||||||
|
test.A("10-20-0-101.test-1.pod.cluster.local. 303 IN A 10.20.0.101"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Qname: "10-20-0-101.test-X.pod.cluster.local.", Qtype: dns.TypeA,
|
||||||
|
Rcode: dns.RcodeNameError,
|
||||||
|
Ns: []dns.RR{
|
||||||
|
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502307903 7200 1800 86400 60"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestKubernetesPodsInsecure(t *testing.T) {
|
||||||
|
corefile := `.:0 {
|
||||||
|
kubernetes cluster.local 0.0.10.in-addr.arpa {
|
||||||
|
endpoint http://localhost:8080
|
||||||
|
namespaces test-1
|
||||||
|
pods insecure
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
server, udp, _, err := CoreDNSServerAndPorts(corefile)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
|
||||||
|
}
|
||||||
|
defer server.Stop()
|
||||||
|
|
||||||
|
// Work-around for timing condition that results in no-data being returned in test environment.
|
||||||
|
time.Sleep(3 * time.Second)
|
||||||
|
|
||||||
|
for _, tc := range dnsTestCasesPodsInsecure {
|
||||||
|
|
||||||
|
c := new(dns.Client)
|
||||||
|
m := tc.Msg()
|
||||||
|
|
||||||
|
res, _, err := c.Exchange(m, udp)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Could not send query: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
test.SortAndCheck(t, res, tc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var dnsTestCasesPodsVerified = []test.Case{
|
||||||
|
{
|
||||||
|
Qname: "10-20-0-101.test-1.pod.cluster.local.", Qtype: dns.TypeA,
|
||||||
|
Rcode: dns.RcodeNameError,
|
||||||
|
Ns: []dns.RR{
|
||||||
|
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502308197 7200 1800 86400 60"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Qname: "10-20-0-101.test-X.pod.cluster.local.", Qtype: dns.TypeA,
|
||||||
|
Rcode: dns.RcodeNameError,
|
||||||
|
Ns: []dns.RR{
|
||||||
|
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502307960 7200 1800 86400 60"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestKubernetesPodsVerified(t *testing.T) {
|
||||||
|
corefile := `.:0 {
|
||||||
|
kubernetes cluster.local 0.0.10.in-addr.arpa {
|
||||||
|
endpoint http://localhost:8080
|
||||||
|
namespaces test-1
|
||||||
|
pods verified
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
server, udp, _, err := CoreDNSServerAndPorts(corefile)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
|
||||||
|
}
|
||||||
|
defer server.Stop()
|
||||||
|
|
||||||
|
// Work-around for timing condition that results in no-data being returned in test environment.
|
||||||
|
time.Sleep(3 * time.Second)
|
||||||
|
|
||||||
|
for _, tc := range dnsTestCasesPodsVerified {
|
||||||
|
|
||||||
|
c := new(dns.Client)
|
||||||
|
m := tc.Msg()
|
||||||
|
|
||||||
|
res, _, err := c.Exchange(m, udp)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Could not send query: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
test.SortAndCheck(t, res, tc)
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,8 +23,6 @@ func init() {
|
||||||
log.SetOutput(ioutil.Discard)
|
log.SetOutput(ioutil.Discard)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test data
|
|
||||||
|
|
||||||
var dnsTestCases = []test.Case{
|
var dnsTestCases = []test.Case{
|
||||||
{
|
{
|
||||||
Qname: "svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeA,
|
Qname: "svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeA,
|
||||||
|
@ -35,24 +33,21 @@ var dnsTestCases = []test.Case{
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "bogusservice.test-1.svc.cluster.local.", Qtype: dns.TypeA,
|
Qname: "bogusservice.test-1.svc.cluster.local.", Qtype: dns.TypeA,
|
||||||
Rcode: dns.RcodeNameError,
|
Rcode: dns.RcodeNameError,
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
Ns: []dns.RR{
|
||||||
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "bogusendpoint.svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeA,
|
Qname: "bogusendpoint.svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeA,
|
||||||
Rcode: dns.RcodeNameError,
|
Rcode: dns.RcodeNameError,
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
Ns: []dns.RR{
|
||||||
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "bogusendpoint.headless-svc.test-1.svc.cluster.local.", Qtype: dns.TypeA,
|
Qname: "bogusendpoint.headless-svc.test-1.svc.cluster.local.", Qtype: dns.TypeA,
|
||||||
Rcode: dns.RcodeNameError,
|
Rcode: dns.RcodeNameError,
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
Ns: []dns.RR{
|
||||||
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
||||||
},
|
},
|
||||||
|
@ -73,16 +68,14 @@ var dnsTestCases = []test.Case{
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "bogusservice.*.svc.cluster.local.", Qtype: dns.TypeA,
|
Qname: "bogusservice.*.svc.cluster.local.", Qtype: dns.TypeA,
|
||||||
Rcode: dns.RcodeNameError,
|
Rcode: dns.RcodeNameError,
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
Ns: []dns.RR{
|
||||||
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "bogusservice.any.svc.cluster.local.", Qtype: dns.TypeA,
|
Qname: "bogusservice.any.svc.cluster.local.", Qtype: dns.TypeA,
|
||||||
Rcode: dns.RcodeNameError,
|
Rcode: dns.RcodeNameError,
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
Ns: []dns.RR{
|
||||||
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
||||||
},
|
},
|
||||||
|
@ -111,16 +104,14 @@ var dnsTestCases = []test.Case{
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "any.test-2.svc.cluster.local.", Qtype: dns.TypeA,
|
Qname: "any.test-2.svc.cluster.local.", Qtype: dns.TypeA,
|
||||||
Rcode: dns.RcodeNameError,
|
Rcode: dns.RcodeNameError,
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
Ns: []dns.RR{
|
||||||
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "*.test-2.svc.cluster.local.", Qtype: dns.TypeA,
|
Qname: "*.test-2.svc.cluster.local.", Qtype: dns.TypeA,
|
||||||
Rcode: dns.RcodeNameError,
|
Rcode: dns.RcodeNameError,
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
Ns: []dns.RR{
|
||||||
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
||||||
},
|
},
|
||||||
|
@ -154,8 +145,7 @@ var dnsTestCases = []test.Case{
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "*.*.bogusservice.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
|
Qname: "*.*.bogusservice.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||||
Rcode: dns.RcodeNameError,
|
Rcode: dns.RcodeNameError,
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
Ns: []dns.RR{
|
||||||
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
||||||
},
|
},
|
||||||
|
@ -184,16 +174,14 @@ var dnsTestCases = []test.Case{
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "*.*.bogusservice.*.svc.cluster.local.", Qtype: dns.TypeSRV,
|
Qname: "*.*.bogusservice.*.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||||
Rcode: dns.RcodeNameError,
|
Rcode: dns.RcodeNameError,
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
Ns: []dns.RR{
|
||||||
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "*.*.bogusservice.any.svc.cluster.local.", Qtype: dns.TypeSRV,
|
Qname: "*.*.bogusservice.any.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||||
Rcode: dns.RcodeNameError,
|
Rcode: dns.RcodeNameError,
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
Ns: []dns.RR{
|
||||||
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
||||||
},
|
},
|
||||||
|
@ -201,10 +189,10 @@ var dnsTestCases = []test.Case{
|
||||||
{
|
{
|
||||||
Qname: "_c-port._UDP.*.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
|
Qname: "_c-port._UDP.*.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||||
Rcode: dns.RcodeSuccess,
|
Rcode: dns.RcodeSuccess,
|
||||||
Answer: append(srvResponse("_c-port._UDP.*.test-1.svc.cluster.local.", "TypeSRV", "headless-svc", "test-1"),
|
Answer: append(srvResponse("_c-port._UDP.*.test-1.svc.cluster.local.", dns.TypeSRV, "headless-svc", "test-1"),
|
||||||
[]dns.RR{
|
[]dns.RR{
|
||||||
test.SRV("_c-port._UDP.*.test-1.svc.cluster.local. 303 IN SRV 0 33 1234 svc-c.test-1.svc.cluster.local.")}...),
|
test.SRV("_c-port._UDP.*.test-1.svc.cluster.local. 303 IN SRV 0 33 1234 svc-c.test-1.svc.cluster.local.")}...),
|
||||||
Extra: append(srvResponse("_c-port._UDP.*.test-1.svc.cluster.local.", "TypeA", "headless-svc", "test-1"),
|
Extra: append(srvResponse("_c-port._UDP.*.test-1.svc.cluster.local.", dns.TypeA, "headless-svc", "test-1"),
|
||||||
[]dns.RR{
|
[]dns.RR{
|
||||||
test.A("svc-c.test-1.svc.cluster.local. 303 IN A 10.0.0.115")}...),
|
test.A("svc-c.test-1.svc.cluster.local. 303 IN A 10.0.0.115")}...),
|
||||||
},
|
},
|
||||||
|
@ -223,16 +211,14 @@ var dnsTestCases = []test.Case{
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "*.*.any.test-2.svc.cluster.local.", Qtype: dns.TypeSRV,
|
Qname: "*.*.any.test-2.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||||
Rcode: dns.RcodeNameError,
|
Rcode: dns.RcodeNameError,
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
Ns: []dns.RR{
|
||||||
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "*.*.*.test-2.svc.cluster.local.", Qtype: dns.TypeSRV,
|
Qname: "*.*.*.test-2.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||||
Rcode: dns.RcodeNameError,
|
Rcode: dns.RcodeNameError,
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
Ns: []dns.RR{
|
||||||
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
||||||
},
|
},
|
||||||
|
@ -252,13 +238,12 @@ var dnsTestCases = []test.Case{
|
||||||
{
|
{
|
||||||
Qname: "*.svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
|
Qname: "*.svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||||
Rcode: dns.RcodeSuccess,
|
Rcode: dns.RcodeSuccess,
|
||||||
Answer: srvResponse("*.svc-1-a.test-1.svc.cluster.local.", "TypeSRV", "svc-1-a", "test-1"),
|
Answer: srvResponse("*.svc-1-a.test-1.svc.cluster.local.", dns.TypeSRV, "svc-1-a", "test-1"),
|
||||||
Extra: srvResponse("*.svc-1-a.test-1.svc.cluster.local.", "TypeA", "svc-1-a", "test-1"),
|
Extra: srvResponse("*.svc-1-a.test-1.svc.cluster.local.", dns.TypeA, "svc-1-a", "test-1"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "*._not-udp-or-tcp.svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
|
Qname: "*._not-udp-or-tcp.svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||||
Rcode: dns.RcodeNameError,
|
Rcode: dns.RcodeNameError,
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
Ns: []dns.RR{
|
||||||
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
||||||
},
|
},
|
||||||
|
@ -276,8 +261,7 @@ var dnsTestCases = []test.Case{
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "10-20-0-101.test-1.pod.cluster.local.", Qtype: dns.TypeA,
|
Qname: "10-20-0-101.test-1.pod.cluster.local.", Qtype: dns.TypeA,
|
||||||
Rcode: dns.RcodeServerFailure,
|
Rcode: dns.RcodeServerFailure,
|
||||||
Answer: []dns.RR{},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "dns-version.cluster.local.", Qtype: dns.TypeTXT,
|
Qname: "dns-version.cluster.local.", Qtype: dns.TypeTXT,
|
||||||
|
@ -303,60 +287,6 @@ var dnsTestCases = []test.Case{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var dnsTestCasesPodsInsecure = []test.Case{
|
|
||||||
{
|
|
||||||
Qname: "10-20-0-101.test-1.pod.cluster.local.", Qtype: dns.TypeA,
|
|
||||||
Rcode: dns.RcodeSuccess,
|
|
||||||
Answer: []dns.RR{
|
|
||||||
test.A("10-20-0-101.test-1.pod.cluster.local. 303 IN A 10.20.0.101"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Qname: "10-20-0-101.test-X.pod.cluster.local.", Qtype: dns.TypeA,
|
|
||||||
Rcode: dns.RcodeNameError,
|
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
|
||||||
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502307903 7200 1800 86400 60"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
var dnsTestCasesPodsVerified = []test.Case{
|
|
||||||
{
|
|
||||||
Qname: "10-20-0-101.test-1.pod.cluster.local.", Qtype: dns.TypeA,
|
|
||||||
Rcode: dns.RcodeNameError,
|
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
|
||||||
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502308197 7200 1800 86400 60"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Qname: "10-20-0-101.test-X.pod.cluster.local.", Qtype: dns.TypeA,
|
|
||||||
Rcode: dns.RcodeNameError,
|
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
|
||||||
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502307960 7200 1800 86400 60"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
var dnsTestCasesAllNSExposed = []test.Case{
|
|
||||||
{
|
|
||||||
Qname: "svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeA,
|
|
||||||
Rcode: dns.RcodeSuccess,
|
|
||||||
Answer: []dns.RR{
|
|
||||||
test.A("svc-1-a.test-1.svc.cluster.local. 303 IN A 10.0.0.100"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Qname: "svc-c.test-2.svc.cluster.local.", Qtype: dns.TypeA,
|
|
||||||
Rcode: dns.RcodeSuccess,
|
|
||||||
Answer: []dns.RR{
|
|
||||||
test.A("svc-c.test-2.svc.cluster.local. 303 IN A 10.0.0.120"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
var dnsTestCasesFallthrough = []test.Case{
|
var dnsTestCasesFallthrough = []test.Case{
|
||||||
{
|
{
|
||||||
Qname: "svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeA,
|
Qname: "svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeA,
|
||||||
|
@ -367,24 +297,21 @@ var dnsTestCasesFallthrough = []test.Case{
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "bogusservice.test-1.svc.cluster.local.", Qtype: dns.TypeA,
|
Qname: "bogusservice.test-1.svc.cluster.local.", Qtype: dns.TypeA,
|
||||||
Rcode: dns.RcodeNameError,
|
Rcode: dns.RcodeNameError,
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
Ns: []dns.RR{
|
||||||
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
|
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "bogusendpoint.svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeA,
|
Qname: "bogusendpoint.svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeA,
|
||||||
Rcode: dns.RcodeNameError,
|
Rcode: dns.RcodeNameError,
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
Ns: []dns.RR{
|
||||||
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
|
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "bogusendpoint.headless-svc.test-1.svc.cluster.local.", Qtype: dns.TypeA,
|
Qname: "bogusendpoint.headless-svc.test-1.svc.cluster.local.", Qtype: dns.TypeA,
|
||||||
Rcode: dns.RcodeNameError,
|
Rcode: dns.RcodeNameError,
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
Ns: []dns.RR{
|
||||||
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
|
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
|
||||||
},
|
},
|
||||||
|
@ -405,16 +332,14 @@ var dnsTestCasesFallthrough = []test.Case{
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "bogusservice.*.svc.cluster.local.", Qtype: dns.TypeA,
|
Qname: "bogusservice.*.svc.cluster.local.", Qtype: dns.TypeA,
|
||||||
Rcode: dns.RcodeNameError,
|
Rcode: dns.RcodeNameError,
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
Ns: []dns.RR{
|
||||||
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
|
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "bogusservice.any.svc.cluster.local.", Qtype: dns.TypeA,
|
Qname: "bogusservice.any.svc.cluster.local.", Qtype: dns.TypeA,
|
||||||
Rcode: dns.RcodeNameError,
|
Rcode: dns.RcodeNameError,
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
Ns: []dns.RR{
|
||||||
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
|
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
|
||||||
},
|
},
|
||||||
|
@ -443,16 +368,14 @@ var dnsTestCasesFallthrough = []test.Case{
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "any.test-2.svc.cluster.local.", Qtype: dns.TypeA,
|
Qname: "any.test-2.svc.cluster.local.", Qtype: dns.TypeA,
|
||||||
Rcode: dns.RcodeNameError,
|
Rcode: dns.RcodeNameError,
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
Ns: []dns.RR{
|
||||||
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
|
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "*.test-2.svc.cluster.local.", Qtype: dns.TypeA,
|
Qname: "*.test-2.svc.cluster.local.", Qtype: dns.TypeA,
|
||||||
Rcode: dns.RcodeNameError,
|
Rcode: dns.RcodeNameError,
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
Ns: []dns.RR{
|
||||||
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
|
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
|
||||||
},
|
},
|
||||||
|
@ -486,8 +409,7 @@ var dnsTestCasesFallthrough = []test.Case{
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "*.*.bogusservice.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
|
Qname: "*.*.bogusservice.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||||
Rcode: dns.RcodeNameError,
|
Rcode: dns.RcodeNameError,
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
Ns: []dns.RR{
|
||||||
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
|
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
|
||||||
},
|
},
|
||||||
|
@ -516,16 +438,14 @@ var dnsTestCasesFallthrough = []test.Case{
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "*.*.bogusservice.*.svc.cluster.local.", Qtype: dns.TypeSRV,
|
Qname: "*.*.bogusservice.*.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||||
Rcode: dns.RcodeNameError,
|
Rcode: dns.RcodeNameError,
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
Ns: []dns.RR{
|
||||||
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
|
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "*.*.bogusservice.any.svc.cluster.local.", Qtype: dns.TypeSRV,
|
Qname: "*.*.bogusservice.any.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||||
Rcode: dns.RcodeNameError,
|
Rcode: dns.RcodeNameError,
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
Ns: []dns.RR{
|
||||||
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
|
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
|
||||||
},
|
},
|
||||||
|
@ -533,10 +453,10 @@ var dnsTestCasesFallthrough = []test.Case{
|
||||||
{
|
{
|
||||||
Qname: "_c-port._UDP.*.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
|
Qname: "_c-port._UDP.*.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||||
Rcode: dns.RcodeSuccess,
|
Rcode: dns.RcodeSuccess,
|
||||||
Answer: append(srvResponse("_c-port._UDP.*.test-1.svc.cluster.local.", "TypeSRV", "headless-svc", "test-1"),
|
Answer: append(srvResponse("_c-port._UDP.*.test-1.svc.cluster.local.", dns.TypeSRV, "headless-svc", "test-1"),
|
||||||
[]dns.RR{
|
[]dns.RR{
|
||||||
test.SRV("_c-port._UDP.*.test-1.svc.cluster.local. 303 IN SRV 0 33 1234 svc-c.test-1.svc.cluster.local.")}...),
|
test.SRV("_c-port._UDP.*.test-1.svc.cluster.local. 303 IN SRV 0 33 1234 svc-c.test-1.svc.cluster.local.")}...),
|
||||||
Extra: append(srvResponse("_c-port._UDP.*.test-1.svc.cluster.local.", "TypeA", "headless-svc", "test-1"),
|
Extra: append(srvResponse("_c-port._UDP.*.test-1.svc.cluster.local.", dns.TypeA, "headless-svc", "test-1"),
|
||||||
[]dns.RR{
|
[]dns.RR{
|
||||||
test.A("svc-c.test-1.svc.cluster.local. 303 IN A 10.0.0.115"),
|
test.A("svc-c.test-1.svc.cluster.local. 303 IN A 10.0.0.115"),
|
||||||
}...),
|
}...),
|
||||||
|
@ -556,16 +476,14 @@ var dnsTestCasesFallthrough = []test.Case{
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "*.*.any.test-2.svc.cluster.local.", Qtype: dns.TypeSRV,
|
Qname: "*.*.any.test-2.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||||
Rcode: dns.RcodeNameError,
|
Rcode: dns.RcodeNameError,
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
Ns: []dns.RR{
|
||||||
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
|
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "*.*.*.test-2.svc.cluster.local.", Qtype: dns.TypeSRV,
|
Qname: "*.*.*.test-2.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||||
Rcode: dns.RcodeNameError,
|
Rcode: dns.RcodeNameError,
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
Ns: []dns.RR{
|
||||||
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
|
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
|
||||||
},
|
},
|
||||||
|
@ -585,13 +503,12 @@ var dnsTestCasesFallthrough = []test.Case{
|
||||||
{
|
{
|
||||||
Qname: "*.svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
|
Qname: "*.svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||||
Rcode: dns.RcodeSuccess,
|
Rcode: dns.RcodeSuccess,
|
||||||
Answer: srvResponse("*.svc-1-a.test-1.svc.cluster.local.", "TypeSRV", "svc-1-a", "test-1"),
|
Answer: srvResponse("*.svc-1-a.test-1.svc.cluster.local.", dns.TypeSRV, "svc-1-a", "test-1"),
|
||||||
Extra: srvResponse("*.svc-1-a.test-1.svc.cluster.local.", "TypeA", "svc-1-a", "test-1"),
|
Extra: srvResponse("*.svc-1-a.test-1.svc.cluster.local.", dns.TypeA, "svc-1-a", "test-1"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Qname: "*._not-udp-or-tcp.svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
|
Qname: "*._not-udp-or-tcp.svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||||
Rcode: dns.RcodeNameError,
|
Rcode: dns.RcodeNameError,
|
||||||
Answer: []dns.RR{},
|
|
||||||
Ns: []dns.RR{
|
Ns: []dns.RR{
|
||||||
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
|
test.SOA("cluster.local. 303 IN SOA sns.dns.icann.org. noc.dns.icann.org. 2015082541 7200 3600 1209600 3600"),
|
||||||
},
|
},
|
||||||
|
@ -658,16 +575,6 @@ var dnsTestCasesFallthrough = []test.Case{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var dnsTestCasesAPIProxy = []test.Case{
|
|
||||||
{
|
|
||||||
Qname: "svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeA,
|
|
||||||
Rcode: dns.RcodeSuccess,
|
|
||||||
Answer: []dns.RR{
|
|
||||||
test.A("svc-1-a.test-1.svc.cluster.local. 303 IN A 10.0.0.100"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func doIntegrationTests(t *testing.T, corefile string, testCases []test.Case) {
|
func doIntegrationTests(t *testing.T, corefile string, testCases []test.Case) {
|
||||||
server, udp, _, err := CoreDNSServerAndPorts(corefile)
|
server, udp, _, err := CoreDNSServerAndPorts(corefile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -737,61 +644,6 @@ func TestKubernetesIntegration(t *testing.T) {
|
||||||
doIntegrationTests(t, corefile, dnsTestCases)
|
doIntegrationTests(t, corefile, dnsTestCases)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestKubernetesIntegrationAPIProxy(t *testing.T) {
|
|
||||||
|
|
||||||
removeUpstreamConfig, upstreamServer, udp := createUpstreamServer(t)
|
|
||||||
defer upstreamServer.Stop()
|
|
||||||
defer removeUpstreamConfig()
|
|
||||||
|
|
||||||
corefile :=
|
|
||||||
`.:0 {
|
|
||||||
kubernetes cluster.local 0.0.10.in-addr.arpa {
|
|
||||||
endpoint http://nonexistance:8080,http://invalidip:8080,http://localhost:8080
|
|
||||||
namespaces test-1
|
|
||||||
pods disabled
|
|
||||||
upstream ` + udp + `
|
|
||||||
}
|
|
||||||
erratic . {
|
|
||||||
drop 0
|
|
||||||
}
|
|
||||||
`
|
|
||||||
doIntegrationTests(t, corefile, dnsTestCasesAPIProxy)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestKubernetesIntegrationPodsInsecure(t *testing.T) {
|
|
||||||
corefile :=
|
|
||||||
`.:0 {
|
|
||||||
kubernetes cluster.local 0.0.10.in-addr.arpa {
|
|
||||||
endpoint http://localhost:8080
|
|
||||||
namespaces test-1
|
|
||||||
pods insecure
|
|
||||||
}
|
|
||||||
`
|
|
||||||
doIntegrationTests(t, corefile, dnsTestCasesPodsInsecure)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestKubernetesIntegrationPodsVerified(t *testing.T) {
|
|
||||||
corefile :=
|
|
||||||
`.:0 {
|
|
||||||
kubernetes cluster.local 0.0.10.in-addr.arpa {
|
|
||||||
endpoint http://localhost:8080
|
|
||||||
namespaces test-1
|
|
||||||
pods verified
|
|
||||||
}
|
|
||||||
`
|
|
||||||
doIntegrationTests(t, corefile, dnsTestCasesPodsVerified)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestKubernetesIntegrationAllNSExposed(t *testing.T) {
|
|
||||||
corefile :=
|
|
||||||
`.:0 {
|
|
||||||
kubernetes cluster.local {
|
|
||||||
endpoint http://localhost:8080
|
|
||||||
}
|
|
||||||
`
|
|
||||||
doIntegrationTests(t, corefile, dnsTestCasesAllNSExposed)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestKubernetesIntegrationFallthrough(t *testing.T) {
|
func TestKubernetesIntegrationFallthrough(t *testing.T) {
|
||||||
dbfile, rmFunc, err := TempFile(os.TempDir(), clusterLocal)
|
dbfile, rmFunc, err := TempFile(os.TempDir(), clusterLocal)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -819,7 +671,7 @@ func TestKubernetesIntegrationFallthrough(t *testing.T) {
|
||||||
doIntegrationTests(t, corefile, dnsTestCasesFallthrough)
|
doIntegrationTests(t, corefile, dnsTestCasesFallthrough)
|
||||||
}
|
}
|
||||||
|
|
||||||
//headlessAResponse returns the answer to an A request for the specific name and namespace
|
// headlessAResponse returns the answer to an A request for the specific name and namespace.
|
||||||
func headlessAResponse(qname, namespace, name string) []dns.RR {
|
func headlessAResponse(qname, namespace, name string) []dns.RR {
|
||||||
rr := []dns.RR{}
|
rr := []dns.RR{}
|
||||||
|
|
||||||
|
@ -837,8 +689,8 @@ func headlessAResponse(qname, namespace, name string) []dns.RR {
|
||||||
}
|
}
|
||||||
|
|
||||||
// srvResponse returns the answer to a SRV request for the specific name and namespace
|
// srvResponse returns the answer to a SRV request for the specific name and namespace
|
||||||
// responsetype is the type of answer to generate, eg: TypeSRV ( for answer section) or TypeA (for extra section)
|
// qtype is the type of answer to generate, eg: TypeSRV (for answer section) or TypeA (for extra section).
|
||||||
func srvResponse(qname, responsetype, namespace, name string) []dns.RR {
|
func srvResponse(qname string, qtype uint16, namespace, name string) []dns.RR {
|
||||||
rr := []dns.RR{}
|
rr := []dns.RR{}
|
||||||
|
|
||||||
str, err := endpointIPs(name, namespace)
|
str, err := endpointIPs(name, namespace)
|
||||||
|
@ -852,15 +704,17 @@ func srvResponse(qname, responsetype, namespace, name string) []dns.RR {
|
||||||
for i := 0; i < lr; i++ {
|
for i := 0; i < lr; i++ {
|
||||||
ip := strings.Replace(result[i], ".", "-", -1)
|
ip := strings.Replace(result[i], ".", "-", -1)
|
||||||
t := strconv.Itoa(100 / (lr + 1))
|
t := strconv.Itoa(100 / (lr + 1))
|
||||||
if responsetype == "TypeA" {
|
|
||||||
|
switch qtype {
|
||||||
|
case dns.TypeA:
|
||||||
rr = append(rr, test.A(ip+"."+namespace+"."+name+".svc.cluster.local. 303 IN A "+result[i]))
|
rr = append(rr, test.A(ip+"."+namespace+"."+name+".svc.cluster.local. 303 IN A "+result[i]))
|
||||||
}
|
case dns.TypeSRV:
|
||||||
if responsetype == "TypeSRV" && namespace == "headless-svc" {
|
if namespace == "headless-svc" {
|
||||||
rr = append(rr, test.SRV(qname+" 303 IN SRV 0 "+t+" 1234 "+ip+"."+namespace+"."+name+".svc.cluster.local."))
|
rr = append(rr, test.SRV(qname+" 303 IN SRV 0 "+t+" 1234 "+ip+"."+namespace+"."+name+".svc.cluster.local."))
|
||||||
}
|
} else {
|
||||||
if responsetype == "TypeSRV" && namespace != "headless-svc" {
|
rr = append(rr, test.SRV(qname+" 303 IN SRV 0 "+t+" 443 "+ip+"."+namespace+"."+name+".svc.cluster.local."))
|
||||||
rr = append(rr, test.SRV(qname+" 303 IN SRV 0 "+t+" 443 "+ip+"."+namespace+"."+name+".svc.cluster.local."))
|
rr = append(rr, test.SRV(qname+" 303 IN SRV 0 "+t+" 80 "+ip+"."+namespace+"."+name+".svc.cluster.local."))
|
||||||
rr = append(rr, test.SRV(qname+" 303 IN SRV 0 "+t+" 80 "+ip+"."+namespace+"."+name+".svc.cluster.local."))
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rr
|
return rr
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue