diff options
author | 2017-08-09 04:06:48 -0700 | |
---|---|---|
committer | 2017-08-09 04:06:48 -0700 | |
commit | b8e2c476a5535a35daa54ef4e13e627ffa5cb912 (patch) | |
tree | b71397a19b466fd241306b50e184648dbf66291c | |
parent | b46b9880bd606fd2d0acaccf7d1915a8803bc81b (diff) | |
download | coredns-b8e2c476a5535a35daa54ef4e13e627ffa5cb912.tar.gz coredns-b8e2c476a5535a35daa54ef4e13e627ffa5cb912.tar.zst coredns-b8e2c476a5535a35daa54ef4e13e627ffa5cb912.zip |
mw/authpath: hook in kubernetees (#860)
Call out to kubernetes to get the search path - this still needs
to return something sensible, but all infrastructure has landed
to make it work.
-rw-r--r-- | middleware/autopath/setup.go | 11 | ||||
-rw-r--r-- | middleware/kubernetes/autopath.go | 31 | ||||
-rw-r--r-- | middleware/kubernetes/setup.go | 7 |
3 files changed, 35 insertions, 14 deletions
diff --git a/middleware/autopath/setup.go b/middleware/autopath/setup.go index 8abd67acb..cbaf007fc 100644 --- a/middleware/autopath/setup.go +++ b/middleware/autopath/setup.go @@ -5,6 +5,7 @@ import ( "github.com/coredns/coredns/core/dnsserver" "github.com/coredns/coredns/middleware" + "github.com/coredns/coredns/middleware/kubernetes" "github.com/mholt/caddy" "github.com/miekg/dns" @@ -25,14 +26,14 @@ func setup(c *caddy.Controller) error { } c.OnStartup(func() error { - // So we know for sure the mw is initialized. + // Do this in OnStartup, so all middleware has been initialized. + // TODO(miek): fabricate test to proof this is not thread safe. m := dnsserver.GetMiddleware(c, mw) switch mw { case "kubernetes": - m = m - //if k, ok := m.(kubernetes.Kubernetes); ok { - //&ap.searchFunc = k.AutoPath - //} + if k, ok := m.(kubernetes.Kubernetes); ok { + ap.searchFunc = k.AutoPath + } } return nil }) diff --git a/middleware/kubernetes/autopath.go b/middleware/kubernetes/autopath.go index 3d677e4df..4c5870c6b 100644 --- a/middleware/kubernetes/autopath.go +++ b/middleware/kubernetes/autopath.go @@ -1,11 +1,32 @@ package kubernetes -import "k8s.io/client-go/1.5/pkg/api" +import ( + "fmt" -// TODO(miek): rename and put in autopath.go file. This will be for the -// external middleware autopath to use. Mostly to get the namespace: -//name, path, ok := autopath.SplitSearch(zone, state.QName(), p.Namespace) -func (k *Kubernetes) findPodWithIP(ip string) (p *api.Pod) { + "github.com/coredns/coredns/request" + + "k8s.io/client-go/1.5/pkg/api" +) + +func (k *Kubernetes) AutoPath(state request.Request) ([]string, error) { + ip := state.IP() + + pod := k.PodWithIP(ip) + if pod == nil { + return nil, fmt.Errorf("kubernets: no pod found for %s", ip) + } + + // something something namespace + namespace := pod.Namespace + + search := []string{namespace} // TODO: way more + + search = append(search, "") // sentinal + return search, nil +} + +// PodWithIP return the api.Pod for source IP ip. It return nil if nothing can be found. +func (k *Kubernetes) PodWithIP(ip string) (p *api.Pod) { objList := k.APIConn.PodIndex(ip) for _, o := range objList { p, ok := o.(*api.Pod) diff --git a/middleware/kubernetes/setup.go b/middleware/kubernetes/setup.go index 24c81438d..b28e5df18 100644 --- a/middleware/kubernetes/setup.go +++ b/middleware/kubernetes/setup.go @@ -203,8 +203,7 @@ func kubernetesParse(c *caddy.Controller) (*Kubernetes, error) { } const ( - defaultResyncPeriod = 5 * time.Minute - defautNdots = 0 - defaultResolvConfFile = "/etc/resolv.conf" - defaultOnNXDOMAIN = dns.RcodeSuccess + defaultResyncPeriod = 5 * time.Minute + defautNdots = 0 + defaultOnNXDOMAIN = dns.RcodeSuccess ) |