aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Chris O'Haver <cohaver@infoblox.com> 2017-11-15 02:16:04 -0500
committerGravatar Miek Gieben <miek@miek.nl> 2017-11-15 07:16:04 +0000
commit99dd8f99f3f95e7000c5aac32701b2d0432b35bd (patch)
tree9ff07ff2b42eb0165061d4fcd2f384af25dc8d67
parentc37bf56b1e30ebc9bc94efca0ea12158d5648463 (diff)
downloadcoredns-99dd8f99f3f95e7000c5aac32701b2d0432b35bd.tar.gz
coredns-99dd8f99f3f95e7000c5aac32701b2d0432b35bd.tar.zst
coredns-99dd8f99f3f95e7000c5aac32701b2d0432b35bd.zip
plugin/k8s: clean up and add some ipv6 tests (#1237)
* clean up and add some ipv6 tests * aaaa endpoint * gofmt
-rw-r--r--plugin/kubernetes/handler_test.go371
1 files changed, 138 insertions, 233 deletions
diff --git a/plugin/kubernetes/handler_test.go b/plugin/kubernetes/handler_test.go
index f9a600868..5cfa86116 100644
--- a/plugin/kubernetes/handler_test.go
+++ b/plugin/kubernetes/handler_test.go
@@ -90,12 +90,16 @@ var dnsTestCases = []test.Case{
Qname: "_http._tcp.hdls1.testns.svc.cluster.local.", Qtype: dns.TypeSRV,
Rcode: dns.RcodeSuccess,
Answer: []dns.RR{
- test.SRV("_http._tcp.hdls1.testns.svc.cluster.local. 303 IN SRV 0 50 80 172-0-0-2.hdls1.testns.svc.cluster.local."),
- test.SRV("_http._tcp.hdls1.testns.svc.cluster.local. 303 IN SRV 0 50 80 172-0-0-3.hdls1.testns.svc.cluster.local."),
+ test.SRV("_http._tcp.hdls1.testns.svc.cluster.local. 303 IN SRV 0 25 80 172-0-0-2.hdls1.testns.svc.cluster.local."),
+ test.SRV("_http._tcp.hdls1.testns.svc.cluster.local. 303 IN SRV 0 25 80 172-0-0-3.hdls1.testns.svc.cluster.local."),
+ test.SRV("_http._tcp.hdls1.testns.svc.cluster.local. 303 IN SRV 0 25 80 5678-abcd--1.hdls1.testns.svc.cluster.local."),
+ test.SRV("_http._tcp.hdls1.testns.svc.cluster.local. 303 IN SRV 0 25 80 5678-abcd--2.hdls1.testns.svc.cluster.local."),
},
Extra: []dns.RR{
test.A("172-0-0-2.hdls1.testns.svc.cluster.local. 303 IN A 172.0.0.2"),
test.A("172-0-0-3.hdls1.testns.svc.cluster.local. 303 IN A 172.0.0.3"),
+ test.AAAA("5678-abcd--1.hdls1.testns.svc.cluster.local. 303 IN AAAA 5678:abcd::1"),
+ test.AAAA("5678-abcd--2.hdls1.testns.svc.cluster.local. 303 IN AAAA 5678:abcd::2"),
},
},
// CNAME External
@@ -106,7 +110,7 @@ var dnsTestCases = []test.Case{
test.CNAME("external.testns.svc.cluster.local. 303 IN CNAME ext.interwebs.test."),
},
},
- // AAAA Service (existing service)
+ // AAAA Service (with an existing A record, but no AAAA record)
{
Qname: "svc1.testns.svc.cluster.local.", Qtype: dns.TypeAAAA,
Rcode: dns.RcodeSuccess,
@@ -154,6 +158,31 @@ var dnsTestCases = []test.Case{
test.SOA("cluster.local. 300 IN SOA ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 60"),
},
},
+ // AAAA Service
+ {
+ Qname: "svc6.testns.svc.cluster.local.", Qtype: dns.TypeAAAA,
+ Rcode: dns.RcodeSuccess,
+ Answer: []dns.RR{
+ test.AAAA("svc6.testns.svc.cluster.local. 5 IN AAAA 1234:abcd::1"),
+ },
+ },
+ // AAAA Service (Headless)
+ {
+ Qname: "hdls1.testns.svc.cluster.local.", Qtype: dns.TypeAAAA,
+ Rcode: dns.RcodeSuccess,
+ Answer: []dns.RR{
+ test.AAAA("hdls1.testns.svc.cluster.local. 303 IN AAAA 5678:abcd::1"),
+ test.AAAA("hdls1.testns.svc.cluster.local. 303 IN AAAA 5678:abcd::2"),
+ },
+ },
+ // AAAA Endpoint
+ {
+ Qname: "5678-abcd--1.hdls1.testns.svc.cluster.local.", Qtype: dns.TypeAAAA,
+ Rcode: dns.RcodeSuccess,
+ Answer: []dns.RR{
+ test.AAAA("5678-abcd--1.hdls1.testns.svc.cluster.local. 303 IN AAAA 5678:abcd::1"),
+ },
+ },
}
func TestServeDNS(t *testing.T) {
@@ -209,264 +238,140 @@ func (APIConnServeTest) PodIndex(string) []*api.Pod {
return a
}
-func (APIConnServeTest) SvcIndex(string) []*api.Service {
- svcs := []*api.Service{
- {
- ObjectMeta: meta.ObjectMeta{
- Name: "svc1",
- Namespace: "testns",
- },
- Spec: api.ServiceSpec{
- ClusterIP: "10.0.0.1",
- Ports: []api.ServicePort{{
- Name: "http",
- Protocol: "tcp",
- Port: 80,
- }},
- },
- },
- {
- ObjectMeta: meta.ObjectMeta{
- Name: "hdls1",
- Namespace: "testns",
- },
- Spec: api.ServiceSpec{
- ClusterIP: api.ClusterIPNone,
- },
+var svcIndex = map[string][]*api.Service{
+ "svc1.testns": {{
+ ObjectMeta: meta.ObjectMeta{
+ Name: "svc1",
+ Namespace: "testns",
+ },
+ Spec: api.ServiceSpec{
+ ClusterIP: "10.0.0.1",
+ Ports: []api.ServicePort{{
+ Name: "http",
+ Protocol: "tcp",
+ Port: 80,
+ }},
+ },
+ }},
+ "svc6.testns": {{
+ ObjectMeta: meta.ObjectMeta{
+ Name: "svc6",
+ Namespace: "testns",
+ },
+ Spec: api.ServiceSpec{
+ ClusterIP: "1234:abcd::1",
+ Ports: []api.ServicePort{{
+ Name: "http",
+ Protocol: "tcp",
+ Port: 80,
+ }},
+ },
+ }},
+ "hdls1.testns": {{
+ ObjectMeta: meta.ObjectMeta{
+ Name: "hdls1",
+ Namespace: "testns",
},
- {
- ObjectMeta: meta.ObjectMeta{
- Name: "external",
- Namespace: "testns",
- },
- Spec: api.ServiceSpec{
- ExternalName: "ext.interwebs.test",
- Ports: []api.ServicePort{{
- Name: "http",
- Protocol: "tcp",
- Port: 80,
- }},
- },
+ Spec: api.ServiceSpec{
+ ClusterIP: api.ClusterIPNone,
},
- }
- return svcs
+ }},
+ "external.testns": {{
+ ObjectMeta: meta.ObjectMeta{
+ Name: "external",
+ Namespace: "testns",
+ },
+ Spec: api.ServiceSpec{
+ ExternalName: "ext.interwebs.test",
+ Ports: []api.ServicePort{{
+ Name: "http",
+ Protocol: "tcp",
+ Port: 80,
+ }},
+ },
+ }},
+}
+
+func (APIConnServeTest) SvcIndex(s string) []*api.Service {
+ return svcIndex[s]
}
func (APIConnServeTest) ServiceList() []*api.Service {
- svcs := []*api.Service{
- {
- ObjectMeta: meta.ObjectMeta{
- Name: "svc1",
- Namespace: "testns",
- },
- Spec: api.ServiceSpec{
- ClusterIP: "10.0.0.1",
- Ports: []api.ServicePort{{
- Name: "http",
- Protocol: "tcp",
- Port: 80,
- }},
- },
- },
- {
- ObjectMeta: meta.ObjectMeta{
- Name: "hdls1",
- Namespace: "testns",
- },
- Spec: api.ServiceSpec{
- ClusterIP: api.ClusterIPNone,
- },
- },
- {
- ObjectMeta: meta.ObjectMeta{
- Name: "external",
- Namespace: "testns",
- },
- Spec: api.ServiceSpec{
- ExternalName: "ext.interwebs.test",
- Ports: []api.ServicePort{{
- Name: "http",
- Protocol: "tcp",
- Port: 80,
- }},
- },
- },
+ var svcs []*api.Service
+ for _, svc := range svcIndex {
+ svcs = append(svcs, svc...)
}
return svcs
}
-func (APIConnServeTest) EpIndex(string) []*api.Endpoints {
- n := "test.node.foo.bar"
-
- eps := []*api.Endpoints{
- {
- Subsets: []api.EndpointSubset{
- {
- Addresses: []api.EndpointAddress{
- {
- IP: "172.0.0.1",
- Hostname: "ep1a",
- },
+var epsIndex = map[string][]*api.Endpoints{
+ "svc1.testns": {{
+ Subsets: []api.EndpointSubset{
+ {
+ Addresses: []api.EndpointAddress{
+ {
+ IP: "172.0.0.1",
+ Hostname: "ep1a",
},
- Ports: []api.EndpointPort{
- {
- Port: 80,
- Protocol: "tcp",
- Name: "http",
- },
+ },
+ Ports: []api.EndpointPort{
+ {
+ Port: 80,
+ Protocol: "tcp",
+ Name: "http",
},
},
},
- ObjectMeta: meta.ObjectMeta{
- Name: "svc1",
- Namespace: "testns",
- },
},
- {
- Subsets: []api.EndpointSubset{
- {
- Addresses: []api.EndpointAddress{
- {
- IP: "172.0.0.2",
- },
+ ObjectMeta: meta.ObjectMeta{
+ Name: "svc1",
+ Namespace: "testns",
+ },
+ }},
+ "hdls1.testns": {{
+ Subsets: []api.EndpointSubset{
+ {
+ Addresses: []api.EndpointAddress{
+ {
+ IP: "172.0.0.2",
},
- Ports: []api.EndpointPort{
- {
- Port: 80,
- Protocol: "tcp",
- Name: "http",
- },
+ {
+ IP: "172.0.0.3",
},
- },
- },
- ObjectMeta: meta.ObjectMeta{
- Name: "hdls1",
- Namespace: "testns",
- },
- },
- {
- Subsets: []api.EndpointSubset{
- {
- Addresses: []api.EndpointAddress{
- {
- IP: "172.0.0.3",
- },
+ {
+ IP: "5678:abcd::1",
},
- Ports: []api.EndpointPort{
- {
- Port: 80,
- Protocol: "tcp",
- Name: "http",
- },
+ {
+ IP: "5678:abcd::2",
},
},
- },
- ObjectMeta: meta.ObjectMeta{
- Name: "hdls1",
- Namespace: "testns",
- },
- },
- {
- Subsets: []api.EndpointSubset{
- {
- Addresses: []api.EndpointAddress{
- {
- IP: "10.9.8.7",
- NodeName: &n,
- },
+ Ports: []api.EndpointPort{
+ {
+ Port: 80,
+ Protocol: "tcp",
+ Name: "http",
},
},
},
},
- }
- return eps
+ ObjectMeta: meta.ObjectMeta{
+ Name: "hdls1",
+ Namespace: "testns",
+ },
+ }},
}
-func (APIConnServeTest) EndpointsList() []*api.Endpoints {
- n := "test.node.foo.bar"
+func (APIConnServeTest) EpIndex(s string) []*api.Endpoints {
+ return epsIndex[s]
+}
- eps := []*api.Endpoints{
- {
- Subsets: []api.EndpointSubset{
- {
- Addresses: []api.EndpointAddress{
- {
- IP: "172.0.0.1",
- Hostname: "ep1a",
- },
- },
- Ports: []api.EndpointPort{
- {
- Port: 80,
- Protocol: "tcp",
- Name: "http",
- },
- },
- },
- },
- ObjectMeta: meta.ObjectMeta{
- Name: "svc1",
- Namespace: "testns",
- },
- },
- {
- Subsets: []api.EndpointSubset{
- {
- Addresses: []api.EndpointAddress{
- {
- IP: "172.0.0.2",
- },
- },
- Ports: []api.EndpointPort{
- {
- Port: 80,
- Protocol: "tcp",
- Name: "http",
- },
- },
- },
- },
- ObjectMeta: meta.ObjectMeta{
- Name: "hdls1",
- Namespace: "testns",
- },
- },
- {
- Subsets: []api.EndpointSubset{
- {
- Addresses: []api.EndpointAddress{
- {
- IP: "172.0.0.3",
- },
- },
- Ports: []api.EndpointPort{
- {
- Port: 80,
- Protocol: "tcp",
- Name: "http",
- },
- },
- },
- },
- ObjectMeta: meta.ObjectMeta{
- Name: "hdls1",
- Namespace: "testns",
- },
- },
- {
- Subsets: []api.EndpointSubset{
- {
- Addresses: []api.EndpointAddress{
- {
- IP: "10.9.8.7",
- NodeName: &n,
- },
- },
- },
- },
- },
+func (APIConnServeTest) EndpointsList() []*api.Endpoints {
+ var eps []*api.Endpoints
+ for _, ep := range epsIndex {
+ eps = append(eps, ep...)
}
return eps
+
}
func (APIConnServeTest) GetNodeByName(name string) (*api.Node, error) {