incorporate review comments

This commit is contained in:
Murali Reddy 2021-08-18 23:02:41 +05:30 committed by Aaron U'Ren
parent 892361800b
commit 101658a51a

View File

@ -227,32 +227,30 @@ func (nrc *NetworkRoutingController) OnServiceUpdate(objNew interface{}, objOld
// //
// As such, it needs to be handled differently as nrc.handleServiceUpdate only withdraws VIPs if the service // As such, it needs to be handled differently as nrc.handleServiceUpdate only withdraws VIPs if the service
// endpoint is no longer scheduled on this node and its a local type service. // endpoint is no longer scheduled on this node and its a local type service.
withdrawnServiceVips := nrc.getExternalIPsToWithdraw(getServiceObject(objOld), getServiceObject(objNew)) nrc.withdrawVIPs(nrc.getExternalIPsToWithdraw(getServiceObject(objOld), getServiceObject(objNew)))
}
func (nrc *NetworkRoutingController) getExternalIPsToWithdraw(svcOld, svcNew *v1core.Service) (out []string) {
withdrawnServiceVips := make([]string, 0)
if svcOld != nil && svcNew != nil {
withdrawnServiceVips = getMissingPrevGen(nrc.getExternalIPs(svcOld), nrc.getExternalIPs(svcNew))
}
// ensure external IP to be withdrawn is not used by any other service // ensure external IP to be withdrawn is not used by any other service
allActiveVIPs, _, err := nrc.getActiveVIPs() allActiveVIPs, _, err := nrc.getActiveVIPs()
if err != nil { if err != nil {
klog.Errorf("Failed to get all active VIP's due to: %s", err.Error()) klog.Errorf("failed to get all active VIP's due to: %s", err.Error())
return return
} }
activeVIPsMap := make(map[string]bool) activeVIPsMap := make(map[string]bool)
for _, activeVIP := range allActiveVIPs { for _, activeVIP := range allActiveVIPs {
activeVIPsMap[activeVIP] = true activeVIPsMap[activeVIP] = true
} }
withdrawVIPs := make([]string, 0)
for _, serviceVIP := range withdrawnServiceVips { for _, serviceVIP := range withdrawnServiceVips {
// withdraw VIP only if updated service is the last service using the VIP // withdraw VIP only if updated service is the last service using the VIP
if !activeVIPsMap[serviceVIP] { if !activeVIPsMap[serviceVIP] {
withdrawVIPs = append(withdrawVIPs, serviceVIP) out = append(out, serviceVIP)
} }
} }
nrc.withdrawVIPs(withdrawVIPs)
}
func (nrc *NetworkRoutingController) getExternalIPsToWithdraw(svcOld, svcNew *v1core.Service) (out []string) {
if svcOld != nil && svcNew != nil {
out = getMissingPrevGen(nrc.getExternalIPs(svcOld), nrc.getExternalIPs(svcNew))
}
return return
} }