-
Notifications
You must be signed in to change notification settings - Fork 2
/
metadata.go
43 lines (34 loc) · 883 Bytes
/
metadata.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package kubepods
import (
"context"
"github.com/coredns/coredns/plugin/metadata"
"github.com/coredns/coredns/request"
core "k8s.io/api/core/v1"
)
// Metadata implements the metadata.Provider interface.
func (k *KubePods) Metadata(ctx context.Context, state request.Request) context.Context {
if k.indexer == nil {
return ctx
}
p, err := k.indexer.ByIndex("reverse", state.IP())
if err != nil || len(p) == 0 {
return ctx
}
pod, ok := p[0].(*core.Pod)
if !ok {
return ctx
}
metadata.SetValueFunc(ctx, "kubepods/client-namespace", func() string {
return pod.Namespace
})
metadata.SetValueFunc(ctx, "kubepods/client-pod-name", func() string {
return pod.Name
})
for key := range pod.Annotations {
value := pod.Annotations[key]
metadata.SetValueFunc(ctx, "kubepods/client-pod-annotation-"+key, func() string {
return value
})
}
return ctx
}