From 94e163b5d7bb65de6958574f460e02a7b2e0941d Mon Sep 17 00:00:00 2001 From: Andrew Sy Kim Date: Fri, 10 Aug 2018 10:10:37 -0400 Subject: [PATCH] update BGP export policies on endpoints add event (#508) --- pkg/controllers/routing/ecmp_vip.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pkg/controllers/routing/ecmp_vip.go b/pkg/controllers/routing/ecmp_vip.go index ebfbcfd6..b6510f7c 100644 --- a/pkg/controllers/routing/ecmp_vip.go +++ b/pkg/controllers/routing/ecmp_vip.go @@ -145,7 +145,7 @@ func (nrc *NetworkRoutingController) OnServiceDelete(obj interface{}) { func (nrc *NetworkRoutingController) newEndpointsEventHandler() cache.ResourceEventHandler { return cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { - nrc.OnEndpointsUpdate(obj) + nrc.OnEndpointsAdd(obj) }, UpdateFunc: func(oldObj, newObj interface{}) { nrc.OnEndpointsUpdate(newObj) @@ -158,6 +158,25 @@ func (nrc *NetworkRoutingController) newEndpointsEventHandler() cache.ResourceEv } } +// OnEndpointsAdd handles endpoint add events from apiserver +// This method calls OnEndpointsUpdate with the addition of updating BGP export policies +// Calling addExportPolicies here covers the edge case where addExportPolicies fails in +// OnServiceUpdate because the corresponding Endpoint resource for the +// Service was not created yet. +func (nrc *NetworkRoutingController) OnEndpointsAdd(obj interface{}) { + if !nrc.bgpServerStarted { + glog.V(3).Info("Skipping OnAdd event to endpoint, controller still performing bootup full-sync") + return + } + + err := nrc.addExportPolicies() + if err != nil { + glog.Errorf("error adding BGP export policies: %s", err) + } + + nrc.OnEndpointsUpdate(obj) +} + // OnEndpointsUpdate handles the endpoint updates from the kubernetes API server func (nrc *NetworkRoutingController) OnEndpointsUpdate(obj interface{}) { ep, ok := obj.(*v1core.Endpoints)