Unverified Commit 0948f96e authored by Kubernetes Prow Robot's avatar Kubernetes Prow Robot Committed by GitHub

Merge pull request #72409 from DataDog/automated-cherry-pick-of-#71895-#72106-upstream-release-1.13

Automated cherry pick of #71895 #72106 upstream release 1.13
parents 31c32d75 3b3763cb
...@@ -168,6 +168,7 @@ func (m *GracefulTerminationManager) deleteRsFunc(rsToDelete *listItem) (bool, e ...@@ -168,6 +168,7 @@ func (m *GracefulTerminationManager) deleteRsFunc(rsToDelete *listItem) (bool, e
// For UDP, ActiveConn is always 0 // For UDP, ActiveConn is always 0
// For TCP, InactiveConn are connections not in ESTABLISHED state // For TCP, InactiveConn are connections not in ESTABLISHED state
if rs.ActiveConn+rs.InactiveConn != 0 { if rs.ActiveConn+rs.InactiveConn != 0 {
klog.Infof("Not deleting, RS %v: %v ActiveConn, %v InactiveConn", rsToDelete.String(), rs.ActiveConn, rs.InactiveConn)
return false, nil return false, nil
} }
klog.Infof("Deleting rs: %s", rsToDelete.String()) klog.Infof("Deleting rs: %s", rsToDelete.String())
......
...@@ -1206,7 +1206,15 @@ func (proxier *Proxier) syncProxyRules() { ...@@ -1206,7 +1206,15 @@ func (proxier *Proxier) syncProxyRules() {
} }
proxier.portsMap = replacementPortsMap proxier.portsMap = replacementPortsMap
// Clean up legacy IPVS services // Get legacy bind address
// currentBindAddrs represents ip addresses bind to DefaultDummyDevice from the system
currentBindAddrs, err := proxier.netlinkHandle.ListBindAddress(DefaultDummyDevice)
if err != nil {
klog.Errorf("Failed to get bind address, err: %v", err)
}
legacyBindAddrs := proxier.getLegacyBindAddr(activeBindAddrs, currentBindAddrs)
// Clean up legacy IPVS services and unbind addresses
appliedSvcs, err := proxier.ipvs.GetVirtualServers() appliedSvcs, err := proxier.ipvs.GetVirtualServers()
if err == nil { if err == nil {
for _, appliedSvc := range appliedSvcs { for _, appliedSvc := range appliedSvcs {
...@@ -1215,15 +1223,7 @@ func (proxier *Proxier) syncProxyRules() { ...@@ -1215,15 +1223,7 @@ func (proxier *Proxier) syncProxyRules() {
} else { } else {
klog.Errorf("Failed to get ipvs service, err: %v", err) klog.Errorf("Failed to get ipvs service, err: %v", err)
} }
proxier.cleanLegacyService(activeIPVSServices, currentIPVSServices) proxier.cleanLegacyService(activeIPVSServices, currentIPVSServices, legacyBindAddrs)
// Clean up legacy bind address
// currentBindAddrs represents ip addresses bind to DefaultDummyDevice from the system
currentBindAddrs, err := proxier.netlinkHandle.ListBindAddress(DefaultDummyDevice)
if err != nil {
klog.Errorf("Failed to get bind address, err: %v", err)
}
proxier.cleanLegacyBindAddr(activeBindAddrs, currentBindAddrs)
// Update healthz timestamp // Update healthz timestamp
if proxier.healthzServer != nil { if proxier.healthzServer != nil {
...@@ -1621,29 +1621,38 @@ func (proxier *Proxier) syncEndpoint(svcPortName proxy.ServicePortName, onlyNode ...@@ -1621,29 +1621,38 @@ func (proxier *Proxier) syncEndpoint(svcPortName proxy.ServicePortName, onlyNode
klog.V(5).Infof("Using graceful delete to delete: %v", uniqueRS) klog.V(5).Infof("Using graceful delete to delete: %v", uniqueRS)
err = proxier.gracefuldeleteManager.GracefulDeleteRS(appliedVirtualServer, delDest) err = proxier.gracefuldeleteManager.GracefulDeleteRS(appliedVirtualServer, delDest)
if err != nil { if err != nil {
klog.Errorf("Failed to delete destination: %v, error: %v", delDest, err) klog.Errorf("Failed to delete destination: %v, error: %v", uniqueRS, err)
continue continue
} }
} }
return nil return nil
} }
func (proxier *Proxier) cleanLegacyService(activeServices map[string]bool, currentServices map[string]*utilipvs.VirtualServer) { func (proxier *Proxier) cleanLegacyService(activeServices map[string]bool, currentServices map[string]*utilipvs.VirtualServer, legacyBindAddrs map[string]bool) {
for cs := range currentServices { for cs := range currentServices {
svc := currentServices[cs] svc := currentServices[cs]
if _, ok := activeServices[cs]; !ok { if _, ok := activeServices[cs]; !ok {
// This service was not processed in the latest sync loop so before deleting it, // This service was not processed in the latest sync loop so before deleting it,
// make sure it does not fall within an excluded CIDR range.
okayToDelete := true okayToDelete := true
rsList, _ := proxier.ipvs.GetRealServers(svc) rsList, _ := proxier.ipvs.GetRealServers(svc)
// If we still have real servers graceful termination is not done
if len(rsList) > 0 {
okayToDelete = false
}
// Applying graceful termination to all real servers
for _, rs := range rsList { for _, rs := range rsList {
uniqueRS := GetUniqueRSName(svc, rs) uniqueRS := GetUniqueRSName(svc, rs)
// if there are in terminating real server in this service, then handle it later // If RS is already in the graceful termination list, no need to add it again
if proxier.gracefuldeleteManager.InTerminationList(uniqueRS) { if proxier.gracefuldeleteManager.InTerminationList(uniqueRS) {
okayToDelete = false continue
break }
klog.V(5).Infof("Using graceful delete to delete: %v", uniqueRS)
if err := proxier.gracefuldeleteManager.GracefulDeleteRS(svc, rs); err != nil {
klog.Errorf("Failed to delete destination: %v, error: %v", uniqueRS, err)
} }
} }
// make sure it does not fall within an excluded CIDR range.
for _, excludedCIDR := range proxier.excludeCIDRs { for _, excludedCIDR := range proxier.excludeCIDRs {
// Any validation of this CIDR already should have occurred. // Any validation of this CIDR already should have occurred.
_, n, _ := net.ParseCIDR(excludedCIDR) _, n, _ := net.ParseCIDR(excludedCIDR)
...@@ -1653,26 +1662,33 @@ func (proxier *Proxier) cleanLegacyService(activeServices map[string]bool, curre ...@@ -1653,26 +1662,33 @@ func (proxier *Proxier) cleanLegacyService(activeServices map[string]bool, curre
} }
} }
if okayToDelete { if okayToDelete {
klog.V(4).Infof("Delete service %s", svc.String())
if err := proxier.ipvs.DeleteVirtualServer(svc); err != nil { if err := proxier.ipvs.DeleteVirtualServer(svc); err != nil {
klog.Errorf("Failed to delete service, error: %v", err) klog.Errorf("Failed to delete service %s, error: %v", svc.String(), err)
}
addr := svc.Address.String()
if _, ok := legacyBindAddrs[addr]; ok {
klog.V(4).Infof("Unbinding address %s", addr)
if err := proxier.netlinkHandle.UnbindAddress(addr, DefaultDummyDevice); err != nil {
klog.Errorf("Failed to unbind service addr %s from dummy interface %s: %v", addr, DefaultDummyDevice, err)
} else {
// In case we delete a multi-port service, avoid trying to unbind multiple times
delete(legacyBindAddrs, addr)
}
} }
} }
} }
} }
} }
func (proxier *Proxier) cleanLegacyBindAddr(activeBindAddrs map[string]bool, currentBindAddrs []string) { func (proxier *Proxier) getLegacyBindAddr(activeBindAddrs map[string]bool, currentBindAddrs []string) map[string]bool {
legacyAddrs := make(map[string]bool)
for _, addr := range currentBindAddrs { for _, addr := range currentBindAddrs {
if _, ok := activeBindAddrs[addr]; !ok { if _, ok := activeBindAddrs[addr]; !ok {
// This address was not processed in the latest sync loop legacyAddrs[addr] = true
klog.V(4).Infof("Unbind addr %s", addr)
err := proxier.netlinkHandle.UnbindAddress(addr, DefaultDummyDevice)
// Ignore no such address error when try to unbind address
if err != nil {
klog.Errorf("Failed to unbind service addr %s from dummy interface %s: %v", addr, DefaultDummyDevice, err)
}
} }
} }
return legacyAddrs
} }
// Join all words with spaces, terminate with newline and write to buff. // Join all words with spaces, terminate with newline and write to buff.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment