Skip to content

Commit 6ba2e94

Browse files
andrewsykimmurali-reddy
authored andcommitted
ignore update events for endpoints used for leader election (#390)
1 parent dd5d2fa commit 6ba2e94

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

app/controllers/network_routes_controller.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,10 @@ func (nrc *NetworkRoutingController) OnEndpointsUpdate(obj interface{}) {
14901490
return
14911491
}
14921492

1493+
if isEndpointsForLeaderElection(ep) {
1494+
return
1495+
}
1496+
14931497
svc, err := nrc.serviceForEndpoints(ep)
14941498
if err != nil {
14951499
glog.Errorf("failed to convert endpoints resource to service: %s", err)

app/controllers/network_services_controller.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ const (
4949
svcHairpinAnnotation = "kube-router.io/service.hairpin"
5050
svcLocalAnnotation = "kube-router.io/service.local"
5151
svcSkipLbIpsAnnotation = "kube-router.io/service.skiplbips"
52+
53+
LeaderElectionRecordAnnotationKey = "control-plane.alpha.kubernetes.io/leader"
5254
)
5355

5456
var (
@@ -353,6 +355,16 @@ func (nsc *NetworkServicesController) OnEndpointsUpdate(obj interface{}) {
353355

354356
glog.V(1).Info("Received endpoints update from watch API")
355357

358+
ep, ok := obj.(*api.Endpoints)
359+
if !ok {
360+
glog.Error("could not convert endpoints update object to *v1.Endpoints")
361+
return
362+
}
363+
364+
if isEndpointsForLeaderElection(ep) {
365+
return
366+
}
367+
356368
// build new endpoints map to reflect the change
357369
newEndpointsMap := nsc.buildEndpointsInfo()
358370

@@ -1617,6 +1629,11 @@ func (ln *linuxNetworking) setupRoutesForExternalIPForDSR(serviceInfoMap service
16171629
return nil
16181630
}
16191631

1632+
func isEndpointsForLeaderElection(ep *api.Endpoints) bool {
1633+
_, isLeaderElection := ep.Annotations[LeaderElectionRecordAnnotationKey]
1634+
return isLeaderElection
1635+
}
1636+
16201637
// unique identifier for a load-balanced service (namespace + name + portname)
16211638
func generateServiceId(namespace, svcName, port string) string {
16221639
return namespace + "-" + svcName + "-" + port

0 commit comments

Comments
 (0)