Skip to content

Commit 8923618

Browse files
murali-reddyaauren
authored andcommitted
ensure withdrawn external IP's on service update, are not used by any
other service. i.e) check if external IP really not used by any service Fixes cloudnativelabs#1154
1 parent dc19603 commit 8923618

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

pkg/controllers/routing/ecmp_vip.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff 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

233252
func (nrc *NetworkRoutingController) getExternalIPsToWithdraw(svcOld, svcNew *v1core.Service) (out []string) {

0 commit comments

Comments
 (0)