diff options
author | 2019-06-09 00:10:57 -0700 | |
---|---|---|
committer | 2019-06-09 08:10:57 +0100 | |
commit | ffcd2f61cfc2290b23e92c9123cf71b854be9e0d (patch) | |
tree | 7870daa67eeb364e022b37d5489067ff65578b88 /plugin/kubernetes/metadata.go | |
parent | a1c97f82a6f27ae1f4489a1dc5d0bc6fa4cce9ed (diff) | |
download | coredns-ffcd2f61cfc2290b23e92c9123cf71b854be9e0d.tar.gz coredns-ffcd2f61cfc2290b23e92c9123cf71b854be9e0d.tar.zst coredns-ffcd2f61cfc2290b23e92c9123cf71b854be9e0d.zip |
Publish metadata from kubernetes plugin (#2829)
* Publish metadata from kubernetes plugin
* stickler fix
* Add a couple tests
* Add metadata section to README
* Update plugin/kubernetes/README.md
Co-Authored-By: Chris O'Haver <cohaver@infoblox.com>
* Address nit
Diffstat (limited to 'plugin/kubernetes/metadata.go')
-rw-r--r-- | plugin/kubernetes/metadata.go | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/plugin/kubernetes/metadata.go b/plugin/kubernetes/metadata.go new file mode 100644 index 000000000..323ae9e11 --- /dev/null +++ b/plugin/kubernetes/metadata.go @@ -0,0 +1,59 @@ +package kubernetes + +import ( + "context" + + "github.com/coredns/coredns/plugin/metadata" + "github.com/coredns/coredns/request" +) + +// Metadata implements the metadata.Provider interface. +func (k *Kubernetes) Metadata(ctx context.Context, state request.Request) context.Context { + // possible optimization: cache r so it doesn't need to be calculated again in ServeDNS + r, err := parseRequest(state) + if err != nil { + metadata.SetValueFunc(ctx, "kubernetes/parse-error", func() string { + return err.Error() + }) + return ctx + } + + metadata.SetValueFunc(ctx, "kubernetes/port-name", func() string { + return r.port + }) + + metadata.SetValueFunc(ctx, "kubernetes/protocol", func() string { + return r.protocol + }) + + metadata.SetValueFunc(ctx, "kubernetes/endpoint", func() string { + return r.endpoint + }) + + metadata.SetValueFunc(ctx, "kubernetes/service", func() string { + return r.service + }) + + metadata.SetValueFunc(ctx, "kubernetes/namespace", func() string { + return r.namespace + }) + + metadata.SetValueFunc(ctx, "kubernetes/kind", func() string { + return r.podOrSvc + }) + + pod := k.podWithIP(state.IP()) + if pod == nil { + return ctx + } + + metadata.SetValueFunc(ctx, "kubernetes/client-namespace", func() string { + return pod.Namespace + }) + + metadata.SetValueFunc(ctx, "kubernetes/client-pod-name", func() string { + return pod.Name + }) + + return ctx +} |