discovery/kubernetes/endpoints.go
func NewEndpoints(l log.Logger, svc, eps, pod cache.SharedInformer) *Endpoints {
	if l == nil {
		l = log.NewNopLogger()
	}
	e := &Endpoints{
		logger:         l,
		endpointsInf:   eps,
		endpointsStore: eps.GetStore(),
		serviceInf:     svc,
		serviceStore:   svc.GetStore(),
		podInf:         pod,
		podStore:       pod.GetStore(),
		queue:          workqueue.NewNamed("endpoints"),
	}

	e.endpointsInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
		AddFunc: func(o interface{}) {
			eventCount.WithLabelValues("endpoints", "add").Inc()
			e.enqueue(o)
		},
		UpdateFunc: func(_, o interface{}) {
			eventCount.WithLabelValues("endpoints", "update").Inc()
			e.enqueue(o)
		},
		DeleteFunc: func(o interface{}) {
			eventCount.WithLabelValues("endpoints", "delete").Inc()
			e.enqueue(o)
		},
	})

	serviceUpdate := func(o interface{}) {
		svc, err := convertToService(o)
		if err != nil {
			level.Error(e.logger).Log("msg", "converting to Service object failed", "err", err)
			return
		}

		ep := &apiv1.Endpoints{}
		ep.Namespace = svc.Namespace
		ep.Name = svc.Name
		obj, exists, err := e.endpointsStore.Get(ep)
		if exists && err == nil {
			e.enqueue(obj.(*apiv1.Endpoints))
		}

		if err != nil {
			level.Error(e.logger).Log("msg", "retrieving endpoints failed", "err", err)
		}
	}
	e.serviceInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
		// TODO(fabxc): potentially remove add and delete event handlers. Those should
		// be triggered via the endpoint handlers already.
		AddFunc: func(o interface{}) {
			eventCount.WithLabelValues("service", "add").Inc()
			serviceUpdate(o)
		},
		UpdateFunc: func(_, o interface{}) {
			eventCount.WithLabelValues("service", "update").Inc()
			serviceUpdate(o)
		},
		DeleteFunc: func(o interface{}) {
			eventCount.WithLabelValues("service", "delete").Inc()
			serviceUpdate(o)
		},
	})

	return e
}
func NewEndpoints(l log.Logger, svc, eps, pod cache.SharedInformer) *Endpoints {
	if l == nil {
		l = log.NewNopLogger()
	}
	e := &Endpoints{
		logger:         l,
		endpointsInf:   eps,
		endpointsStore: eps.GetStore(),
		serviceInf:     svc,
		serviceStore:   svc.GetStore(),
		podInf:         pod,
		podStore:       pod.GetStore(),
		queue:          workqueue.NewNamed("endpoints"),
	}

	e.endpointsInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
		AddFunc: func(o interface{}) {
			eventCount.WithLabelValues("endpoints", "add").Inc()
			e.enqueue(o)
		},
		UpdateFunc: func(_, o interface{}) {
			eventCount.WithLabelValues("endpoints", "update").Inc()
			e.enqueue(o)
		},
		DeleteFunc: func(o interface{}) {
			eventCount.WithLabelValues("endpoints", "delete").Inc()
			e.enqueue(o)
		},
	})

	serviceUpdate := func(o interface{}) {
		svc, err := convertToService(o)
		if err != nil {
			level.Error(e.logger).Log("msg", "converting to Service object failed", "err", err)
			return
		}

		ep := &apiv1.Endpoints{}
		ep.Namespace = svc.Namespace
		ep.Name = svc.Name
		obj, exists, err := e.endpointsStore.Get(ep)
		if exists && err == nil {
			e.enqueue(obj.(*apiv1.Endpoints))
		}

		if err != nil {
			level.Error(e.logger).Log("msg", "retrieving endpoints failed", "err", err)
		}
	}
	e.serviceInf.AddEventHandler(cache.ResourceEventHandlerFuncs{
		// TODO(fabxc): potentially remove add and delete event handlers. Those should
		// be triggered via the endpoint handlers already.
		AddFunc: func(o interface{}) {
			eventCount.WithLabelValues("service", "add").Inc()
			serviceUpdate(o)
		},
		UpdateFunc: func(_, o interface{}) {
			eventCount.WithLabelValues("service", "update").Inc()
			serviceUpdate(o)
		},
		DeleteFunc: func(o interface{}) {
			eventCount.WithLabelValues("service", "delete").Inc()
			serviceUpdate(o)
		},
	})

	return e
}
func NewEndpoints ( l log . Logger , svc , eps , pod cache . SharedInformer ) * Endpoints { if l == nil { l = log . NewNopLogger ( ) } e := & Endpoints { logger : l , endpointsInf : eps , endpointsStore : eps . GetStore ( ) , serviceInf : svc , serviceStore : svc . GetStore ( ) , podInf : pod , podStore : pod . GetStore ( ) , queue : workqueue . NewNamed ( " " ) , } e . endpointsInf . AddEventHandler ( cache . ResourceEventHandlerFuncs { AddFunc : func ( o interface { } ) { eventCount . WithLabelValues ( " " , " " ) . Inc ( ) e . enqueue ( o ) } , UpdateFunc : func ( _ , o interface { } ) { eventCount . WithLabelValues ( " " , " " ) . Inc ( ) e . enqueue ( o ) } , DeleteFunc : func ( o interface { } ) { eventCount . WithLabelValues ( " " , " " ) . Inc ( ) e . enqueue ( o ) } , } ) serviceUpdate := func ( o interface { } ) { svc , err := convertToService ( o ) if err != nil { level . Error ( e . logger ) . Log ( " " , " " , " " , err ) return } ep := & apiv1 . Endpoints { } ep . Namespace = svc . Namespace ep . Name = svc . Name obj , exists , err := e . endpointsStore . Get ( ep ) if exists && err == nil { e . enqueue ( obj . ( * apiv1 . Endpoints ) ) } if err != nil { level . Error ( e . logger ) . Log ( " " , " " , " " , err ) } } e . serviceInf . AddEventHandler ( cache . ResourceEventHandlerFuncs { // TODO(fabxc): potentially remove add and delete event handlers. Those should // be triggered via the endpoint handlers already. AddFunc : func ( o interface { } ) { eventCount . WithLabelValues ( " " , " " ) . Inc ( ) serviceUpdate ( o ) } , UpdateFunc : func ( _ , o interface { } ) { eventCount . WithLabelValues ( " " , " " ) . Inc ( ) serviceUpdate ( o ) } , DeleteFunc : func ( o interface { } ) { eventCount . WithLabelValues ( " " , " " ) . Inc ( ) serviceUpdate ( o ) } , } ) return e }
// NewEndpoints returns a new endpoints discovery.
NewEndpoints returns a new endpoints discovery .