aboutsummaryrefslogtreecommitdiffstats
path: root/cmd/ovn4nfvk8s-cni/app
diff options
context:
space:
mode:
authorRitu Sood <ritu.sood@intel.com>2019-02-17 05:58:57 -0800
committerRitu Sood <ritu.sood@intel.com>2019-02-17 06:01:05 -0800
commit8dffa72e276cd58669f589f7d2693a046f644695 (patch)
treec59b5685f1cabf99a584ed642224924086936905 /cmd/ovn4nfvk8s-cni/app
parent95d21eeecec4ea01078c62527faa0fe8c3f9c539 (diff)
Add Routes to Pod
Based on Pod annotations list ovnNetworkRoutes routes are added to the Pod namespace Change-Id: If6b8b6375d798dcbd45e51ccd5adae4b24369c5c Signed-off-by: Ritu Sood <ritu.sood@intel.com>
Diffstat (limited to 'cmd/ovn4nfvk8s-cni/app')
-rw-r--r--cmd/ovn4nfvk8s-cni/app/helper_linux.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/cmd/ovn4nfvk8s-cni/app/helper_linux.go b/cmd/ovn4nfvk8s-cni/app/helper_linux.go
index 1a98a61..fc4fd94 100644
--- a/cmd/ovn4nfvk8s-cni/app/helper_linux.go
+++ b/cmd/ovn4nfvk8s-cni/app/helper_linux.go
@@ -143,6 +143,32 @@ var ConfigureInterface = func(args *skel.CmdArgs, namespace, podName, macAddress
return []*current.Interface{hostIface, contIface}, nil
}
+func setupRoute(netns ns.NetNS, dst, gw, dev string) error {
+ // Add Route to the namespace
+ err := netns.Do(func(_ ns.NetNS) error {
+ dstAddr, dstAddrNet, _ := net.ParseCIDR(dst)
+ ipNet := net.IPNet{IP: dstAddr, Mask: dstAddrNet.Mask}
+ link, err := netlink.LinkByName(dev)
+ err = ip.AddRoute(&ipNet, net.ParseIP(gw), link)
+ if err != nil {
+ logrus.Errorf("ip.AddRoute failed %v dst %v gw %v", err, dst, gw)
+ }
+ return err
+ })
+ return err
+}
+
+// ConfigureRoute sets up the container routes
+var ConfigureRoute = func(args *skel.CmdArgs, dst, gw, dev string) error {
+ netns, err := ns.GetNS(args.Netns)
+ if err != nil {
+ return fmt.Errorf("failed to open netns %q: %v", args.Netns, err)
+ }
+ defer netns.Close()
+ err = setupRoute(netns, dst, gw, dev)
+ return err
+}
+
// PlatformSpecificCleanup deletes the OVS port
func PlatformSpecificCleanup(ifaceName string) (bool, error) {
done := false