diff options
author | 2023-06-12 11:22:57 -0400 | |
---|---|---|
committer | 2023-06-12 08:22:57 -0700 | |
commit | 06cd8439182be8b9ed17280eaae411f9afb7c8f2 (patch) | |
tree | 6b99d7bb86286cf5eeccc4d616a85445ca0cbaa6 /plugin/kubernetes/controller.go | |
parent | 6e6fc650ceb6ce234293b0d92c09259d200f86a4 (diff) | |
download | coredns-06cd8439182be8b9ed17280eaae411f9afb7c8f2.tar.gz coredns-06cd8439182be8b9ed17280eaae411f9afb7c8f2.tar.zst coredns-06cd8439182be8b9ed17280eaae411f9afb7c8f2.zip |
plugin/kubernetes: Remove Endpoint and EndpointSlice v1beta Support (#6147)
* remove endpoint and endpointslicev1beta watch support
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
* adjust readme
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
* informer object changes
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
* remove unused funcs
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
---------
Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
Diffstat (limited to 'plugin/kubernetes/controller.go')
-rw-r--r-- | plugin/kubernetes/controller.go | 88 |
1 files changed, 0 insertions, 88 deletions
diff --git a/plugin/kubernetes/controller.go b/plugin/kubernetes/controller.go index a785a003d..e7db294fc 100644 --- a/plugin/kubernetes/controller.go +++ b/plugin/kubernetes/controller.go @@ -12,7 +12,6 @@ import ( api "k8s.io/api/core/v1" discovery "k8s.io/api/discovery/v1" - discoveryV1beta1 "k8s.io/api/discovery/v1beta1" meta "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" @@ -66,10 +65,6 @@ type dnsControl struct { selector labels.Selector namespaceSelector labels.Selector - // epLock is used to lock reads of epLister and epController while they are being replaced - // with the api.Endpoints Lister/Controller on k8s systems that don't use discovery.EndpointSlices - epLock sync.RWMutex - svcController cache.Controller podController cache.Controller epController cache.Controller @@ -153,12 +148,10 @@ func newdnsController(ctx context.Context, kubeClient kubernetes.Interface, opts cache.Indexers{epNameNamespaceIndex: epNameNamespaceIndexFunc, epIPIndex: epIPIndexFunc}, object.DefaultProcessor(object.EndpointSliceToEndpoints, dns.EndpointSliceLatencyRecorder()), ) - dns.epLock.Lock() dns.epLister = epLister if opts.initEndpointsCache { dns.epController = epController } - dns.epLock.Unlock() dns.nsLister, dns.nsController = object.NewIndexerInformer( &cache.ListWatch{ @@ -174,42 +167,6 @@ func newdnsController(ctx context.Context, kubeClient kubernetes.Interface, opts return &dns } -// WatchEndpoints will set the endpoint Lister and Controller to watch object.Endpoints -// instead of the default discovery.EndpointSlice. This is used in older k8s clusters where -// discovery.EndpointSlice is not fully supported. -// This can be removed when all supported k8s versions fully support EndpointSlice. -func (dns *dnsControl) WatchEndpoints(ctx context.Context) { - dns.epLock.Lock() - dns.epLister, dns.epController = object.NewIndexerInformer( - &cache.ListWatch{ - ListFunc: endpointsListFunc(ctx, dns.client, api.NamespaceAll, dns.selector), - WatchFunc: endpointsWatchFunc(ctx, dns.client, api.NamespaceAll, dns.selector), - }, - &api.Endpoints{}, - cache.ResourceEventHandlerFuncs{AddFunc: dns.Add, UpdateFunc: dns.Update, DeleteFunc: dns.Delete}, - cache.Indexers{epNameNamespaceIndex: epNameNamespaceIndexFunc, epIPIndex: epIPIndexFunc}, - object.DefaultProcessor(object.ToEndpoints, dns.EndpointsLatencyRecorder()), - ) - dns.epLock.Unlock() -} - -// WatchEndpointSliceV1beta1 will set the endpoint Lister and Controller to watch v1beta1 -// instead of the default v1. -func (dns *dnsControl) WatchEndpointSliceV1beta1(ctx context.Context) { - dns.epLock.Lock() - dns.epLister, dns.epController = object.NewIndexerInformer( - &cache.ListWatch{ - ListFunc: endpointSliceListFuncV1beta1(ctx, dns.client, api.NamespaceAll, dns.selector), - WatchFunc: endpointSliceWatchFuncV1beta1(ctx, dns.client, api.NamespaceAll, dns.selector), - }, - &discoveryV1beta1.EndpointSlice{}, - cache.ResourceEventHandlerFuncs{AddFunc: dns.Add, UpdateFunc: dns.Update, DeleteFunc: dns.Delete}, - cache.Indexers{epNameNamespaceIndex: epNameNamespaceIndexFunc, epIPIndex: epIPIndexFunc}, - object.DefaultProcessor(object.EndpointSliceV1beta1ToEndpoints, dns.EndpointSliceLatencyRecorder()), - ) - dns.epLock.Unlock() -} - func (dns *dnsControl) EndpointsLatencyRecorder() *object.EndpointLatencyRecorder { return &object.EndpointLatencyRecorder{ ServiceFunc: func(o meta.Object) []*object.Service { @@ -298,14 +255,6 @@ func podListFunc(ctx context.Context, c kubernetes.Interface, ns string, s label return c.CoreV1().Pods(ns).List(ctx, opts) } } -func endpointSliceListFuncV1beta1(ctx context.Context, c kubernetes.Interface, ns string, s labels.Selector) func(meta.ListOptions) (runtime.Object, error) { - return func(opts meta.ListOptions) (runtime.Object, error) { - if s != nil { - opts.LabelSelector = s.String() - } - return c.DiscoveryV1beta1().EndpointSlices(ns).List(ctx, opts) - } -} func endpointSliceListFunc(ctx context.Context, c kubernetes.Interface, ns string, s labels.Selector) func(meta.ListOptions) (runtime.Object, error) { return func(opts meta.ListOptions) (runtime.Object, error) { @@ -316,15 +265,6 @@ func endpointSliceListFunc(ctx context.Context, c kubernetes.Interface, ns strin } } -func endpointsListFunc(ctx context.Context, c kubernetes.Interface, ns string, s labels.Selector) func(meta.ListOptions) (runtime.Object, error) { - return func(opts meta.ListOptions) (runtime.Object, error) { - if s != nil { - opts.LabelSelector = s.String() - } - return c.CoreV1().Endpoints(ns).List(ctx, opts) - } -} - func namespaceListFunc(ctx context.Context, c kubernetes.Interface, s labels.Selector) func(meta.ListOptions) (runtime.Object, error) { return func(opts meta.ListOptions) (runtime.Object, error) { if s != nil { @@ -356,15 +296,6 @@ func podWatchFunc(ctx context.Context, c kubernetes.Interface, ns string, s labe } } -func endpointSliceWatchFuncV1beta1(ctx context.Context, c kubernetes.Interface, ns string, s labels.Selector) func(options meta.ListOptions) (watch.Interface, error) { - return func(options meta.ListOptions) (watch.Interface, error) { - if s != nil { - options.LabelSelector = s.String() - } - return c.DiscoveryV1beta1().EndpointSlices(ns).Watch(ctx, options) - } -} - func endpointSliceWatchFunc(ctx context.Context, c kubernetes.Interface, ns string, s labels.Selector) func(options meta.ListOptions) (watch.Interface, error) { return func(options meta.ListOptions) (watch.Interface, error) { if s != nil { @@ -374,15 +305,6 @@ func endpointSliceWatchFunc(ctx context.Context, c kubernetes.Interface, ns stri } } -func endpointsWatchFunc(ctx context.Context, c kubernetes.Interface, ns string, s labels.Selector) func(options meta.ListOptions) (watch.Interface, error) { - return func(options meta.ListOptions) (watch.Interface, error) { - if s != nil { - options.LabelSelector = s.String() - } - return c.CoreV1().Endpoints(ns).Watch(ctx, options) - } -} - func namespaceWatchFunc(ctx context.Context, c kubernetes.Interface, s labels.Selector) func(options meta.ListOptions) (watch.Interface, error) { return func(options meta.ListOptions) (watch.Interface, error) { if s != nil { @@ -413,9 +335,7 @@ func (dns *dnsControl) Run() { go dns.svcController.Run(dns.stopCh) if dns.epController != nil { go func() { - dns.epLock.RLock() dns.epController.Run(dns.stopCh) - dns.epLock.RUnlock() }() } if dns.podController != nil { @@ -430,9 +350,7 @@ func (dns *dnsControl) HasSynced() bool { a := dns.svcController.HasSynced() b := true if dns.epController != nil { - dns.epLock.RLock() b = dns.epController.HasSynced() - dns.epLock.RUnlock() } c := true if dns.podController != nil { @@ -455,8 +373,6 @@ func (dns *dnsControl) ServiceList() (svcs []*object.Service) { } func (dns *dnsControl) EndpointsList() (eps []*object.Endpoints) { - dns.epLock.RLock() - defer dns.epLock.RUnlock() os := dns.epLister.List() for _, o := range os { ep, ok := o.(*object.Endpoints) @@ -531,8 +447,6 @@ func (dns *dnsControl) SvcExtIndexReverse(ip string) (svcs []*object.Service) { } func (dns *dnsControl) EpIndex(idx string) (ep []*object.Endpoints) { - dns.epLock.RLock() - defer dns.epLock.RUnlock() os, err := dns.epLister.ByIndex(epNameNamespaceIndex, idx) if err != nil { return nil @@ -548,8 +462,6 @@ func (dns *dnsControl) EpIndex(idx string) (ep []*object.Endpoints) { } func (dns *dnsControl) EpIndexReverse(ip string) (ep []*object.Endpoints) { - dns.epLock.RLock() - defer dns.epLock.RUnlock() os, err := dns.epLister.ByIndex(epIPIndex, ip) if err != nil { return nil |