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)
|
||||
}
|
||||
|
||||
// Test data
|
||||
|
||||
var dnsTestCases = []test.Case{
|
||||
{
|
||||
Qname: "svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeA,
|
||||
|
@ -36,7 +34,6 @@ var dnsTestCases = []test.Case{
|
|||
{
|
||||
Qname: "bogusservice.test-1.svc.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. 1502313310 7200 1800 86400 60"),
|
||||
},
|
||||
|
@ -44,7 +41,6 @@ var dnsTestCases = []test.Case{
|
|||
{
|
||||
Qname: "bogusendpoint.svc-1-a.test-1.svc.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. 1502313310 7200 1800 86400 60"),
|
||||
},
|
||||
|
@ -52,7 +48,6 @@ var dnsTestCases = []test.Case{
|
|||
{
|
||||
Qname: "bogusendpoint.headless-svc.test-1.svc.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. 1502313310 7200 1800 86400 60"),
|
||||
},
|
||||
|
@ -74,7 +69,6 @@ var dnsTestCases = []test.Case{
|
|||
{
|
||||
Qname: "bogusservice.*.svc.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. 1502313310 7200 1800 86400 60"),
|
||||
},
|
||||
|
@ -82,7 +76,6 @@ var dnsTestCases = []test.Case{
|
|||
{
|
||||
Qname: "bogusservice.any.svc.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. 1502313310 7200 1800 86400 60"),
|
||||
},
|
||||
|
@ -112,7 +105,6 @@ var dnsTestCases = []test.Case{
|
|||
{
|
||||
Qname: "any.test-2.svc.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. 1502313310 7200 1800 86400 60"),
|
||||
},
|
||||
|
@ -120,7 +112,6 @@ var dnsTestCases = []test.Case{
|
|||
{
|
||||
Qname: "*.test-2.svc.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. 1502313310 7200 1800 86400 60"),
|
||||
},
|
||||
|
@ -155,7 +146,6 @@ var dnsTestCases = []test.Case{
|
|||
{
|
||||
Qname: "*.*.bogusservice.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||
Rcode: dns.RcodeNameError,
|
||||
Answer: []dns.RR{},
|
||||
Ns: []dns.RR{
|
||||
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
||||
},
|
||||
|
@ -185,7 +175,6 @@ var dnsTestCases = []test.Case{
|
|||
{
|
||||
Qname: "*.*.bogusservice.*.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||
Rcode: dns.RcodeNameError,
|
||||
Answer: []dns.RR{},
|
||||
Ns: []dns.RR{
|
||||
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
||||
},
|
||||
|
@ -193,7 +182,6 @@ var dnsTestCases = []test.Case{
|
|||
{
|
||||
Qname: "*.*.bogusservice.any.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||
Rcode: dns.RcodeNameError,
|
||||
Answer: []dns.RR{},
|
||||
Ns: []dns.RR{
|
||||
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,
|
||||
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{
|
||||
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{
|
||||
test.A("svc-c.test-1.svc.cluster.local. 303 IN A 10.0.0.115")}...),
|
||||
},
|
||||
|
@ -224,7 +212,6 @@ var dnsTestCases = []test.Case{
|
|||
{
|
||||
Qname: "*.*.any.test-2.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||
Rcode: dns.RcodeNameError,
|
||||
Answer: []dns.RR{},
|
||||
Ns: []dns.RR{
|
||||
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
||||
},
|
||||
|
@ -232,7 +219,6 @@ var dnsTestCases = []test.Case{
|
|||
{
|
||||
Qname: "*.*.*.test-2.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||
Rcode: dns.RcodeNameError,
|
||||
Answer: []dns.RR{},
|
||||
Ns: []dns.RR{
|
||||
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,
|
||||
Rcode: dns.RcodeSuccess,
|
||||
Answer: srvResponse("*.svc-1-a.test-1.svc.cluster.local.", "TypeSRV", "svc-1-a", "test-1"),
|
||||
Extra: srvResponse("*.svc-1-a.test-1.svc.cluster.local.", "TypeA", "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.", dns.TypeA, "svc-1-a", "test-1"),
|
||||
},
|
||||
{
|
||||
Qname: "*._not-udp-or-tcp.svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||
Rcode: dns.RcodeNameError,
|
||||
Answer: []dns.RR{},
|
||||
Ns: []dns.RR{
|
||||
test.SOA("cluster.local. 303 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1502313310 7200 1800 86400 60"),
|
||||
},
|
||||
|
@ -277,7 +262,6 @@ var dnsTestCases = []test.Case{
|
|||
{
|
||||
Qname: "10-20-0-101.test-1.pod.cluster.local.", Qtype: dns.TypeA,
|
||||
Rcode: dns.RcodeServerFailure,
|
||||
Answer: []dns.RR{},
|
||||
},
|
||||
{
|
||||
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{
|
||||
{
|
||||
Qname: "svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeA,
|
||||
|
@ -368,7 +298,6 @@ var dnsTestCasesFallthrough = []test.Case{
|
|||
{
|
||||
Qname: "bogusservice.test-1.svc.cluster.local.", Qtype: dns.TypeA,
|
||||
Rcode: dns.RcodeNameError,
|
||||
Answer: []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"),
|
||||
},
|
||||
|
@ -376,7 +305,6 @@ var dnsTestCasesFallthrough = []test.Case{
|
|||
{
|
||||
Qname: "bogusendpoint.svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeA,
|
||||
Rcode: dns.RcodeNameError,
|
||||
Answer: []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"),
|
||||
},
|
||||
|
@ -384,7 +312,6 @@ var dnsTestCasesFallthrough = []test.Case{
|
|||
{
|
||||
Qname: "bogusendpoint.headless-svc.test-1.svc.cluster.local.", Qtype: dns.TypeA,
|
||||
Rcode: dns.RcodeNameError,
|
||||
Answer: []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"),
|
||||
},
|
||||
|
@ -406,7 +333,6 @@ var dnsTestCasesFallthrough = []test.Case{
|
|||
{
|
||||
Qname: "bogusservice.*.svc.cluster.local.", Qtype: dns.TypeA,
|
||||
Rcode: dns.RcodeNameError,
|
||||
Answer: []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"),
|
||||
},
|
||||
|
@ -414,7 +340,6 @@ var dnsTestCasesFallthrough = []test.Case{
|
|||
{
|
||||
Qname: "bogusservice.any.svc.cluster.local.", Qtype: dns.TypeA,
|
||||
Rcode: dns.RcodeNameError,
|
||||
Answer: []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"),
|
||||
},
|
||||
|
@ -444,7 +369,6 @@ var dnsTestCasesFallthrough = []test.Case{
|
|||
{
|
||||
Qname: "any.test-2.svc.cluster.local.", Qtype: dns.TypeA,
|
||||
Rcode: dns.RcodeNameError,
|
||||
Answer: []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"),
|
||||
},
|
||||
|
@ -452,7 +376,6 @@ var dnsTestCasesFallthrough = []test.Case{
|
|||
{
|
||||
Qname: "*.test-2.svc.cluster.local.", Qtype: dns.TypeA,
|
||||
Rcode: dns.RcodeNameError,
|
||||
Answer: []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"),
|
||||
},
|
||||
|
@ -487,7 +410,6 @@ var dnsTestCasesFallthrough = []test.Case{
|
|||
{
|
||||
Qname: "*.*.bogusservice.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||
Rcode: dns.RcodeNameError,
|
||||
Answer: []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"),
|
||||
},
|
||||
|
@ -517,7 +439,6 @@ var dnsTestCasesFallthrough = []test.Case{
|
|||
{
|
||||
Qname: "*.*.bogusservice.*.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||
Rcode: dns.RcodeNameError,
|
||||
Answer: []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"),
|
||||
},
|
||||
|
@ -525,7 +446,6 @@ var dnsTestCasesFallthrough = []test.Case{
|
|||
{
|
||||
Qname: "*.*.bogusservice.any.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||
Rcode: dns.RcodeNameError,
|
||||
Answer: []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"),
|
||||
},
|
||||
|
@ -533,10 +453,10 @@ var dnsTestCasesFallthrough = []test.Case{
|
|||
{
|
||||
Qname: "_c-port._UDP.*.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||
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{
|
||||
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{
|
||||
test.A("svc-c.test-1.svc.cluster.local. 303 IN A 10.0.0.115"),
|
||||
}...),
|
||||
|
@ -557,7 +477,6 @@ var dnsTestCasesFallthrough = []test.Case{
|
|||
{
|
||||
Qname: "*.*.any.test-2.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||
Rcode: dns.RcodeNameError,
|
||||
Answer: []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"),
|
||||
},
|
||||
|
@ -565,7 +484,6 @@ var dnsTestCasesFallthrough = []test.Case{
|
|||
{
|
||||
Qname: "*.*.*.test-2.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||
Rcode: dns.RcodeNameError,
|
||||
Answer: []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"),
|
||||
},
|
||||
|
@ -585,13 +503,12 @@ var dnsTestCasesFallthrough = []test.Case{
|
|||
{
|
||||
Qname: "*.svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||
Rcode: dns.RcodeSuccess,
|
||||
Answer: srvResponse("*.svc-1-a.test-1.svc.cluster.local.", "TypeSRV", "svc-1-a", "test-1"),
|
||||
Extra: srvResponse("*.svc-1-a.test-1.svc.cluster.local.", "TypeA", "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.", dns.TypeA, "svc-1-a", "test-1"),
|
||||
},
|
||||
{
|
||||
Qname: "*._not-udp-or-tcp.svc-1-a.test-1.svc.cluster.local.", Qtype: dns.TypeSRV,
|
||||
Rcode: dns.RcodeNameError,
|
||||
Answer: []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"),
|
||||
},
|
||||
|
@ -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) {
|
||||
server, udp, _, err := CoreDNSServerAndPorts(corefile)
|
||||
if err != nil {
|
||||
|
@ -737,61 +644,6 @@ func TestKubernetesIntegration(t *testing.T) {
|
|||
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) {
|
||||
dbfile, rmFunc, err := TempFile(os.TempDir(), clusterLocal)
|
||||
if err != nil {
|
||||
|
@ -819,7 +671,7 @@ func TestKubernetesIntegrationFallthrough(t *testing.T) {
|
|||
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 {
|
||||
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
|
||||
// responsetype 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 {
|
||||
// qtype is the type of answer to generate, eg: TypeSRV (for answer section) or TypeA (for extra section).
|
||||
func srvResponse(qname string, qtype uint16, namespace, name string) []dns.RR {
|
||||
rr := []dns.RR{}
|
||||
|
||||
str, err := endpointIPs(name, namespace)
|
||||
|
@ -852,17 +704,19 @@ func srvResponse(qname, responsetype, namespace, name string) []dns.RR {
|
|||
for i := 0; i < lr; i++ {
|
||||
ip := strings.Replace(result[i], ".", "-", -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]))
|
||||
}
|
||||
if responsetype == "TypeSRV" && namespace == "headless-svc" {
|
||||
case dns.TypeSRV:
|
||||
if namespace == "headless-svc" {
|
||||
rr = append(rr, test.SRV(qname+" 303 IN SRV 0 "+t+" 1234 "+ip+"."+namespace+"."+name+".svc.cluster.local."))
|
||||
}
|
||||
if responsetype == "TypeSRV" && namespace != "headless-svc" {
|
||||
} else {
|
||||
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."))
|
||||
}
|
||||
}
|
||||
}
|
||||
return rr
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue