Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read resolv.conf file just once #588

Merged
merged 2 commits into from
Apr 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions controllers/nginx/pkg/cmd/controller/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"k8s.io/ingress/controllers/nginx/pkg/version"
"k8s.io/ingress/core/pkg/ingress"
"k8s.io/ingress/core/pkg/ingress/defaults"
"k8s.io/ingress/core/pkg/net/dns"
"k8s.io/ingress/core/pkg/net/ssl"
)

Expand Down Expand Up @@ -69,10 +70,17 @@ func newNGINXController() ingress.Controller {
if ngx == "" {
ngx = binary
}

h, err := dns.GetSystemNameServers()
if err != nil {
glog.Warningf("unexpected error reading system nameservers: %v", err)
}

n := &NGINXController{
binary: ngx,
configmap: &api_v1.ConfigMap{},
isIPV6Enabled: isIPv6Enabled(),
resolver: h,
}

var onChange func()
Expand Down Expand Up @@ -125,6 +133,8 @@ type NGINXController struct {

// returns true if IPV6 is enabled in the pod
isIPV6Enabled bool

resolver []net.IP
}

// Start start a new NGINX master process running in foreground.
Expand Down Expand Up @@ -340,6 +350,7 @@ func (n *NGINXController) OnUpdate(ingressCfg ingress.Configuration) ([]byte, er
}

cfg := ngx_template.ReadConfig(n.configmap.Data)
cfg.Resolver = n.resolver

// we need to check if the status module configuration changed
if cfg.EnableVtsStatus {
Expand Down
8 changes: 0 additions & 8 deletions controllers/nginx/pkg/template/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/mitchellh/mapstructure"

"k8s.io/ingress/controllers/nginx/pkg/config"
"k8s.io/ingress/core/pkg/net/dns"
)

const (
Expand Down Expand Up @@ -72,13 +71,6 @@ func ReadConfig(src map[string]string) config.Configuration {
to.SkipAccessLogURLs = skipUrls
to.WhitelistSourceRange = whitelist

h, err := dns.GetSystemNameServers()
if err != nil {
glog.Warningf("unexpected error reading system nameservers: %v", err)
} else {
to.Resolver = h
}

config := &mapstructure.DecoderConfig{
Metadata: nil,
WeaklyTypedInput: true,
Expand Down
9 changes: 0 additions & 9 deletions controllers/nginx/pkg/template/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/kylelemons/godebug/pretty"

"k8s.io/ingress/controllers/nginx/pkg/config"
"k8s.io/ingress/core/pkg/net/dns"
)

func TestFilterErrors(t *testing.T) {
Expand Down Expand Up @@ -54,26 +53,18 @@ func TestMergeConfigMapToStruct(t *testing.T) {
def.UseProxyProtocol = true
def.GzipTypes = "text/html"

h, err := dns.GetSystemNameServers()
if err != nil {
t.Errorf("unexpected error: %v", err)
}
def.Resolver = h

to := ReadConfig(conf)
if diff := pretty.Compare(to, def); diff != "" {
t.Errorf("unexpected diff: (-got +want)\n%s", diff)
}

def = config.NewDefault()
def.Resolver = h
to = ReadConfig(map[string]string{})
if diff := pretty.Compare(to, def); diff != "" {
t.Errorf("unexpected diff: (-got +want)\n%s", diff)
}

def = config.NewDefault()
def.Resolver = h
def.WhitelistSourceRange = []string{"1.1.1.1/32"}
to = ReadConfig(map[string]string{
"whitelist-source-range": "1.1.1.1/32",
Expand Down