| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | package kubernetes | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-21 15:15:47 +01:00
										 |  |  | 	"github.com/coredns/coredns/plugin/pkg/dnstest" | 
					
						
							| 
									
										
										
										
											2017-09-14 09:36:06 +01:00
										 |  |  | 	"github.com/coredns/coredns/plugin/test" | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/miekg/dns" | 
					
						
							|  |  |  | 	"golang.org/x/net/context" | 
					
						
							| 
									
										
										
										
											2018-01-03 19:11:28 +08:00
										 |  |  | 	api "k8s.io/api/core/v1" | 
					
						
							| 
									
										
										
										
											2017-09-29 15:58:50 -04:00
										 |  |  | 	meta "k8s.io/apimachinery/pkg/apis/meta/v1" | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-02 18:49:50 +02:00
										 |  |  | var dnsTestCases = []test.Case{ | 
					
						
							|  |  |  | 	// A Service | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 		Qname: "svc1.testns.svc.cluster.local.", Qtype: dns.TypeA, | 
					
						
							|  |  |  | 		Rcode: dns.RcodeSuccess, | 
					
						
							|  |  |  | 		Answer: []dns.RR{ | 
					
						
							| 
									
										
										
										
											2017-08-27 01:32:46 +01:00
										 |  |  | 			test.A("svc1.testns.svc.cluster.local.	5	IN	A	10.0.0.1"), | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2017-09-02 18:49:50 +02:00
										 |  |  | 	// A Service (wildcard) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-08-22 20:44:42 +01:00
										 |  |  | 		Qname: "svc1.*.svc.cluster.local.", Qtype: dns.TypeA, | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 		Rcode: dns.RcodeSuccess, | 
					
						
							|  |  |  | 		Answer: []dns.RR{ | 
					
						
							| 
									
										
										
										
											2017-08-27 01:32:46 +01:00
										 |  |  | 			test.A("svc1.*.svc.cluster.local.  5       IN      A       10.0.0.1"), | 
					
						
							| 
									
										
										
										
											2017-08-22 20:44:42 +01:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2017-09-02 18:49:50 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-09-01 02:55:09 -04:00
										 |  |  | 		Qname: "svc1.testns.svc.cluster.local.", Qtype: dns.TypeSRV, | 
					
						
							|  |  |  | 		Rcode: dns.RcodeSuccess, | 
					
						
							| 
									
										
										
										
											2017-11-15 15:04:17 +00:00
										 |  |  | 		Answer: []dns.RR{test.SRV("svc1.testns.svc.cluster.local.	5	IN	SRV	0 100 80 svc1.testns.svc.cluster.local.")}, | 
					
						
							|  |  |  | 		Extra: []dns.RR{test.A("svc1.testns.svc.cluster.local.  5       IN      A       10.0.0.1")}, | 
					
						
							| 
									
										
										
										
											2017-09-01 02:55:09 -04:00
										 |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2017-09-02 18:49:50 +02:00
										 |  |  | 	// SRV Service (wildcard) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-08-22 20:44:42 +01:00
										 |  |  | 		Qname: "svc1.*.svc.cluster.local.", Qtype: dns.TypeSRV, | 
					
						
							|  |  |  | 		Rcode: dns.RcodeSuccess, | 
					
						
							| 
									
										
										
										
											2017-11-15 15:04:17 +00:00
										 |  |  | 		Answer: []dns.RR{test.SRV("svc1.*.svc.cluster.local.	5	IN	SRV	0 100 80 svc1.testns.svc.cluster.local.")}, | 
					
						
							|  |  |  | 		Extra: []dns.RR{test.A("svc1.testns.svc.cluster.local.  5       IN      A       10.0.0.1")}, | 
					
						
							| 
									
										
										
										
											2017-08-22 20:44:42 +01:00
										 |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2017-09-02 18:49:50 +02:00
										 |  |  | 	// SRV Service (wildcards) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-08-22 20:44:42 +01:00
										 |  |  | 		Qname: "*.any.svc1.*.svc.cluster.local.", Qtype: dns.TypeSRV, | 
					
						
							|  |  |  | 		Rcode: dns.RcodeSuccess, | 
					
						
							| 
									
										
										
										
											2017-11-15 15:04:17 +00:00
										 |  |  | 		Answer: []dns.RR{test.SRV("*.any.svc1.*.svc.cluster.local.	5	IN	SRV	0 100 80 svc1.testns.svc.cluster.local.")}, | 
					
						
							|  |  |  | 		Extra: []dns.RR{test.A("svc1.testns.svc.cluster.local.  5       IN      A       10.0.0.1")}, | 
					
						
							| 
									
										
										
										
											2017-08-22 20:44:42 +01:00
										 |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2017-09-02 18:49:50 +02:00
										 |  |  | 	// A Service (wildcards) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-08-22 20:44:42 +01:00
										 |  |  | 		Qname: "*.any.svc1.*.svc.cluster.local.", Qtype: dns.TypeA, | 
					
						
							|  |  |  | 		Rcode: dns.RcodeSuccess, | 
					
						
							|  |  |  | 		Answer: []dns.RR{ | 
					
						
							| 
									
										
										
										
											2017-11-15 15:04:17 +00:00
										 |  |  | 			test.A("*.any.svc1.*.svc.cluster.local.  5       IN      A       10.0.0.1"), | 
					
						
							| 
									
										
										
										
											2017-08-22 20:44:42 +01:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2017-09-02 18:49:50 +02:00
										 |  |  | 	// SRV Service Not udp/tcp | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-08-22 20:44:42 +01:00
										 |  |  | 		Qname: "*._not-udp-or-tcp.svc1.testns.svc.cluster.local.", Qtype: dns.TypeSRV, | 
					
						
							| 
									
										
										
										
											2017-08-23 07:19:41 +01:00
										 |  |  | 		Rcode: dns.RcodeNameError, | 
					
						
							| 
									
										
										
										
											2017-08-22 20:44:42 +01:00
										 |  |  | 		Ns: []dns.RR{ | 
					
						
							|  |  |  | 			test.SOA("cluster.local.	300	IN	SOA	ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 60"), | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2017-09-02 18:49:50 +02:00
										 |  |  | 	// SRV Service | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 		Qname: "_http._tcp.svc1.testns.svc.cluster.local.", Qtype: dns.TypeSRV, | 
					
						
							|  |  |  | 		Rcode: dns.RcodeSuccess, | 
					
						
							|  |  |  | 		Answer: []dns.RR{ | 
					
						
							| 
									
										
										
										
											2017-11-15 15:04:17 +00:00
										 |  |  | 			test.SRV("_http._tcp.svc1.testns.svc.cluster.local.	5	IN	SRV	0 100 80 svc1.testns.svc.cluster.local."), | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		Extra: []dns.RR{ | 
					
						
							| 
									
										
										
										
											2017-11-15 15:04:17 +00:00
										 |  |  | 			test.A("svc1.testns.svc.cluster.local.	5	IN	A	10.0.0.1"), | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2017-09-02 18:49:50 +02:00
										 |  |  | 	// A Service (Headless) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-08-22 20:44:42 +01:00
										 |  |  | 		Qname: "hdls1.testns.svc.cluster.local.", Qtype: dns.TypeA, | 
					
						
							|  |  |  | 		Rcode: dns.RcodeSuccess, | 
					
						
							|  |  |  | 		Answer: []dns.RR{ | 
					
						
							| 
									
										
										
										
											2017-11-15 15:04:17 +00:00
										 |  |  | 			test.A("hdls1.testns.svc.cluster.local.	5	IN	A	172.0.0.2"), | 
					
						
							|  |  |  | 			test.A("hdls1.testns.svc.cluster.local.	5	IN	A	172.0.0.3"), | 
					
						
							| 
									
										
										
										
											2017-08-22 20:44:42 +01:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2017-12-14 13:14:10 -06:00
										 |  |  | 	// A pod ip | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		Qname: "172-0-0-2.hdls1.testns.svc.cluster.local.", Qtype: dns.TypeA, | 
					
						
							|  |  |  | 		Rcode: dns.RcodeSuccess, | 
					
						
							|  |  |  | 		Answer: []dns.RR{ | 
					
						
							|  |  |  | 			test.A("172-0-0-2.hdls1.testns.svc.cluster.local.	5	IN	A	172.0.0.2"), | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	// A pod ip | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		Qname: "172-0-0-3.hdls1.testns.svc.cluster.local.", Qtype: dns.TypeA, | 
					
						
							|  |  |  | 		Rcode: dns.RcodeSuccess, | 
					
						
							|  |  |  | 		Answer: []dns.RR{ | 
					
						
							|  |  |  | 			test.A("172-0-0-3.hdls1.testns.svc.cluster.local.	5	IN	A	172.0.0.3"), | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2017-09-02 18:49:50 +02:00
										 |  |  | 	// SRV Service (Headless) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 		Qname: "_http._tcp.hdls1.testns.svc.cluster.local.", Qtype: dns.TypeSRV, | 
					
						
							|  |  |  | 		Rcode: dns.RcodeSuccess, | 
					
						
							|  |  |  | 		Answer: []dns.RR{ | 
					
						
							| 
									
										
										
										
											2017-11-15 15:04:17 +00:00
										 |  |  | 			test.SRV("_http._tcp.hdls1.testns.svc.cluster.local.	5	IN	SRV	0 25 80 172-0-0-2.hdls1.testns.svc.cluster.local."), | 
					
						
							|  |  |  | 			test.SRV("_http._tcp.hdls1.testns.svc.cluster.local.	5	IN	SRV	0 25 80 172-0-0-3.hdls1.testns.svc.cluster.local."), | 
					
						
							|  |  |  | 			test.SRV("_http._tcp.hdls1.testns.svc.cluster.local.	5	IN	SRV	0 25 80 5678-abcd--1.hdls1.testns.svc.cluster.local."), | 
					
						
							|  |  |  | 			test.SRV("_http._tcp.hdls1.testns.svc.cluster.local.	5	IN	SRV	0 25 80 5678-abcd--2.hdls1.testns.svc.cluster.local."), | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 		Extra: []dns.RR{ | 
					
						
							| 
									
										
										
										
											2017-11-15 15:04:17 +00:00
										 |  |  | 			test.A("172-0-0-2.hdls1.testns.svc.cluster.local.	5	IN	A	172.0.0.2"), | 
					
						
							|  |  |  | 			test.A("172-0-0-3.hdls1.testns.svc.cluster.local.	5	IN	A	172.0.0.3"), | 
					
						
							|  |  |  | 			test.AAAA("5678-abcd--1.hdls1.testns.svc.cluster.local.	5	IN	AAAA	5678:abcd::1"), | 
					
						
							|  |  |  | 			test.AAAA("5678-abcd--2.hdls1.testns.svc.cluster.local.	5	IN	AAAA	5678:abcd::2"), | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2017-12-14 13:14:10 -06:00
										 |  |  | 	// AAAA | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		Qname: "5678-abcd--2.hdls1.testns.svc.cluster.local", Qtype: dns.TypeAAAA, | 
					
						
							|  |  |  | 		Rcode: dns.RcodeSuccess, | 
					
						
							|  |  |  | 		Answer: []dns.RR{test.AAAA("5678-abcd--2.hdls1.testns.svc.cluster.local.	5	IN	AAAA	5678:abcd::2")}, | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2017-09-02 18:49:50 +02:00
										 |  |  | 	// CNAME External | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 		Qname: "external.testns.svc.cluster.local.", Qtype: dns.TypeCNAME, | 
					
						
							|  |  |  | 		Rcode: dns.RcodeSuccess, | 
					
						
							|  |  |  | 		Answer: []dns.RR{ | 
					
						
							| 
									
										
										
										
											2017-11-15 15:04:17 +00:00
										 |  |  | 			test.CNAME("external.testns.svc.cluster.local.	5	IN	CNAME	ext.interwebs.test."), | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2017-11-15 02:16:04 -05:00
										 |  |  | 	// AAAA Service (with an existing A record, but no AAAA record) | 
					
						
							| 
									
										
										
										
											2017-09-02 18:49:50 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-07-20 08:19:29 -04:00
										 |  |  | 		Qname: "svc1.testns.svc.cluster.local.", Qtype: dns.TypeAAAA, | 
					
						
							| 
									
										
										
										
											2017-08-23 07:19:41 +01:00
										 |  |  | 		Rcode: dns.RcodeSuccess, | 
					
						
							| 
									
										
										
										
											2017-07-20 08:19:29 -04:00
										 |  |  | 		Ns: []dns.RR{ | 
					
						
							|  |  |  | 			test.SOA("cluster.local.	300	IN	SOA	ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 60"), | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2017-09-02 18:49:50 +02:00
										 |  |  | 	// AAAA Service (non-existing service) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-07-20 08:19:29 -04:00
										 |  |  | 		Qname: "svc0.testns.svc.cluster.local.", Qtype: dns.TypeAAAA, | 
					
						
							| 
									
										
										
										
											2017-08-23 07:19:41 +01:00
										 |  |  | 		Rcode: dns.RcodeNameError, | 
					
						
							|  |  |  | 		Ns: []dns.RR{ | 
					
						
							|  |  |  | 			test.SOA("cluster.local.	300	IN	SOA	ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 60"), | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2017-09-02 18:49:50 +02:00
										 |  |  | 	// A Service (non-existing service) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-08-23 07:19:41 +01:00
										 |  |  | 		Qname: "svc0.testns.svc.cluster.local.", Qtype: dns.TypeA, | 
					
						
							|  |  |  | 		Rcode: dns.RcodeNameError, | 
					
						
							| 
									
										
										
										
											2017-07-20 08:19:29 -04:00
										 |  |  | 		Ns: []dns.RR{ | 
					
						
							|  |  |  | 			test.SOA("cluster.local.	300	IN	SOA	ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 60"), | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2018-01-05 17:53:26 +00:00
										 |  |  | 	// A Service (non-existing namespace) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		Qname: "svc0.svc-nons.svc.cluster.local.", Qtype: dns.TypeA, | 
					
						
							|  |  |  | 		Rcode: dns.RcodeNameError, | 
					
						
							|  |  |  | 		Ns: []dns.RR{ | 
					
						
							|  |  |  | 			test.SOA("cluster.local.	300	IN	SOA	ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 60"), | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2017-09-02 18:49:50 +02:00
										 |  |  | 	// TXT Schema | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-08-02 12:42:15 -04:00
										 |  |  | 		Qname: "dns-version.cluster.local.", Qtype: dns.TypeTXT, | 
					
						
							|  |  |  | 		Rcode: dns.RcodeSuccess, | 
					
						
							|  |  |  | 		Answer: []dns.RR{ | 
					
						
							|  |  |  | 			test.TXT("dns-version.cluster.local 28800 IN TXT 1.0.1"), | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2017-09-02 18:49:50 +02:00
										 |  |  | 	// A Service (Headless) does not exist | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-08-23 07:19:41 +01:00
										 |  |  | 		Qname: "bogusendpoint.hdls1.testns.svc.cluster.local.", Qtype: dns.TypeA, | 
					
						
							|  |  |  | 		Rcode: dns.RcodeNameError, | 
					
						
							|  |  |  | 		Ns: []dns.RR{ | 
					
						
							|  |  |  | 			test.SOA("cluster.local.	300	IN	SOA	ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 60"), | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2017-09-02 18:49:50 +02:00
										 |  |  | 	// A Service does not exist | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-08-23 07:19:41 +01:00
										 |  |  | 		Qname: "bogusendpoint.svc0.testns.svc.cluster.local.", Qtype: dns.TypeA, | 
					
						
							|  |  |  | 		Rcode: dns.RcodeNameError, | 
					
						
							|  |  |  | 		Ns: []dns.RR{ | 
					
						
							|  |  |  | 			test.SOA("cluster.local.	300	IN	SOA	ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 60"), | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2017-11-15 02:16:04 -05:00
										 |  |  | 	// 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"), | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2017-12-14 13:14:10 -06:00
										 |  |  | 	// SRV | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		Qname: "_http._tcp.svc6.testns.svc.cluster.local.", Qtype: dns.TypeSRV, | 
					
						
							|  |  |  | 		Rcode: dns.RcodeSuccess, | 
					
						
							|  |  |  | 		Answer: []dns.RR{ | 
					
						
							|  |  |  | 			test.SRV("_http._tcp.svc6.testns.svc.cluster.local.	5	IN	SRV	0 100 80 svc6.testns.svc.cluster.local."), | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		Extra: []dns.RR{ | 
					
						
							|  |  |  | 			test.AAAA("svc6.testns.svc.cluster.local.	5	IN	AAAA	1234:abcd::1"), | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2017-11-15 02:16:04 -05:00
										 |  |  | 	// AAAA Service (Headless) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		Qname: "hdls1.testns.svc.cluster.local.", Qtype: dns.TypeAAAA, | 
					
						
							|  |  |  | 		Rcode: dns.RcodeSuccess, | 
					
						
							|  |  |  | 		Answer: []dns.RR{ | 
					
						
							| 
									
										
										
										
											2017-11-15 15:04:17 +00:00
										 |  |  | 			test.AAAA("hdls1.testns.svc.cluster.local.	5	IN	AAAA	5678:abcd::1"), | 
					
						
							|  |  |  | 			test.AAAA("hdls1.testns.svc.cluster.local.	5	IN	AAAA	5678:abcd::2"), | 
					
						
							| 
									
										
										
										
											2017-11-15 02:16:04 -05:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	// AAAA Endpoint | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		Qname: "5678-abcd--1.hdls1.testns.svc.cluster.local.", Qtype: dns.TypeAAAA, | 
					
						
							|  |  |  | 		Rcode: dns.RcodeSuccess, | 
					
						
							|  |  |  | 		Answer: []dns.RR{ | 
					
						
							| 
									
										
										
										
											2017-11-15 15:04:17 +00:00
										 |  |  | 			test.AAAA("5678-abcd--1.hdls1.testns.svc.cluster.local.	5	IN	AAAA	5678:abcd::1"), | 
					
						
							| 
									
										
										
										
											2017-11-15 02:16:04 -05:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestServeDNS(t *testing.T) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-18 14:45:20 +01:00
										 |  |  | 	k := New([]string{"cluster.local."}) | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 	k.APIConn = &APIConnServeTest{} | 
					
						
							| 
									
										
										
										
											2017-08-07 14:45:30 -07:00
										 |  |  | 	k.Next = test.NextHandler(dns.RcodeSuccess, nil) | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 	ctx := context.TODO() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-02 18:49:50 +02:00
										 |  |  | 	for i, tc := range dnsTestCases { | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 		r := tc.Msg() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-21 15:15:47 +01:00
										 |  |  | 		w := dnstest.NewRecorder(&test.ResponseWriter{}) | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		_, err := k.ServeDNS(ctx, w, r) | 
					
						
							| 
									
										
										
										
											2017-08-03 15:16:50 -04:00
										 |  |  | 		if err != tc.Error { | 
					
						
							| 
									
										
										
										
											2017-09-02 18:49:50 +02:00
										 |  |  | 			t.Errorf("Test %d expected no error, got %v", i, err) | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 			return | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-08-03 15:16:50 -04:00
										 |  |  | 		if tc.Error != nil { | 
					
						
							|  |  |  | 			continue | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		resp := w.Msg | 
					
						
							| 
									
										
										
										
											2017-08-07 14:45:30 -07:00
										 |  |  | 		if resp == nil { | 
					
						
							| 
									
										
										
										
											2017-09-02 18:49:50 +02:00
										 |  |  | 			t.Fatalf("Test %d, got nil message and no error for %q", i, r.Question[0].Name) | 
					
						
							| 
									
										
										
										
											2017-08-07 14:45:30 -07:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// Before sorting, make sure that CNAMES do not appear after their target records | 
					
						
							| 
									
										
										
										
											2017-08-24 11:05:16 -04:00
										 |  |  | 		test.CNAMEOrder(t, resp) | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-16 15:30:58 +01:00
										 |  |  | 		test.SortAndCheck(t, resp, tc) | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type APIConnServeTest struct{} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-20 22:53:17 +01:00
										 |  |  | func (APIConnServeTest) HasSynced() bool                        { return true } | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | func (APIConnServeTest) Run()                                   { return } | 
					
						
							|  |  |  | func (APIConnServeTest) Stop() error                            { return nil } | 
					
						
							|  |  |  | func (APIConnServeTest) EpIndexReverse(string) []*api.Endpoints { return nil } | 
					
						
							|  |  |  | func (APIConnServeTest) SvcIndexReverse(string) []*api.Service  { return nil } | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-29 15:58:50 -04:00
										 |  |  | func (APIConnServeTest) PodIndex(string) []*api.Pod { | 
					
						
							|  |  |  | 	a := []*api.Pod{{ | 
					
						
							|  |  |  | 		ObjectMeta: meta.ObjectMeta{ | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 			Namespace: "podns", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 		Status: api.PodStatus{ | 
					
						
							|  |  |  | 			PodIP: "10.240.0.1", // Remote IP set in test.ResponseWriter | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2017-09-29 15:58:50 -04:00
										 |  |  | 	}} | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 	return a | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-15 02:16:04 -05:00
										 |  |  | 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", | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2017-11-15 02:16:04 -05:00
										 |  |  | 		Spec: api.ServiceSpec{ | 
					
						
							|  |  |  | 			ClusterIP: api.ClusterIPNone, | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2017-11-15 02:16:04 -05:00
										 |  |  | 	}}, | 
					
						
							|  |  |  | 	"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, | 
					
						
							|  |  |  | 			}}, | 
					
						
							| 
									
										
										
										
											2017-11-22 06:17:27 -05:00
										 |  |  | 			Type: api.ServiceTypeExternalName, | 
					
						
							| 
									
										
										
										
											2017-11-15 02:16:04 -05:00
										 |  |  | 		}, | 
					
						
							|  |  |  | 	}}, | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func (APIConnServeTest) SvcIndex(s string) []*api.Service { | 
					
						
							|  |  |  | 	return svcIndex[s] | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | func (APIConnServeTest) ServiceList() []*api.Service { | 
					
						
							| 
									
										
										
										
											2017-11-15 02:16:04 -05:00
										 |  |  | 	var svcs []*api.Service | 
					
						
							|  |  |  | 	for _, svc := range svcIndex { | 
					
						
							|  |  |  | 		svcs = append(svcs, svc...) | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return svcs | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-15 02:16:04 -05:00
										 |  |  | var epsIndex = map[string][]*api.Endpoints{ | 
					
						
							|  |  |  | 	"svc1.testns": {{ | 
					
						
							|  |  |  | 		Subsets: []api.EndpointSubset{ | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				Addresses: []api.EndpointAddress{ | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						IP:       "172.0.0.1", | 
					
						
							|  |  |  | 						Hostname: "ep1a", | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | 					}, | 
					
						
							| 
									
										
										
										
											2017-11-15 02:16:04 -05:00
										 |  |  | 				}, | 
					
						
							|  |  |  | 				Ports: []api.EndpointPort{ | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						Port:     80, | 
					
						
							|  |  |  | 						Protocol: "tcp", | 
					
						
							|  |  |  | 						Name:     "http", | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | 					}, | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2017-11-15 02:16:04 -05:00
										 |  |  | 		ObjectMeta: meta.ObjectMeta{ | 
					
						
							|  |  |  | 			Name:      "svc1", | 
					
						
							|  |  |  | 			Namespace: "testns", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	}}, | 
					
						
							|  |  |  | 	"hdls1.testns": {{ | 
					
						
							|  |  |  | 		Subsets: []api.EndpointSubset{ | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				Addresses: []api.EndpointAddress{ | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						IP: "172.0.0.2", | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | 					}, | 
					
						
							| 
									
										
										
										
											2017-11-15 02:16:04 -05:00
										 |  |  | 					{ | 
					
						
							|  |  |  | 						IP: "172.0.0.3", | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | 					}, | 
					
						
							| 
									
										
										
										
											2017-11-15 02:16:04 -05:00
										 |  |  | 					{ | 
					
						
							|  |  |  | 						IP: "5678:abcd::1", | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | 					}, | 
					
						
							| 
									
										
										
										
											2017-11-15 02:16:04 -05:00
										 |  |  | 					{ | 
					
						
							|  |  |  | 						IP: "5678:abcd::2", | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | 					}, | 
					
						
							|  |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2017-11-15 02:16:04 -05:00
										 |  |  | 				Ports: []api.EndpointPort{ | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						Port:     80, | 
					
						
							|  |  |  | 						Protocol: "tcp", | 
					
						
							|  |  |  | 						Name:     "http", | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | 					}, | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2017-11-15 02:16:04 -05:00
										 |  |  | 		ObjectMeta: meta.ObjectMeta{ | 
					
						
							|  |  |  | 			Name:      "hdls1", | 
					
						
							|  |  |  | 			Namespace: "testns", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	}}, | 
					
						
							| 
									
										
										
										
											2017-10-17 21:30:54 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-15 02:16:04 -05:00
										 |  |  | func (APIConnServeTest) EpIndex(s string) []*api.Endpoints { | 
					
						
							|  |  |  | 	return epsIndex[s] | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-15 02:16:04 -05:00
										 |  |  | func (APIConnServeTest) EndpointsList() []*api.Endpoints { | 
					
						
							|  |  |  | 	var eps []*api.Endpoints | 
					
						
							|  |  |  | 	for _, ep := range epsIndex { | 
					
						
							|  |  |  | 		eps = append(eps, ep...) | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-09-29 15:58:50 -04:00
										 |  |  | 	return eps | 
					
						
							| 
									
										
										
										
											2017-11-15 02:16:04 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-29 15:58:50 -04:00
										 |  |  | func (APIConnServeTest) GetNodeByName(name string) (*api.Node, error) { | 
					
						
							|  |  |  | 	return &api.Node{ | 
					
						
							|  |  |  | 		ObjectMeta: meta.ObjectMeta{ | 
					
						
							| 
									
										
										
										
											2017-07-11 18:05:32 -04:00
										 |  |  | 			Name: "test.node.foo.bar", | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	}, nil | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-11-13 21:51:51 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | func (APIConnServeTest) GetNamespaceByName(name string) (*api.Namespace, error) { | 
					
						
							| 
									
										
										
										
											2017-12-15 15:31:57 -06:00
										 |  |  | 	if name == "pod-nons" { // handler_pod_verified_test.go uses this for non-existent namespace. | 
					
						
							| 
									
										
										
										
											2017-11-13 21:51:51 +00:00
										 |  |  | 		return &api.Namespace{}, nil | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return &api.Namespace{ | 
					
						
							|  |  |  | 		ObjectMeta: meta.ObjectMeta{ | 
					
						
							|  |  |  | 			Name: name, | 
					
						
							|  |  |  | 		}, | 
					
						
							|  |  |  | 	}, nil | 
					
						
							|  |  |  | } |