Skip to content

Commit 2f39f98

Browse files
dlamottemurali-reddy
authored andcommitted
cleanup routing table 79 (external IPs) (#431)
1 parent 0a9b164 commit 2f39f98

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

pkg/controllers/proxy/network_services_controller.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,18 +1661,36 @@ func (ln *linuxNetworking) setupRoutesForExternalIPForDSR(serviceInfoMap service
16611661
if err != nil {
16621662
return errors.New("Failed to get routes in external_ip table due to: " + err.Error())
16631663
}
1664+
outStr := string(out)
1665+
activeExternalIPs := make(map[string]bool)
16641666
for _, svc := range serviceInfoMap {
16651667
for _, externalIP := range svc.externalIPs {
1666-
if !strings.Contains(string(out), externalIP) {
1668+
activeExternalIPs[externalIP] = true
1669+
1670+
if !strings.Contains(outStr, externalIP) {
16671671
if err = exec.Command("ip", "route", "add", externalIP, "dev", "kube-bridge", "table",
16681672
externalIPRouteTableId).Run(); err != nil {
1669-
return errors.New("Failed to add route for " + externalIP + " in custom route table for external IP's due to: " + err.Error())
1673+
glog.Error("Failed to add route for " + externalIP + " in custom route table for external IP's due to: " + err.Error())
1674+
continue
16701675
}
16711676
}
16721677
}
16731678
}
16741679

1675-
// TODO: cleanup routes for non-active exteranl IP's
1680+
// clean up stale external IPs
1681+
for _, line := range strings.Split(strings.Trim(outStr, "\n"), "\n") {
1682+
route := strings.Split(strings.Trim(line, " "), " ")
1683+
ip := route[0]
1684+
1685+
if !activeExternalIPs[ip] {
1686+
args := []string{"route", "del", "table", externalIPRouteTableId}
1687+
args = append(args, route...)
1688+
if err = exec.Command("ip", args...).Run(); err != nil {
1689+
glog.Errorf("Failed to del route for %v in custom route table for external IP's due to: %s", ip, err)
1690+
continue
1691+
}
1692+
}
1693+
}
16761694

16771695
return nil
16781696
}

0 commit comments

Comments
 (0)