From 0538a2a93e77d2cc9c0c593a9791b5524bcb2dd4 Mon Sep 17 00:00:00 2001 From: Murali Reddy Date: Sun, 13 May 2018 12:38:25 +0530 Subject: [PATCH] perform clean-up of external ip from custom route table for external ip only if the table is not empty (#437) --- .../proxy/network_services_controller.go | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/pkg/controllers/proxy/network_services_controller.go b/pkg/controllers/proxy/network_services_controller.go index 6f5e5e8e..e79a4bed 100644 --- a/pkg/controllers/proxy/network_services_controller.go +++ b/pkg/controllers/proxy/network_services_controller.go @@ -1686,17 +1686,19 @@ func (ln *linuxNetworking) setupRoutesForExternalIPForDSR(serviceInfoMap service } } - // clean up stale external IPs - for _, line := range strings.Split(strings.Trim(outStr, "\n"), "\n") { - route := strings.Split(strings.Trim(line, " "), " ") - ip := route[0] - - if !activeExternalIPs[ip] { - args := []string{"route", "del", "table", externalIPRouteTableId} - args = append(args, route...) - if err = exec.Command("ip", args...).Run(); err != nil { - glog.Errorf("Failed to del route for %v in custom route table for external IP's due to: %s", ip, err) - continue + // check if there are any pbr in externalIPRouteTableId for external IP's + if len(outStr) > 0 { + // clean up stale external IPs + for _, line := range strings.Split(strings.Trim(outStr, "\n"), "\n") { + route := strings.Split(strings.Trim(line, " "), " ") + ip := route[0] + if !activeExternalIPs[ip] { + args := []string{"route", "del", "table", externalIPRouteTableId} + args = append(args, route...) + if err = exec.Command("ip", args...).Run(); err != nil { + glog.Errorf("Failed to del route for %v in custom route table for external IP's due to: %s", ip, err) + continue + } } } }