diff options
author | 2016-08-19 17:14:17 -0700 | |
---|---|---|
committer | 2016-08-19 17:14:17 -0700 | |
commit | 9ac3cab1b7b1b1e78f86ce3c6a80fbee312162e6 (patch) | |
tree | 437e9755927c33af16276ad2602a6da115f948cb /middleware/kubernetes/controller.go | |
parent | a1989c35231b0e5ea271b2f68d82c1a63e697cd0 (diff) | |
download | coredns-9ac3cab1b7b1b1e78f86ce3c6a80fbee312162e6.tar.gz coredns-9ac3cab1b7b1b1e78f86ce3c6a80fbee312162e6.tar.zst coredns-9ac3cab1b7b1b1e78f86ce3c6a80fbee312162e6.zip |
Make CoreDNS a server type plugin for Caddy (#220)
* Make CoreDNS a server type plugin for Caddy
Remove code we don't need and port all middleware over. Fix all tests
and rework the documentation.
Also make `go generate` build a caddy binary which we then copy into
our directory. This means `go build`-builds remain working as-is.
And new etc instances in each etcd test for better isolation.
Fix more tests and rework test.Server with the newer support Caddy offers.
Fix Makefile to support new mode of operation.
Diffstat (limited to 'middleware/kubernetes/controller.go')
-rw-r--r-- | middleware/kubernetes/controller.go | 56 |
1 files changed, 25 insertions, 31 deletions
diff --git a/middleware/kubernetes/controller.go b/middleware/kubernetes/controller.go index 3fbea313e..5de16d61c 100644 --- a/middleware/kubernetes/controller.go +++ b/middleware/kubernetes/controller.go @@ -2,7 +2,6 @@ package kubernetes import ( "fmt" - "log" "sync" "time" @@ -12,7 +11,7 @@ import ( "k8s.io/kubernetes/pkg/client/cache" client "k8s.io/kubernetes/pkg/client/unversioned" "k8s.io/kubernetes/pkg/controller/framework" - "k8s.io/kubernetes/pkg/labels" + "k8s.io/kubernetes/pkg/labels" "k8s.io/kubernetes/pkg/runtime" "k8s.io/kubernetes/pkg/watch" ) @@ -24,7 +23,7 @@ var ( type dnsController struct { client *client.Client - selector *labels.Selector + selector *labels.Selector endpController *framework.Controller svcController *framework.Controller @@ -45,9 +44,9 @@ type dnsController struct { // newDNSController creates a controller for coredns func newdnsController(kubeClient *client.Client, resyncPeriod time.Duration, lselector *labels.Selector) *dnsController { dns := dnsController{ - client: kubeClient, - selector: lselector, - stopCh: make(chan struct{}), + client: kubeClient, + selector: lselector, + stopCh: make(chan struct{}), } dns.endpLister.Store, dns.endpController = framework.NewInformer( @@ -76,54 +75,54 @@ func newdnsController(kubeClient *client.Client, resyncPeriod time.Duration, lse func serviceListFunc(c *client.Client, ns string, s *labels.Selector) func(api.ListOptions) (runtime.Object, error) { return func(opts api.ListOptions) (runtime.Object, error) { - if s != nil { - opts.LabelSelector = *s - } + if s != nil { + opts.LabelSelector = *s + } return c.Services(ns).List(opts) } } func serviceWatchFunc(c *client.Client, ns string, s *labels.Selector) func(options api.ListOptions) (watch.Interface, error) { return func(options api.ListOptions) (watch.Interface, error) { - if s != nil { - options.LabelSelector = *s - } + if s != nil { + options.LabelSelector = *s + } return c.Services(ns).Watch(options) } } func endpointsListFunc(c *client.Client, ns string, s *labels.Selector) func(api.ListOptions) (runtime.Object, error) { return func(opts api.ListOptions) (runtime.Object, error) { - if s != nil { - opts.LabelSelector = *s - } + if s != nil { + opts.LabelSelector = *s + } return c.Endpoints(ns).List(opts) } } func endpointsWatchFunc(c *client.Client, ns string, s *labels.Selector) func(options api.ListOptions) (watch.Interface, error) { return func(options api.ListOptions) (watch.Interface, error) { - if s != nil { - options.LabelSelector = *s - } + if s != nil { + options.LabelSelector = *s + } return c.Endpoints(ns).Watch(options) } } func namespaceListFunc(c *client.Client, s *labels.Selector) func(api.ListOptions) (runtime.Object, error) { return func(opts api.ListOptions) (runtime.Object, error) { - if s != nil { - opts.LabelSelector = *s - } + if s != nil { + opts.LabelSelector = *s + } return c.Namespaces().List(opts) } } func namespaceWatchFunc(c *client.Client, s *labels.Selector) func(options api.ListOptions) (watch.Interface, error) { return func(options api.ListOptions) (watch.Interface, error) { - if s != nil { - options.LabelSelector = *s - } + if s != nil { + options.LabelSelector = *s + } return c.Namespaces().Watch(options) } } @@ -140,7 +139,6 @@ func (dns *dnsController) Stop() error { // Only try draining the workqueue if we haven't already. if !dns.shutdown { close(dns.stopCh) - log.Println("shutting down controller queues") dns.shutdown = true return nil @@ -151,14 +149,10 @@ func (dns *dnsController) Stop() error { // Run starts the controller. func (dns *dnsController) Run() { - log.Println("[debug] Starting k8s notification controllers") - go dns.endpController.Run(dns.stopCh) go dns.svcController.Run(dns.stopCh) go dns.nsController.Run(dns.stopCh) - <-dns.stopCh - log.Println("[debug] shutting down coredns controller") } func (dns *dnsController) GetNamespaceList() *api.NamespaceList { @@ -203,12 +197,12 @@ func (dns *dnsController) GetServiceInNamespace(namespace string, servicename st svcObj, svcExists, err := dns.svcLister.Store.GetByKey(svcKey) if err != nil { - log.Printf("error getting service %v from the cache: %v\n", svcKey, err) + // TODO(...): should return err here return nil } if !svcExists { - log.Printf("service %v does not exists\n", svcKey) + // TODO(...): should return err here return nil } |