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.
This commit is contained in:
parent
a1989c3523
commit
9ac3cab1b7
140 changed files with 2058 additions and 8229 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue