From cb31ac08740f764a9b69ece7c8841b727d162ca7 Mon Sep 17 00:00:00 2001 From: Zicheng Huang Date: Wed, 24 Aug 2022 12:53:13 +0200 Subject: [PATCH] Resolve comments --- cmd/node-cache/app/cache_app_test.go | 2 +- cmd/node-cache/app/configmap.go | 10 +++++----- pkg/dns/config/config.go | 7 +++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/cmd/node-cache/app/cache_app_test.go b/cmd/node-cache/app/cache_app_test.go index 7caed0202..922f64e0c 100644 --- a/cmd/node-cache/app/cache_app_test.go +++ b/cmd/node-cache/app/cache_app_test.go @@ -246,7 +246,7 @@ func TestUpdateIPv6CoreFile(t *testing.T) { } customConfig := &config.Config{StubDomains: map[string][]string{ "acme.local": {"2001:db8:1:1:1::1"}, - "google.local": {"8.8.8.8"}, + "google.local": {"2001:4860:4860::8888"}, "widget.local": {"[2001:db8:2:2:2::2]:10053", "2001:db8:3:3:3::3"}, }, UpstreamNameservers: []string{"[2001:db8:2:2:2::2]:10053", "2001:db8:3:3:3::3"}, diff --git a/cmd/node-cache/app/configmap.go b/cmd/node-cache/app/configmap.go index 9efae5337..59fcadb3d 100644 --- a/cmd/node-cache/app/configmap.go +++ b/cmd/node-cache/app/configmap.go @@ -82,6 +82,11 @@ func getStubDomainStr(stubDomainMap map[string][]string, info *stubDomainInfo) s } func (c *CacheApp) updateCorefile(dnsConfig *config.Config) { + if err := dnsConfig.ValidateNodeLocalCacheConfig(); err != nil { + clog.Errorf("Invalid config: %v", err) + setupErrCount.WithLabelValues("configmap").Inc() + return + } // construct part of the Corefile baseConfig, err := ioutil.ReadFile(c.params.BaseCoreFile) if err != nil { @@ -89,11 +94,6 @@ func (c *CacheApp) updateCorefile(dnsConfig *config.Config) { setupErrCount.WithLabelValues("configmap").Inc() return } - if err = dnsConfig.ValidateNodeLocalCacheConfig(); err != nil { - clog.Errorf("Invalid config: %v", err) - setupErrCount.WithLabelValues("configmap").Inc() - return - } stubDomainStr := getStubDomainStr(dnsConfig.StubDomains, &stubDomainInfo{Port: c.params.LocalPort, CacheTTL: defaultTTL, LocalIP: strings.Replace(c.params.LocalIPStr, ",", " ", -1)}) diff --git a/pkg/dns/config/config.go b/pkg/dns/config/config.go index 274702456..c68cbf1b5 100644 --- a/pkg/dns/config/config.go +++ b/pkg/dns/config/config.go @@ -22,7 +22,6 @@ import ( "strconv" "github.com/coredns/coredns/plugin/pkg/parse" - types "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/validation" fed "k8s.io/dns/pkg/dns/federation" @@ -136,9 +135,9 @@ func (config *Config) validateUpstreamNameserver() error { // ValidateNodeLocalCacheConfig returns nil if the config can be compiled // to a valid Corefile. func (config *Config) ValidateNodeLocalCacheConfig() error { - for _, stubDomains := range config.StubDomains { - if err := validateForwardProxy(stubDomains...); err != nil { - return err + for domain, nameservers := range config.StubDomains { + if err := validateForwardProxy(nameservers...); err != nil { + return fmt.Errorf("invalid nameservers %s for the stub domain %s: %v", nameservers, domain, err) } } if err := validateForwardProxy(config.UpstreamNameservers...); err != nil {