aboutsummaryrefslogtreecommitdiff
path: root/plugin/kubernetes/controller.go
diff options
context:
space:
mode:
authorGravatar Chris O'Haver <cohaver@infoblox.com> 2023-06-07 16:22:28 -0400
committerGravatar GitHub <noreply@github.com> 2023-06-07 16:22:28 -0400
commit6d3db023fe60caf68e1132e65c09f8cf49007a24 (patch)
treee6630a7c16194123639885c4fd07f0c37b69b1fe /plugin/kubernetes/controller.go
parent7bf37c1da049a1ac00e10d9f68b64219886574de (diff)
downloadcoredns-6d3db023fe60caf68e1132e65c09f8cf49007a24.tar.gz
coredns-6d3db023fe60caf68e1132e65c09f8cf49007a24.tar.zst
coredns-6d3db023fe60caf68e1132e65c09f8cf49007a24.zip
plugin/kubernetes: fix headless/endpoint query panics when endpoints are disabled (#6137)
* always create listers, so we dont panic 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.go52
1 files changed, 28 insertions, 24 deletions
diff --git a/plugin/kubernetes/controller.go b/plugin/kubernetes/controller.go
index 7edd18ca9..a785a003d 100644
--- a/plugin/kubernetes/controller.go
+++ b/plugin/kubernetes/controller.go
@@ -128,33 +128,37 @@ func newdnsController(ctx context.Context, kubeClient kubernetes.Interface, opts
object.DefaultProcessor(object.ToService, nil),
)
+ podLister, podController := object.NewIndexerInformer(
+ &cache.ListWatch{
+ ListFunc: podListFunc(ctx, dns.client, api.NamespaceAll, dns.selector),
+ WatchFunc: podWatchFunc(ctx, dns.client, api.NamespaceAll, dns.selector),
+ },
+ &api.Pod{},
+ cache.ResourceEventHandlerFuncs{AddFunc: dns.Add, UpdateFunc: dns.Update, DeleteFunc: dns.Delete},
+ cache.Indexers{podIPIndex: podIPIndexFunc},
+ object.DefaultProcessor(object.ToPod, nil),
+ )
+ dns.podLister = podLister
if opts.initPodCache {
- dns.podLister, dns.podController = object.NewIndexerInformer(
- &cache.ListWatch{
- ListFunc: podListFunc(ctx, dns.client, api.NamespaceAll, dns.selector),
- WatchFunc: podWatchFunc(ctx, dns.client, api.NamespaceAll, dns.selector),
- },
- &api.Pod{},
- cache.ResourceEventHandlerFuncs{AddFunc: dns.Add, UpdateFunc: dns.Update, DeleteFunc: dns.Delete},
- cache.Indexers{podIPIndex: podIPIndexFunc},
- object.DefaultProcessor(object.ToPod, nil),
- )
+ dns.podController = podController
}
+ epLister, epController := object.NewIndexerInformer(
+ &cache.ListWatch{
+ ListFunc: endpointSliceListFunc(ctx, dns.client, api.NamespaceAll, dns.selector),
+ WatchFunc: endpointSliceWatchFunc(ctx, dns.client, api.NamespaceAll, dns.selector),
+ },
+ &discovery.EndpointSlice{},
+ cache.ResourceEventHandlerFuncs{AddFunc: dns.Add, UpdateFunc: dns.Update, DeleteFunc: dns.Delete},
+ cache.Indexers{epNameNamespaceIndex: epNameNamespaceIndexFunc, epIPIndex: epIPIndexFunc},
+ object.DefaultProcessor(object.EndpointSliceToEndpoints, dns.EndpointSliceLatencyRecorder()),
+ )
+ dns.epLock.Lock()
+ dns.epLister = epLister
if opts.initEndpointsCache {
- dns.epLock.Lock()
- dns.epLister, dns.epController = object.NewIndexerInformer(
- &cache.ListWatch{
- ListFunc: endpointSliceListFunc(ctx, dns.client, api.NamespaceAll, dns.selector),
- WatchFunc: endpointSliceWatchFunc(ctx, dns.client, api.NamespaceAll, dns.selector),
- },
- &discovery.EndpointSlice{},
- cache.ResourceEventHandlerFuncs{AddFunc: dns.Add, UpdateFunc: dns.Update, DeleteFunc: dns.Delete},
- cache.Indexers{epNameNamespaceIndex: epNameNamespaceIndexFunc, epIPIndex: epIPIndexFunc},
- object.DefaultProcessor(object.EndpointSliceToEndpoints, dns.EndpointSliceLatencyRecorder()),
- )
- dns.epLock.Unlock()
+ dns.epController = epController
}
+ dns.epLock.Unlock()
dns.nsLister, dns.nsController = object.NewIndexerInformer(
&cache.ListWatch{
@@ -561,8 +565,8 @@ func (dns *dnsControl) EpIndexReverse(ip string) (ep []*object.Endpoints) {
}
// GetNodeByName return the node by name. If nothing is found an error is
-// returned. This query causes a roundtrip to the k8s API server, so use
-// sparingly. Currently this is only used for Federation.
+// returned. This query causes a round trip to the k8s API server, so use
+// sparingly. Currently, this is only used for Federation.
func (dns *dnsControl) GetNodeByName(ctx context.Context, name string) (*api.Node, error) {
v1node, err := dns.client.CoreV1().Nodes().Get(ctx, name, meta.GetOptions{})
return v1node, err