Skip to content

Commit

Permalink
skip logging Error when there is no Service object for an Endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
murali-reddy authored and aauren committed Mar 24, 2021
1 parent f4b7d61 commit c309b27
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
6 changes: 5 additions & 1 deletion pkg/controllers/proxy/network_services_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -812,11 +812,15 @@ func (nsc *NetworkServicesController) OnEndpointsUpdate(ep *api.Endpoints) {
// skip processing as we only work with VIPs in the next section. Since the ClusterIP field is immutable we don't
// need to consider previous versions of the service here as we are guaranteed if is a ClusterIP now, it was a
// ClusterIP before.
svc, err := utils.ServiceForEndpoints(&nsc.svcLister, ep)
svc, exists, err := utils.ServiceForEndpoints(&nsc.svcLister, ep)
if err != nil {
glog.Errorf("failed to convert endpoints resource to service: %s", err)
return
}
// ignore updates to Endpoints object with no corresponding Service object
if !exists {
return
}
if utils.ServiceIsHeadless(svc) {
glog.V(1).Infof("The service associated with endpoint: %s/%s is headless, skipping...", ep.Namespace, ep.Name)
return
Expand Down
7 changes: 6 additions & 1 deletion pkg/controllers/routing/ecmp_vip.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,17 @@ func (nrc *NetworkRoutingController) OnEndpointsUpdate(obj interface{}) {
return
}

svc, err := utils.ServiceForEndpoints(&nrc.svcLister, ep)
svc, exists, err := utils.ServiceForEndpoints(&nrc.svcLister, ep)
if err != nil {
glog.Errorf("failed to convert endpoints resource to service: %s", err)
return
}

// ignore updates to Endpoints object with no corresponding Service object
if !exists {
return
}

nrc.tryHandleServiceUpdate(svc, "Updating service %s/%s triggered by endpoint update event")
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/utils/service.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
package utils

import (
"fmt"
"strings"

v1core "k8s.io/api/core/v1"
"k8s.io/client-go/tools/cache"
)

func ServiceForEndpoints(ci *cache.Indexer, ep *v1core.Endpoints) (interface{}, error) {
// ServiceForEndpoints given Endpoint object return Service API object if it exists
func ServiceForEndpoints(ci *cache.Indexer, ep *v1core.Endpoints) (interface{}, bool, error) {
key, err := cache.MetaNamespaceKeyFunc(ep)
if err != nil {
return nil, err
return nil, false, err
}

item, exists, err := (*ci).GetByKey(key)
if err != nil {
return nil, err
return nil, false, err

This comment has been minimized.

Copy link
@zerkms

zerkms Apr 7, 2021

Contributor

Could all these conditions replaced by simply return item, exists, err, or even return ci.GetByKey(key)

}

if !exists {
return nil, fmt.Errorf("service resource doesn't exist for endpoints: %q", ep.Name)
return nil, false, nil
}

return item, nil
return item, true, nil
}

// ServiceIsHeadless decides whether or not the this service is a headless service which is often useful to kube-router
Expand Down

0 comments on commit c309b27

Please sign in to comment.