mirror of
https://github.com/coredns/coredns.git
synced 2025-10-29 01:04:15 -04:00
plugin/kubernetes: lazy initialze EndPointsList (#1168)
If we don't need it, don't initialize it. Fixes #1156
This commit is contained in:
@@ -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 (
|
||||||
|
endpointsListFunc func() []*api.Endpoints
|
||||||
endpointsList []*api.Endpoints
|
endpointsList []*api.Endpoints
|
||||||
serviceList []*api.Service
|
serviceList []*api.Service
|
||||||
idx string
|
|
||||||
)
|
)
|
||||||
|
|
||||||
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.
|
|||||||
|
|
||||||
// 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
|
||||||
|
|||||||
Reference in New Issue
Block a user