mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 10:13:14 -04:00 
			
		
		
		
	middleware/kubernetes: fix aaaa response (#780)
* fix aaaa response * unit tests
This commit is contained in:
		
				
					committed by
					
						 John Belamaric
						John Belamaric
					
				
			
			
				
	
			
			
			
						parent
						
							81315b0b3b
						
					
				
				
					commit
					58006cf847
				
			| @@ -57,7 +57,7 @@ func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M | ||||
| 				path = strings.Join(dns.SplitDomainName(path)[1:], ".") | ||||
| 				newstate := state.NewWithQuestion(strings.Join([]string{name, path}, "."), state.QType()) | ||||
| 				records, extra, _, err = k.routeRequest(zone, newstate) | ||||
| 				if !k.IsNameError(err) { | ||||
| 				if !k.IsNameError(err) && len(records) > 0 { | ||||
| 					records = append(records, nil) | ||||
| 					copy(records[1:], records) | ||||
| 					records[0] = newCNAME(origQName, records[0].Header().Name, records[0].Header().Ttl) | ||||
| @@ -79,7 +79,7 @@ func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M | ||||
| 			// Search . in this middleware | ||||
| 			newstate := state.NewWithQuestion(strings.Join([]string{name, "."}, ""), state.QType()) | ||||
| 			records, extra, _, err = k.routeRequest(zone, newstate) | ||||
| 			if !k.IsNameError(err) { | ||||
| 			if !k.IsNameError(err) && len(records) > 0 { | ||||
| 				records = append(records, nil) | ||||
| 				copy(records[1:], records) | ||||
| 				records[0] = newCNAME(origQName, records[0].Header().Name, records[0].Header().Ttl) | ||||
|   | ||||
| @@ -81,6 +81,22 @@ var dnsTestCases = map[string](*test.Case){ | ||||
| 			test.CNAME("svc0.testns.fed.svc.cluster.local.	0	IN	CNAME	svc0.testns.fed.svc.fd-az.fd-r.federal.test."), | ||||
| 		}, | ||||
| 	}, | ||||
| 	"AAAA Service (existing service)": { | ||||
| 		Qname: "svc1.testns.svc.cluster.local.", Qtype: dns.TypeAAAA, | ||||
| 		Rcode:  dns.RcodeSuccess, | ||||
| 		Answer: []dns.RR{}, | ||||
| 		Ns: []dns.RR{ | ||||
| 			test.SOA("cluster.local.	300	IN	SOA	ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 60"), | ||||
| 		}, | ||||
| 	}, | ||||
| 	"AAAA Service (non-existing service)": { | ||||
| 		Qname: "svc0.testns.svc.cluster.local.", Qtype: dns.TypeAAAA, | ||||
| 		Rcode:  dns.RcodeNameError, | ||||
| 		Answer: []dns.RR{}, | ||||
| 		Ns: []dns.RR{ | ||||
| 			test.SOA("cluster.local.	300	IN	SOA	ns.dns.cluster.local. hostmaster.cluster.local. 1499347823 7200 1800 86400 60"), | ||||
| 		}, | ||||
| 	}, | ||||
| } | ||||
|  | ||||
| var autopathCases = map[string](*test.Case){ | ||||
|   | ||||
| @@ -115,10 +115,7 @@ func (k *Kubernetes) Services(state request.Request, exact bool, opt middleware. | ||||
| 		return nil, nil, e | ||||
| 	} | ||||
| 	switch state.Type() { | ||||
| 	case "AAAA": | ||||
| 		// AAAA not implemented | ||||
| 		return nil, nil, errNoItems | ||||
| 	case "A", "CNAME": | ||||
| 	case "A", "AAAA", "CNAME": | ||||
| 		if state.Type() == "A" && isDefaultNS(state.Name(), r) { | ||||
| 			// If this is an A request for "ns.dns", respond with a "fake" record for coredns. | ||||
| 			// SOA records always use this hardcoded name | ||||
| @@ -126,6 +123,10 @@ func (k *Kubernetes) Services(state request.Request, exact bool, opt middleware. | ||||
| 			return svcs, nil, nil | ||||
| 		} | ||||
| 		s, e := k.Entries(r) | ||||
| 		if state.QType() == dns.TypeAAAA { | ||||
| 			// AAAA not implemented | ||||
| 			return nil, nil, e | ||||
| 		} | ||||
| 		return s, nil, e // Haven't implemented debug queries yet. | ||||
| 	case "SRV": | ||||
| 		s, e := k.Entries(r) | ||||
| @@ -325,8 +326,8 @@ func (k *Kubernetes) parseRequest(lowerCasedName string, qtype uint16) (r record | ||||
| 		} | ||||
| 		offset = 2 | ||||
| 	} | ||||
| 	if qtype == dns.TypeA && len(segs) == 4 { | ||||
| 		// This is an endpoint A record request. Get first element as endpoint. | ||||
| 	if (qtype == dns.TypeA || qtype == dns.TypeAAAA) && len(segs) == 4 { | ||||
| 		// This is an endpoint A/AAAA record request. Get first element as endpoint. | ||||
| 		r.endpoint = segs[0] | ||||
| 		offset = 1 | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user