Skip to content

Commit

Permalink
UPSTREAM: <carry>: openshift: Revert "Revert "add wildcard warnings (c…
Browse files Browse the repository at this point in the history
…oredns#5030)" (coredns#5167)"

This reverts commit 4693f40.
  • Loading branch information
Miciah authored and gcs278 committed Feb 15, 2023
1 parent 9cee741 commit 64a383f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions plugin/kubernetes/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package kubernetes

import (
"context"
"strings"
"sync/atomic"

"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/request"
Expand All @@ -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{})
Expand Down Expand Up @@ -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" }
1 change: 1 addition & 0 deletions plugin/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 21 additions & 0 deletions plugin/kubernetes/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"strconv"
"strings"
"sync/atomic"
"time"

"github.com/coredns/caddy"
"github.com/coredns/coredns/core/dnsserver"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 64a383f

Please sign in to comment.