@@ -145,7 +145,7 @@ func (nrc *NetworkRoutingController) OnServiceDelete(obj interface{}) {
145145func (nrc * NetworkRoutingController ) newEndpointsEventHandler () cache.ResourceEventHandler {
146146 return cache.ResourceEventHandlerFuncs {
147147 AddFunc : func (obj interface {}) {
148- nrc .OnEndpointsUpdate (obj )
148+ nrc .OnEndpointsAdd (obj )
149149 },
150150 UpdateFunc : func (oldObj , newObj interface {}) {
151151 nrc .OnEndpointsUpdate (newObj )
@@ -158,6 +158,25 @@ func (nrc *NetworkRoutingController) newEndpointsEventHandler() cache.ResourceEv
158158 }
159159}
160160
161+ // OnEndpointsAdd handles endpoint add events from apiserver
162+ // This method calls OnEndpointsUpdate with the addition of updating BGP export policies
163+ // Calling addExportPolicies here covers the edge case where addExportPolicies fails in
164+ // OnServiceUpdate because the corresponding Endpoint resource for the
165+ // Service was not created yet.
166+ func (nrc * NetworkRoutingController ) OnEndpointsAdd (obj interface {}) {
167+ if ! nrc .bgpServerStarted {
168+ glog .V (3 ).Info ("Skipping OnAdd event to endpoint, controller still performing bootup full-sync" )
169+ return
170+ }
171+
172+ err := nrc .addExportPolicies ()
173+ if err != nil {
174+ glog .Errorf ("error adding BGP export policies: %s" , err )
175+ }
176+
177+ nrc .OnEndpointsUpdate (obj )
178+ }
179+
161180// OnEndpointsUpdate handles the endpoint updates from the kubernetes API server
162181func (nrc * NetworkRoutingController ) OnEndpointsUpdate (obj interface {}) {
163182 ep , ok := obj .(* v1core.Endpoints )
0 commit comments