File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -227,7 +227,26 @@ func (nrc *NetworkRoutingController) OnServiceUpdate(objNew interface{}, objOld
227227 //
228228 // As such, it needs to be handled differently as nrc.handleServiceUpdate only withdraws VIPs if the service
229229 // endpoint is no longer scheduled on this node and its a local type service.
230- nrc .withdrawVIPs (nrc .getExternalIPsToWithdraw (getServiceObject (objOld ), getServiceObject (objNew )))
230+ withdrawnServiceVips := nrc .getExternalIPsToWithdraw (getServiceObject (objOld ), getServiceObject (objNew ))
231+
232+ // ensure external IP to be withdrawn is not used by any other service
233+ allActiveVIPs , _ , err := nrc .getActiveVIPs ()
234+ if err != nil {
235+ klog .Errorf ("Failed to get all active VIP's due to: %s" , err .Error ())
236+ return
237+ }
238+ activeVIPsMap := make (map [string ]bool )
239+ for _ , activeVIP := range allActiveVIPs {
240+ activeVIPsMap [activeVIP ] = true
241+ }
242+ withdrawVIPs := make ([]string , 0 )
243+ for _ , serviceVIP := range withdrawnServiceVips {
244+ // withdraw VIP only if updated service is the last service using the VIP
245+ if ! activeVIPsMap [serviceVIP ] {
246+ withdrawVIPs = append (withdrawVIPs , serviceVIP )
247+ }
248+ }
249+ nrc .withdrawVIPs (withdrawVIPs )
231250}
232251
233252func (nrc * NetworkRoutingController ) getExternalIPsToWithdraw (svcOld , svcNew * v1core.Service ) (out []string ) {
You can’t perform that action at this time.
0 commit comments