Skip to content

Commit

Permalink
Improve the ipAddrAdd performance
Browse files Browse the repository at this point in the history
This commit replaces the `Exec()` call with `netlink.RouteReplace()`. When calling `ipAddrAdd` in a loop (e.g., inside `setupClusterIPServices`), this gives a significant performance boost.
  • Loading branch information
iamakulov committed Aug 6, 2020
1 parent e35dc9d commit d2e223b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions pkg/controllers/proxy/network_services_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/vishvananda/netlink"
"github.com/vishvananda/netns"
"golang.org/x/net/context"
"golang.org/x/sys/unix"
api "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/cache"
Expand Down Expand Up @@ -140,12 +141,17 @@ func (ln *linuxNetworking) ipAddrAdd(iface netlink.Link, ip string, addRoute boo
return nil
}

// TODO: netlink.RouteReplace which is replacement for below command is not working as expected. Call succeeds but
// route is not replaced. For now do it with command.
out, err := exec.Command("ip", "route", "replace", "local", ip, "dev", KubeDummyIf, "table", "local", "proto", "kernel", "scope", "host", "src",
NodeIP.String(), "table", "local").CombinedOutput()
err = netlink.RouteReplace(&netlink.Route{
Dst: &net.IPNet{IP: net.ParseIP(ip), Mask: net.IPv4Mask(255, 255, 255, 255)},
LinkIndex: iface.Attrs().Index,
Table: unix.RT_TABLE_LOCAL,
Protocol: unix.RTPROT_KERNEL,
Scope: unix.RT_SCOPE_HOST,
Type: unix.RTN_LOCAL,
Src: NodeIP,
})
if err != nil {
glog.Errorf("Failed to replace route to service VIP %s configured on %s. Error: %v, Output: %s", ip, KubeDummyIf, err, out)
glog.Errorf("Failed to replace route to service VIP %s configured on %s. Error: %v", ip, KubeDummyIf, err)
}
return nil
}
Expand Down

0 comments on commit d2e223b

Please sign in to comment.