@@ -47,6 +47,7 @@ type NetworkRoutingController struct {
4747 enablePodEgress bool
4848 hostnameOverride string
4949 advertiseClusterIp bool
50+ advertiseExternalIp bool
5051 defaultNodeAsnNumber uint32
5152 nodeAsnNumber uint32
5253 globalPeerRouters []* config.NeighborConfig
@@ -207,7 +208,7 @@ func (nrc *NetworkRoutingController) Run(stopCh <-chan struct{}, wg *sync.WaitGr
207208
208209 // advertise cluster IP for the service to be reachable via host
209210 if nrc .advertiseClusterIp {
210- glog .Infof ("Advertising cluster ips" )
211+ glog .Infof ("Advertising cluster ips of services to the external BGP peers " )
211212 for _ , svc := range watchers .ServiceWatcher .List () {
212213 if svc .Spec .Type == "ClusterIP" || svc .Spec .Type == "NodePort" || svc .Spec .Type == "LoadBalancer" {
213214
@@ -222,6 +223,22 @@ func (nrc *NetworkRoutingController) Run(stopCh <-chan struct{}, wg *sync.WaitGr
222223 }
223224 }
224225
226+ // advertise cluster IP for the service to be reachable via host
227+ if nrc .advertiseExternalIp {
228+ glog .Infof ("Advertising external ips of the services to the external BGP peers" )
229+ for _ , svc := range watchers .ServiceWatcher .List () {
230+ if svc .Spec .Type == "ClusterIP" || svc .Spec .Type == "NodePort" {
231+ // skip headless services
232+ if svc .Spec .ClusterIP == "None" || svc .Spec .ClusterIP == "" {
233+ continue
234+ }
235+ for _ , externalIP := range svc .Spec .ExternalIPs {
236+ nrc .AdvertiseClusterIp (externalIP )
237+ }
238+ }
239+ }
240+ }
241+
225242 glog .Infof ("Performing periodic syn of the routes" )
226243 err = nrc .advertiseRoute ()
227244 if err != nil {
@@ -370,6 +387,21 @@ func (nrc *NetworkRoutingController) getClusterIps() ([]string, error) {
370387 return clusterIpList , nil
371388}
372389
390+ func (nrc * NetworkRoutingController ) getExternalIps () ([]string , error ) {
391+ externalIpList := make ([]string , 0 )
392+ for _ , svc := range watchers .ServiceWatcher .List () {
393+ if svc .Spec .Type == "ClusterIP" || svc .Spec .Type == "NodePort" {
394+
395+ // skip headless services
396+ if svc .Spec .ClusterIP == "None" || svc .Spec .ClusterIP == "" {
397+ continue
398+ }
399+ externalIpList = append (externalIpList , svc .Spec .ExternalIPs ... )
400+ }
401+ }
402+ return externalIpList , nil
403+ }
404+
373405// Used for processing Annotations that may contain multiple items
374406// Pass this the string and the delimiter
375407func stringToSlice (s , d string ) []string {
@@ -525,6 +557,10 @@ func (nrc *NetworkRoutingController) addExportPolicies() error {
525557 for _ , ip := range clusterIps {
526558 clusterIpPrefixList = append (clusterIpPrefixList , config.Prefix {IpPrefix : ip + "/32" })
527559 }
560+ externalIps , _ := nrc .getExternalIps ()
561+ for _ , ip := range externalIps {
562+ clusterIpPrefixList = append (clusterIpPrefixList , config.Prefix {IpPrefix : ip + "/32" })
563+ }
528564 clusterIpPrefixSet , err := table .NewPrefixSet (config.PrefixSet {
529565 PrefixSetName : "clusteripprefixset" ,
530566 PrefixList : clusterIpPrefixList ,
@@ -1307,6 +1343,7 @@ func NewNetworkRoutingController(clientset *kubernetes.Clientset,
13071343 }
13081344
13091345 nrc .advertiseClusterIp = kubeRouterConfig .AdvertiseClusterIp
1346+ nrc .advertiseExternalIp = kubeRouterConfig .AdvertiseExternalIp
13101347
13111348 nrc .enableOverlays = kubeRouterConfig .EnableOverlay
13121349
0 commit comments