Skip to content
Open
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
6 changes: 4 additions & 2 deletions Corefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.:1053 {
debug
log
kubeslice
}
forward . <ClusterIP of kube-dns>
reload 2s
}
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ FROM gcr.io/distroless/static:nonroot
WORKDIR /

COPY --from=builder /workspace/coredns .
COPY Corefile Corefile

USER nonroot:nonroot

Expand Down
9 changes: 5 additions & 4 deletions plugin/kubeslice/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ import (
var log = clog.NewWithPlugin("kubeslice")

// ServeDNS implements the plugin.Handler interface.
func (ks Kubeslice) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
func (ks *Kubeslice) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
log.Debug("Question type", r.Question)

state := request.Request{W: w, Req: r}
zone := "slice.local"

records, truncated, err := plugin.A(ctx, &ks, zone, state, nil, plugin.Options{})
records, truncated, err := plugin.A(ctx, ks, zone, state, nil, plugin.Options{})

if err != nil {
return dns.RcodeServerFailure, err
log.Debug("query not answered,fallthrough forrward plugin")
return plugin.NextOrFailure(ks.Name(), ks.Next, ctx, w, r)
}

m := new(dns.Msg)
Expand All @@ -39,4 +40,4 @@ func (ks Kubeslice) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.M
}

// Name implements the Handler interface.
func (e Kubeslice) Name() string { return "kubeslice" }
func (e *Kubeslice) Name() string { return "kubeslice" }
8 changes: 8 additions & 0 deletions plugin/kubeslice/kubeslice.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kubeslice

import (
"context"
"errors"

"github.com/coredns/coredns/plugin/etcd/msg"
"github.com/coredns/coredns/request"
Expand All @@ -17,6 +18,10 @@ type Kubeslice struct {
EndpointsCache dnsCache.EndpointsCache
}

func New() *Kubeslice {
return &Kubeslice{}
}

func (ks *Kubeslice) Services(ctx context.Context, state request.Request, exact bool, opt plugin.Options) ([]msg.Service, error) {

var svcs []msg.Service
Expand Down Expand Up @@ -44,6 +49,9 @@ func (ks *Kubeslice) Services(ctx context.Context, state request.Request, exact
svcs = append(svcs, svc)
}
}
if len(svcs) == 0 {
return svcs, errors.New("no records found")
}

return svcs, nil

Expand Down
2 changes: 1 addition & 1 deletion plugin/kubeslice/ready.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package kubeslice

// Ready implements the ready.Readiness interface, once this flips to true CoreDNS
// assumes this plugin is ready for queries; it is not checked again.
func (ks Kubeslice) Ready() bool { return true }
func (ks *Kubeslice) Ready() bool { return true }
8 changes: 6 additions & 2 deletions plugin/kubeslice/setup.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package kubeslice

import (
"os"

"github.com/coredns/caddy"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
"os"

dnsCache "github.com/kubeslice/dns/plugin/kubeslice/cache"
kubeslicev1beta1 "github.com/kubeslice/worker-operator/api/v1beta1"
Expand All @@ -30,6 +31,7 @@ func init() { plugin.Register("kubeslice", setup) }
// setup is the function that gets called when the config parser see the token "example". Setup is responsible
// for parsing any extra options the example plugin may have. The first token this function sees is "example".
func setup(c *caddy.Controller) error {
f := New()
c.Next() // Ignore "example" and give us the next token.
if c.NextArg() {
// If there was another token, return an error, because we don't have any configuration.
Expand All @@ -42,7 +44,9 @@ func setup(c *caddy.Controller) error {

// Add the Plugin to CoreDNS, so Servers can use it in their plugin chain.
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
return Kubeslice{Next: next, EndpointsCache: cache}
f.Next = next
f.EndpointsCache = cache
return f
})

mgr, err := manager.New(
Expand Down
2 changes: 1 addition & 1 deletion vendor/github.com/coredns/coredns/coremain/run.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.