Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Commit

Permalink
Skip local nameservers from coredns config. (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
r0mant authored Mar 26, 2019
1 parent 5673e26 commit f62f812
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions lib/install/phases/coredns.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@ import (
"bytes"
"context"

"github.com/alecthomas/template"
"github.com/gravitational/gravity/lib/constants"
"github.com/gravitational/gravity/lib/defaults"
"github.com/gravitational/gravity/lib/fsm"
"github.com/gravitational/gravity/lib/ops"
"github.com/gravitational/gravity/lib/storage"
"github.com/gravitational/gravity/lib/systeminfo"
"github.com/gravitational/teleport/lib/utils"

"github.com/alecthomas/template"
"github.com/gravitational/trace"
log "github.com/sirupsen/logrus"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)
Expand Down Expand Up @@ -92,8 +94,18 @@ func (r *corednsExecutor) Execute(ctx context.Context) error {
return trace.Wrap(err)
}

// Filter out local nameservers to avoid CoreDNS forwarding requests
// to itself and triggering loop detection, see for more details:
// https://github.com/coredns/coredns/tree/master/plugin/loop#troubleshooting
var upstreams []string
for _, nameserver := range resolvConf.Servers {
if !utils.IsLocalhost(nameserver) {
upstreams = append(upstreams, nameserver)
}
}

conf, err := GenerateCorefile(CorednsConfig{
UpstreamNameservers: resolvConf.Servers,
UpstreamNameservers: upstreams,
Rotate: resolvConf.Rotate,
Hosts: r.DNSOverrides.Hosts,
Zones: r.DNSOverrides.Zones,
Expand Down Expand Up @@ -174,9 +186,9 @@ const coreDNSTemplateText = `
proxy {{$zone}} {{range $server := $servers}}{{$server}} {{end}}{
policy sequential
}{{end}}
forward . {{range $server := .UpstreamNameservers}}{{$server}} {{end}}{
{{if .UpstreamNameservers}}forward . {{range $server := .UpstreamNameservers}}{{$server}} {{end}}{
{{if .Rotate}}policy random{{else}}policy sequential{{end}}
health_check 0
}
}{{end}}
}
`

0 comments on commit f62f812

Please sign in to comment.