mw/kubernetes: resync to opts (#957)
* mw/kubernetes: resync to opts Only used to initialize the cache that already has a dnsControlopts, so remove it from the main kubernetes struct. * Fix test * mw/kubernetes: LabelSelector to options as well Labels select is also only used for init. Don't carry it in the main kubernetes struct. * remove this test: can't happen Caddyfile parser will only call setup when it sees kubernetes. * erge gone wrong
This commit is contained in:
parent
6a4e69eb9f
commit
12db6618c8
5 changed files with 52 additions and 63 deletions
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"k8s.io/client-go/1.5/kubernetes"
|
||||
"k8s.io/client-go/1.5/pkg/api"
|
||||
unversionedapi "k8s.io/client-go/1.5/pkg/api/unversioned"
|
||||
"k8s.io/client-go/1.5/pkg/api/v1"
|
||||
"k8s.io/client-go/1.5/pkg/labels"
|
||||
"k8s.io/client-go/1.5/pkg/runtime"
|
||||
|
@ -71,13 +72,17 @@ type dnsControl struct {
|
|||
|
||||
type dnsControlOpts struct {
|
||||
initPodCache bool
|
||||
resyncPeriod time.Duration
|
||||
// Label handling.
|
||||
labelSelector *unversionedapi.LabelSelector
|
||||
selector *labels.Selector
|
||||
}
|
||||
|
||||
// newDNSController creates a controller for CoreDNS.
|
||||
func newdnsController(kubeClient *kubernetes.Clientset, resyncPeriod time.Duration, lselector *labels.Selector, opts dnsControlOpts) *dnsControl {
|
||||
func newdnsController(kubeClient *kubernetes.Clientset, opts dnsControlOpts) *dnsControl {
|
||||
dns := dnsControl{
|
||||
client: kubeClient,
|
||||
selector: lselector,
|
||||
selector: opts.selector,
|
||||
stopCh: make(chan struct{}),
|
||||
}
|
||||
|
||||
|
@ -87,7 +92,7 @@ func newdnsController(kubeClient *kubernetes.Clientset, resyncPeriod time.Durati
|
|||
WatchFunc: serviceWatchFunc(dns.client, namespace, dns.selector),
|
||||
},
|
||||
&api.Service{},
|
||||
resyncPeriod,
|
||||
opts.resyncPeriod,
|
||||
cache.ResourceEventHandlerFuncs{},
|
||||
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc})
|
||||
|
||||
|
@ -98,7 +103,7 @@ func newdnsController(kubeClient *kubernetes.Clientset, resyncPeriod time.Durati
|
|||
WatchFunc: podWatchFunc(dns.client, namespace, dns.selector),
|
||||
},
|
||||
&api.Pod{}, // TODO replace with a lighter-weight custom struct
|
||||
resyncPeriod,
|
||||
opts.resyncPeriod,
|
||||
cache.ResourceEventHandlerFuncs{},
|
||||
cache.Indexers{podIPIndex: podIPIndexFunc})
|
||||
}
|
||||
|
@ -108,14 +113,18 @@ func newdnsController(kubeClient *kubernetes.Clientset, resyncPeriod time.Durati
|
|||
ListFunc: namespaceListFunc(dns.client, dns.selector),
|
||||
WatchFunc: namespaceWatchFunc(dns.client, dns.selector),
|
||||
},
|
||||
&api.Namespace{}, resyncPeriod, cache.ResourceEventHandlerFuncs{})
|
||||
&api.Namespace{},
|
||||
opts.resyncPeriod,
|
||||
cache.ResourceEventHandlerFuncs{})
|
||||
|
||||
dns.epLister.Store, dns.epController = cache.NewInformer(
|
||||
&cache.ListWatch{
|
||||
ListFunc: endpointsListFunc(dns.client, namespace, dns.selector),
|
||||
WatchFunc: endpointsWatchFunc(dns.client, namespace, dns.selector),
|
||||
},
|
||||
&api.Endpoints{}, resyncPeriod, cache.ResourceEventHandlerFuncs{})
|
||||
&api.Endpoints{},
|
||||
opts.resyncPeriod,
|
||||
cache.ResourceEventHandlerFuncs{})
|
||||
|
||||
return &dns
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue