From 64a383f22f5b2a2ad53e8b373f7cbc7468815efb Mon Sep 17 00:00:00 2001 From: Miciah Masters Date: Thu, 26 May 2022 17:44:19 -0400 Subject: [PATCH] UPSTREAM: : openshift: Revert "Revert "add wildcard warnings (#5030)" (#5167)" This reverts commit 4693f40990cd6fbd798962d6ac15d8aea9c8b737. --- plugin/kubernetes/handler.go | 11 +++++++++++ plugin/kubernetes/kubernetes.go | 1 + plugin/kubernetes/setup.go | 21 +++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/plugin/kubernetes/handler.go b/plugin/kubernetes/handler.go index d673a7a40f3b..ddf65b42ac8a 100644 --- a/plugin/kubernetes/handler.go +++ b/plugin/kubernetes/handler.go @@ -2,6 +2,8 @@ package kubernetes import ( "context" + "strings" + "sync/atomic" "github.com/coredns/coredns/plugin" "github.com/coredns/coredns/request" @@ -28,6 +30,10 @@ func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M err error ) + if wildQuestion(state.Name()) { + atomic.AddUint64(&wildCount, 1) + } + switch state.QType() { case dns.TypeA: records, truncated, err = plugin.A(ctx, &k, zone, state, nil, plugin.Options{}) @@ -87,8 +93,13 @@ func (k Kubernetes) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M m.Answer = append(m.Answer, records...) m.Extra = append(m.Extra, extra...) w.WriteMsg(m) + return dns.RcodeSuccess, nil } +func wildQuestion(name string) bool { + return strings.HasPrefix(name, "*.") || strings.HasPrefix(name, "any.") || strings.Contains(name, ".*.") || strings.Contains(name, ".any.") +} + // Name implements the Handler interface. func (k Kubernetes) Name() string { return "kubernetes" } diff --git a/plugin/kubernetes/kubernetes.go b/plugin/kubernetes/kubernetes.go index 77b44e71e192..01f309d9db50 100644 --- a/plugin/kubernetes/kubernetes.go +++ b/plugin/kubernetes/kubernetes.go @@ -90,6 +90,7 @@ var ( errNoItems = errors.New("no items found") errNsNotExposed = errors.New("namespace is not exposed") errInvalidRequest = errors.New("invalid query name") + wildCount uint64 ) // Services implements the ServiceBackend interface. diff --git a/plugin/kubernetes/setup.go b/plugin/kubernetes/setup.go index 0b988a9a0741..31dba5d41bed 100644 --- a/plugin/kubernetes/setup.go +++ b/plugin/kubernetes/setup.go @@ -6,6 +6,8 @@ import ( "fmt" "strconv" "strings" + "sync/atomic" + "time" "github.com/coredns/caddy" "github.com/coredns/coredns/core/dnsserver" @@ -59,6 +61,25 @@ func setup(c *caddy.Controller) error { return nil }) + wildWarner := time.NewTicker(10 * time.Second) + c.OnStartup(func() error { + go func() { + for { + select { + case <-wildWarner.C: + if wc := atomic.SwapUint64(&wildCount, 0); wc > 0 { + log.Warningf("%d deprecated wildcard queries received. Wildcard queries will no longer be supported in the next minor release.", wc) + } + } + } + }() + return nil + }) + c.OnShutdown(func() error { + wildWarner.Stop() + return nil + }) + return nil }