@@ -40,7 +40,7 @@ type NetworkRoutingController struct {
4040	nodeSubnet            net.IPNet 
4141	nodeInterface         string 
4242	mu                    sync.Mutex 
43- 	clientset             * kubernetes.Clientset 
43+ 	clientset             kubernetes.Interface 
4444	bgpServer             * gobgp.BgpServer 
4545	syncPeriod            time.Duration 
4646	clusterCIDR           string 
@@ -227,35 +227,12 @@ func (nrc *NetworkRoutingController) Run(stopCh <-chan struct{}, wg *sync.WaitGr
227227
228228		// advertise cluster IP for the service to be reachable via host 
229229		if  nrc .advertiseClusterIp  {
230- 			glog .Infof ("Advertising cluster ips of services to the external BGP peers" )
231- 			for  _ , svc  :=  range  watchers .ServiceWatcher .List () {
232- 				if  svc .Spec .Type  ==  "ClusterIP"  ||  svc .Spec .Type  ==  "NodePort"  ||  svc .Spec .Type  ==  "LoadBalancer"  {
233- 
234- 					// skip headless services 
235- 					if  svc .Spec .ClusterIP  ==  "None"  ||  svc .Spec .ClusterIP  ==  ""  {
236- 						continue 
237- 					}
238- 
239- 					glog .Infof ("found a service of cluster ip type" )
240- 					nrc .AdvertiseClusterIp (svc .Spec .ClusterIP )
241- 				}
242- 			}
230+ 			nrc .advertiseClusterIPs ()
243231		}
244232
245233		// advertise cluster IP for the service to be reachable via host 
246234		if  nrc .advertiseExternalIp  {
247- 			glog .Infof ("Advertising external ips of the services to the external BGP peers" )
248- 			for  _ , svc  :=  range  watchers .ServiceWatcher .List () {
249- 				if  svc .Spec .Type  ==  "ClusterIP"  ||  svc .Spec .Type  ==  "NodePort"  {
250- 					// skip headless services 
251- 					if  svc .Spec .ClusterIP  ==  "None"  ||  svc .Spec .ClusterIP  ==  ""  {
252- 						continue 
253- 					}
254- 					for  _ , externalIP  :=  range  svc .Spec .ExternalIPs  {
255- 						nrc .AdvertiseClusterIp (externalIP )
256- 					}
257- 				}
258- 			}
235+ 			nrc .advertiseExternalIPs ()
259236		}
260237
261238		glog .Infof ("Performing periodic sync of the routes" )
@@ -371,6 +348,43 @@ func (nrc *NetworkRoutingController) watchBgpUpdates() {
371348	}
372349}
373350
351+ func  (nrc  * NetworkRoutingController ) advertiseClusterIPs () {
352+ 	glog .Infof ("Advertising cluster ips of services to the external BGP peers" )
353+ 	for  _ , svc  :=  range  watchers .ServiceWatcher .List () {
354+ 		if  svc .Spec .Type  ==  "ClusterIP"  ||  svc .Spec .Type  ==  "NodePort"  ||  svc .Spec .Type  ==  "LoadBalancer"  {
355+ 
356+ 			// skip headless services 
357+ 			if  svc .Spec .ClusterIP  ==  "None"  ||  svc .Spec .ClusterIP  ==  ""  {
358+ 				continue 
359+ 			}
360+ 
361+ 			glog .Infof ("found a service of cluster ip type" )
362+ 			err  :=  nrc .AdvertiseClusterIp (svc .Spec .ClusterIP )
363+ 			if  err  !=  nil  {
364+ 				glog .Errorf ("error advertising cluster IP: %q error: %v" , svc .Spec .ClusterIP , err )
365+ 			}
366+ 		}
367+ 	}
368+ }
369+ 
370+ func  (nrc  * NetworkRoutingController ) advertiseExternalIPs () {
371+ 	glog .Infof ("Advertising external ips of the services to the external BGP peers" )
372+ 	for  _ , svc  :=  range  watchers .ServiceWatcher .List () {
373+ 		if  svc .Spec .Type  ==  "ClusterIP"  ||  svc .Spec .Type  ==  "NodePort"  {
374+ 			// skip headless services 
375+ 			if  svc .Spec .ClusterIP  ==  "None"  ||  svc .Spec .ClusterIP  ==  ""  {
376+ 				continue 
377+ 			}
378+ 			for  _ , externalIP  :=  range  svc .Spec .ExternalIPs  {
379+ 				err  :=  nrc .AdvertiseClusterIp (externalIP )
380+ 				if  err  !=  nil  {
381+ 					glog .Errorf ("error advertising external IP: %q, error: %v" , externalIP , err )
382+ 				}
383+ 			}
384+ 		}
385+ 	}
386+ }
387+ 
374388func  (nrc  * NetworkRoutingController ) advertiseRoute () error  {
375389	cidr , err  :=  utils .GetPodCidrFromNodeSpec (nrc .clientset , nrc .hostnameOverride )
376390	if  err  !=  nil  {
0 commit comments