aboutsummaryrefslogtreecommitdiff
path: root/plugin/kubernetes/controller.go
diff options
context:
space:
mode:
authorGravatar Chris O'Haver <cohaver@infoblox.com> 2020-12-01 15:29:05 -0500
committerGravatar GitHub <noreply@github.com> 2020-12-01 15:29:05 -0500
commit9121e784966d52bb93696d83d9ab394ac2efd77d (patch)
treec9d6c6ac28f712116eaec06a72119fc709d8e849 /plugin/kubernetes/controller.go
parent56eea6e6099c41e8913b6c24fbbc156133f22c62 (diff)
downloadcoredns-9121e784966d52bb93696d83d9ab394ac2efd77d.tar.gz
coredns-9121e784966d52bb93696d83d9ab394ac2efd77d.tar.zst
coredns-9121e784966d52bb93696d83d9ab394ac2efd77d.zip
plugin/kubernetes: Fix dns programming duration metric (#4255)
* get data reqd to record latency before calling toFuncs * refactor out unnecessary toFunc wrappers * remove latency metric unit tests per PR feedback Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
Diffstat (limited to 'plugin/kubernetes/controller.go')
-rw-r--r--plugin/kubernetes/controller.go40
1 files changed, 21 insertions, 19 deletions
diff --git a/plugin/kubernetes/controller.go b/plugin/kubernetes/controller.go
index f9373eee9..2319cf203 100644
--- a/plugin/kubernetes/controller.go
+++ b/plugin/kubernetes/controller.go
@@ -92,9 +92,8 @@ type dnsControlOpts struct {
namespaceLabelSelector *meta.LabelSelector
namespaceSelector labels.Selector
- zones []string
- endpointNameMode bool
- skipAPIObjectsCleanup bool
+ zones []string
+ endpointNameMode bool
}
// newDNSController creates a controller for CoreDNS.
@@ -116,7 +115,7 @@ func newdnsController(ctx context.Context, kubeClient kubernetes.Interface, opts
&api.Service{},
cache.ResourceEventHandlerFuncs{AddFunc: dns.Add, UpdateFunc: dns.Update, DeleteFunc: dns.Delete},
cache.Indexers{svcNameNamespaceIndex: svcNameNamespaceIndexFunc, svcIPIndex: svcIPIndexFunc},
- object.DefaultProcessor(object.ToService(opts.skipAPIObjectsCleanup), nil),
+ object.DefaultProcessor(object.ToService, nil),
)
if opts.initPodCache {
@@ -128,7 +127,7 @@ func newdnsController(ctx context.Context, kubeClient kubernetes.Interface, opts
&api.Pod{},
cache.ResourceEventHandlerFuncs{AddFunc: dns.Add, UpdateFunc: dns.Update, DeleteFunc: dns.Delete},
cache.Indexers{podIPIndex: podIPIndexFunc},
- object.DefaultProcessor(object.ToPod(opts.skipAPIObjectsCleanup), nil),
+ object.DefaultProcessor(object.ToPod, nil),
)
}
@@ -136,28 +135,28 @@ func newdnsController(ctx context.Context, kubeClient kubernetes.Interface, opts
var (
apiObj runtime.Object
listWatch cache.ListWatch
- to func(bool) object.ToFunc
- latency object.RecordLatencyFunc
+ to object.ToFunc
+ latency *object.EndpointLatencyRecorder
)
if opts.useEndpointSlices {
apiObj = &discovery.EndpointSlice{}
listWatch.ListFunc = endpointSliceListFunc(ctx, dns.client, api.NamespaceAll, dns.selector)
listWatch.WatchFunc = endpointSliceWatchFunc(ctx, dns.client, api.NamespaceAll, dns.selector)
to = object.EndpointSliceToEndpoints
- latency = dns.recordEndpointSliceDNSProgrammingLatency
+ latency = dns.EndpointSliceLatencyRecorder()
} else {
apiObj = &api.Endpoints{}
listWatch.ListFunc = endpointsListFunc(ctx, dns.client, api.NamespaceAll, dns.selector)
listWatch.WatchFunc = endpointsWatchFunc(ctx, dns.client, api.NamespaceAll, dns.selector)
to = object.ToEndpoints
- latency = dns.recordEndpointDNSProgrammingLatency
+ latency = dns.EndpointsLatencyRecorder()
}
dns.epLister, dns.epController = object.NewIndexerInformer(
&listWatch,
apiObj,
cache.ResourceEventHandlerFuncs{AddFunc: dns.Add, UpdateFunc: dns.Update, DeleteFunc: dns.Delete},
cache.Indexers{epNameNamespaceIndex: epNameNamespaceIndexFunc, epIPIndex: epIPIndexFunc},
- object.DefaultProcessor(to(opts.skipAPIObjectsCleanup), latency),
+ object.DefaultProcessor(to, latency),
)
}
@@ -173,12 +172,19 @@ func newdnsController(ctx context.Context, kubeClient kubernetes.Interface, opts
return &dns
}
-func (dns *dnsControl) recordEndpointDNSProgrammingLatency(obj meta.Object) {
- recordDNSProgrammingLatency(dns.getServices(obj.(*api.Endpoints)), obj)
+func (dns *dnsControl) EndpointsLatencyRecorder() *object.EndpointLatencyRecorder {
+ return &object.EndpointLatencyRecorder{
+ ServiceFunc: func(o meta.Object) []*object.Service {
+ return dns.SvcIndex(object.ServiceKey(o.GetName(), o.GetNamespace()))
+ },
+ }
}
-
-func (dns *dnsControl) recordEndpointSliceDNSProgrammingLatency(obj meta.Object) {
- recordDNSProgrammingLatency(dns.SvcIndex(object.ServiceKey(obj.GetLabels()[discovery.LabelServiceName], obj.GetNamespace())), obj)
+func (dns *dnsControl) EndpointSliceLatencyRecorder() *object.EndpointLatencyRecorder {
+ return &object.EndpointLatencyRecorder{
+ ServiceFunc: func(o meta.Object) []*object.Service {
+ return dns.SvcIndex(object.ServiceKey(o.GetLabels()[discovery.LabelServiceName], o.GetNamespace()))
+ },
+ }
}
func podIPIndexFunc(obj interface{}) ([]string, error) {
@@ -518,10 +524,6 @@ func (dns *dnsControl) detectChanges(oldObj, newObj interface{}) {
}
}
-func (dns *dnsControl) getServices(endpoints *api.Endpoints) []*object.Service {
- return dns.SvcIndex(object.ServiceKey(endpoints.GetName(), endpoints.GetNamespace()))
-}
-
// subsetsEquivalent checks if two endpoint subsets are significantly equivalent
// I.e. that they have the same ready addresses, host names, ports (including protocol
// and service names for SRV)