mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 02:03:20 -04:00 
			
		
		
		
	Add txt response per k8s spec
This commit is contained in:
		| @@ -44,8 +44,9 @@ type Kubernetes struct { | |||||||
| } | } | ||||||
|  |  | ||||||
| const ( | const ( | ||||||
| 	PodModeDisabled = "disabled" // default. pod requests are ignored | 	PodModeDisabled  = "disabled" // default. pod requests are ignored | ||||||
| 	PodModeInsecure = "insecure" // ALL pod requests are answered without verfying they exist | 	PodModeInsecure  = "insecure" // ALL pod requests are answered without verfying they exist | ||||||
|  | 	DnsSchemaVersion = "1.0.0"    // https://github.com/kubernetes/dns/blob/master/docs/specification.md | ||||||
| ) | ) | ||||||
|  |  | ||||||
| type endpoint struct { | type endpoint struct { | ||||||
| @@ -82,8 +83,28 @@ func (k *Kubernetes) Services(state request.Request, exact bool, opt middleware. | |||||||
| 	if e != nil { | 	if e != nil { | ||||||
| 		return nil, nil, e | 		return nil, nil, e | ||||||
| 	} | 	} | ||||||
| 	s, e := k.Records(r) |  | ||||||
| 	return s, nil, e // Haven't implemented debug queries yet. | 	switch state.Type() { | ||||||
|  | 	case "A", "SRV": | ||||||
|  | 		s, e := k.Records(r) | ||||||
|  | 		return s, nil, e // Haven't implemented debug queries yet. | ||||||
|  | 	case "TXT": | ||||||
|  | 		s, e := k.recordsForTXT(r) | ||||||
|  | 		return s, nil, e | ||||||
|  | 	} | ||||||
|  | 	return nil, nil, nil | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func (k *Kubernetes) recordsForTXT(r recordRequest) ([]msg.Service, error) { | ||||||
|  | 	switch r.typeName { | ||||||
|  | 	case "dns-version": | ||||||
|  | 		s := msg.Service{ | ||||||
|  | 			Text: DnsSchemaVersion, | ||||||
|  | 			TTL:  28800, | ||||||
|  | 			Key:  msg.Path(r.typeName+"."+r.zone, "coredns")} | ||||||
|  | 		return []msg.Service{s}, nil | ||||||
|  | 	} | ||||||
|  | 	return nil, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| // PrimaryZone will return the first non-reverse zone being handled by this middleware | // PrimaryZone will return the first non-reverse zone being handled by this middleware | ||||||
| @@ -253,6 +274,11 @@ func (k *Kubernetes) parseRequest(lowerCasedName, qtype string) (r recordRequest | |||||||
| 		return r, nil | 		return r, nil | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	if len(segs) == 1 && qtype == "TXT" { | ||||||
|  | 		r.typeName = segs[0] | ||||||
|  | 		return r, nil | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	return r, errors.New("invalid request") | 	return r, errors.New("invalid request") | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -218,6 +218,13 @@ var dnsTestCases = []test.Case{ | |||||||
| 			test.PTR("115.0.0.10.in-addr.arpa.      303    IN      PTR       svc-c.test-1.svc.cluster.local."), | 			test.PTR("115.0.0.10.in-addr.arpa.      303    IN      PTR       svc-c.test-1.svc.cluster.local."), | ||||||
| 		}, | 		}, | ||||||
| 	}, | 	}, | ||||||
|  | 	{ | ||||||
|  | 		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.0\""), | ||||||
|  | 		}, | ||||||
|  | 	}, | ||||||
| } | } | ||||||
|  |  | ||||||
| var dnsTestCasesPodsInsecure = []test.Case{ | var dnsTestCasesPodsInsecure = []test.Case{ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user