aboutsummaryrefslogtreecommitdiff
path: root/plugin/backend_lookup.go
diff options
context:
space:
mode:
authorGravatar Bingshen Wang <bingshen.wbs@gmail.com> 2018-08-25 20:53:41 +0800
committerGravatar Chris O'Haver <cohaver@infoblox.com> 2018-08-25 08:53:41 -0400
commit75f1b9c988e036a56f0ae31224401aa9b652e9ef (patch)
tree31ad62f8b868c76f66abc49b764b2fe98da0710c /plugin/backend_lookup.go
parent610bdc091de5383e7a08633fa99b479b76c81402 (diff)
downloadcoredns-75f1b9c988e036a56f0ae31224401aa9b652e9ef.tar.gz
coredns-75f1b9c988e036a56f0ae31224401aa9b652e9ef.tar.zst
coredns-75f1b9c988e036a56f0ae31224401aa9b652e9ef.zip
fix kubernetes in-cluster CNAME lookup (#2040)
fix #2038 Signed-off-by: bingshen.wbs <bingshen.wbs@alibaba-inc.com>
Diffstat (limited to 'plugin/backend_lookup.go')
-rw-r--r--plugin/backend_lookup.go45
1 files changed, 22 insertions, 23 deletions
diff --git a/plugin/backend_lookup.go b/plugin/backend_lookup.go
index 3946c9fee..002d1855b 100644
--- a/plugin/backend_lookup.go
+++ b/plugin/backend_lookup.go
@@ -40,24 +40,22 @@ func A(b ServiceBackend, zone string, state request.Request, previousRecords []d
if dnsutil.DuplicateCNAME(newRecord, previousRecords) {
continue
}
-
- state1 := state.NewWithQuestion(serv.Host, state.QType())
- nextRecords, err := A(b, zone, state1, append(previousRecords, newRecord), opt)
-
- if err == nil {
- // Not only have we found something we should add the CNAME and the IP addresses.
- if len(nextRecords) > 0 {
- records = append(records, newRecord)
- records = append(records, nextRecords...)
+ if dns.IsSubDomain(zone, dns.Fqdn(serv.Host)) {
+ state1 := state.NewWithQuestion(serv.Host, state.QType())
+ state1.Zone = zone
+ nextRecords, err := A(b, zone, state1, append(previousRecords, newRecord), opt)
+
+ if err == nil {
+ // Not only have we found something we should add the CNAME and the IP addresses.
+ if len(nextRecords) > 0 {
+ records = append(records, newRecord)
+ records = append(records, nextRecords...)
+ }
}
continue
}
// This means we can not complete the CNAME, try to look else where.
target := newRecord.Target
- if dns.IsSubDomain(zone, target) {
- // We should already have found it
- continue
- }
// Lookup
m1, e1 := b.Lookup(state, target, state.QType())
if e1 != nil {
@@ -110,19 +108,20 @@ func AAAA(b ServiceBackend, zone string, state request.Request, previousRecords
if dnsutil.DuplicateCNAME(newRecord, previousRecords) {
continue
}
-
- state1 := state.NewWithQuestion(serv.Host, state.QType())
- nextRecords, err := AAAA(b, zone, state1, append(previousRecords, newRecord), opt)
-
- if err == nil {
- // Not only have we found something we should add the CNAME and the IP addresses.
- if len(nextRecords) > 0 {
- records = append(records, newRecord)
- records = append(records, nextRecords...)
+ if dns.IsSubDomain(zone, dns.Fqdn(serv.Host)) {
+ state1 := state.NewWithQuestion(serv.Host, state.QType())
+ state1.Zone = zone
+ nextRecords, err := AAAA(b, zone, state1, append(previousRecords, newRecord), opt)
+
+ if err == nil {
+ // Not only have we found something we should add the CNAME and the IP addresses.
+ if len(nextRecords) > 0 {
+ records = append(records, newRecord)
+ records = append(records, nextRecords...)
+ }
}
continue
}
-
// This means we can not complete the CNAME, try to look else where.
target := newRecord.Target
m1, e1 := b.Lookup(state, target, state.QType())