Commit cc490a89 authored by Miek Gieben's avatar Miek Gieben Committed by GitHub

plugin/kubernetes: lazy initialze EndPointsList (#1168)

If we don't need it, don't initialize it.

Fixes #1156
parent fcd0342e
...@@ -331,18 +331,20 @@ func (k *Kubernetes) findPods(r recordRequest, zone string) (pods []msg.Service, ...@@ -331,18 +331,20 @@ func (k *Kubernetes) findPods(r recordRequest, zone string) (pods []msg.Service,
func (k *Kubernetes) findServices(r recordRequest, zone string) (services []msg.Service, err error) { func (k *Kubernetes) findServices(r recordRequest, zone string) (services []msg.Service, err error) {
zonePath := msg.Path(zone, "coredns") zonePath := msg.Path(zone, "coredns")
err = errNoItems // Set to errNoItems to signal really nothing found, gets reset when name is matched. err = errNoItems // Set to errNoItems to signal really nothing found, gets reset when name is matched.
var ( var (
endpointsList []*api.Endpoints endpointsListFunc func() []*api.Endpoints
serviceList []*api.Service endpointsList []*api.Endpoints
idx string serviceList []*api.Service
) )
if wildcard(r.service) || wildcard(r.namespace) { if wildcard(r.service) || wildcard(r.namespace) {
serviceList = k.APIConn.ServiceList() serviceList = k.APIConn.ServiceList()
endpointsList = k.APIConn.EndpointsList() endpointsListFunc = func() []*api.Endpoints { return k.APIConn.EndpointsList() }
} else { } else {
idx = r.service + "." + r.namespace idx := r.service + "." + r.namespace
serviceList = k.APIConn.SvcIndex(idx) serviceList = k.APIConn.SvcIndex(idx)
endpointsList = k.APIConn.EpIndex(idx) endpointsListFunc = func() []*api.Endpoints { return k.APIConn.EpIndex(idx) }
} }
for _, svc := range serviceList { for _, svc := range serviceList {
...@@ -359,6 +361,9 @@ func (k *Kubernetes) findServices(r recordRequest, zone string) (services []msg. ...@@ -359,6 +361,9 @@ func (k *Kubernetes) findServices(r recordRequest, zone string) (services []msg.
// Endpoint query or headless service // Endpoint query or headless service
if svc.Spec.ClusterIP == api.ClusterIPNone || r.endpoint != "" { if svc.Spec.ClusterIP == api.ClusterIPNone || r.endpoint != "" {
if endpointsList == nil {
endpointsList = endpointsListFunc()
}
for _, ep := range endpointsList { for _, ep := range endpointsList {
if ep.ObjectMeta.Name != svc.Name || ep.ObjectMeta.Namespace != svc.Namespace { if ep.ObjectMeta.Name != svc.Name || ep.ObjectMeta.Namespace != svc.Namespace {
continue continue
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment