diff options
author | Ritu Sood <ritu.sood@intel.com> | 2019-06-07 13:33:56 -0700 |
---|---|---|
committer | Ritu Sood <ritu.sood@intel.com> | 2019-06-07 13:41:22 -0700 |
commit | f436a990507f6f24e0c6a8e7e8fb3decb9fbbbd0 (patch) | |
tree | 960a464b90ddd82ce1e53b4572ec9a0df093df7c | |
parent | aa14577f6bc672bc8622edada8a487825fdebce1 (diff) |
Fix for format issues
No code change made. Only corrected
the formatting of some files.
Change-Id: I1ccb4a0fddcc65bd7d3f93312c5417e7830fed5a
Signed-off-by: Ritu Sood <ritu.sood@intel.com>
-rw-r--r-- | cmd/ovn4nfvk8s-cni/app/helper_linux.go | 38 | ||||
-rw-r--r-- | cmd/ovn4nfvk8s-cni/ovn4nfvk8s-cni.go | 97 | ||||
-rw-r--r-- | cmd/ovn4nfvk8s-cni/ovn4nfvk8s-cni_test.go | 134 | ||||
-rw-r--r-- | internal/pkg/config/config.go | 2 | ||||
-rw-r--r-- | internal/pkg/ovn/pods.go | 8 |
5 files changed, 139 insertions, 140 deletions
diff --git a/cmd/ovn4nfvk8s-cni/app/helper_linux.go b/cmd/ovn4nfvk8s-cni/app/helper_linux.go index fc4fd94..676901e 100644 --- a/cmd/ovn4nfvk8s-cni/app/helper_linux.go +++ b/cmd/ovn4nfvk8s-cni/app/helper_linux.go @@ -144,29 +144,29 @@ var ConfigureInterface = func(args *skel.CmdArgs, namespace, podName, macAddress } 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 + // 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 + 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 diff --git a/cmd/ovn4nfvk8s-cni/ovn4nfvk8s-cni.go b/cmd/ovn4nfvk8s-cni/ovn4nfvk8s-cni.go index ec37c02..3a6b7f0 100644 --- a/cmd/ovn4nfvk8s-cni/ovn4nfvk8s-cni.go +++ b/cmd/ovn4nfvk8s-cni/ovn4nfvk8s-cni.go @@ -196,51 +196,50 @@ func addMultipleInterfaces(args *skel.CmdArgs, ovnAnnotation, namespace, podName } func addRoutes(args *skel.CmdArgs, ovnAnnotation string, dstResult types.Result) types.Result { - logrus.Infof("ovn4nfvk8s-cni: addRoutes ") - - var ovnAnnotatedMap []map[string]string - ovnAnnotatedMap, err := parseOvnNetworkObject(ovnAnnotation) - if err != nil { - logrus.Errorf("addLogicalPort : Error Parsing Ovn Route List %v", err) - return nil - } - - var result types.Result - var routes []*types.Route - for _, ovnNet := range ovnAnnotatedMap { - dst := ovnNet["dst"] - gw := ovnNet["gw"] - dev := ovnNet["dev"] - if dst == "" || gw == "" || dev == "" { - logrus.Errorf("failed in pod annotation key extract") - return nil - } - err = app.ConfigureRoute(args, dst, gw, dev) - if err != nil { - logrus.Errorf("Failed to configure interface in pod: %v", err) - return nil - } - dstAddr, dstAddrNet, _ := net.ParseCIDR(dst) - routes = append(routes, &types.Route{ - Dst: net.IPNet{IP: dstAddr, Mask: dstAddrNet.Mask}, - GW: net.ParseIP(gw), - }) - } - - result = ¤t.Result{ - Routes: routes, - } - // Build the result structure to pass back to the runtime - dstResult, err = mergeWithResult(result, dstResult) - if err != nil { - logrus.Errorf("Failed to merge results: %v", err) - return nil - } - logrus.Infof("addRoutes: %s", prettyPrint(dstResult)) - return dstResult + logrus.Infof("ovn4nfvk8s-cni: addRoutes ") -} + var ovnAnnotatedMap []map[string]string + ovnAnnotatedMap, err := parseOvnNetworkObject(ovnAnnotation) + if err != nil { + logrus.Errorf("addLogicalPort : Error Parsing Ovn Route List %v", err) + return nil + } + + var result types.Result + var routes []*types.Route + for _, ovnNet := range ovnAnnotatedMap { + dst := ovnNet["dst"] + gw := ovnNet["gw"] + dev := ovnNet["dev"] + if dst == "" || gw == "" || dev == "" { + logrus.Errorf("failed in pod annotation key extract") + return nil + } + err = app.ConfigureRoute(args, dst, gw, dev) + if err != nil { + logrus.Errorf("Failed to configure interface in pod: %v", err) + return nil + } + dstAddr, dstAddrNet, _ := net.ParseCIDR(dst) + routes = append(routes, &types.Route{ + Dst: net.IPNet{IP: dstAddr, Mask: dstAddrNet.Mask}, + GW: net.ParseIP(gw), + }) + } + + result = ¤t.Result{ + Routes: routes, + } + // Build the result structure to pass back to the runtime + dstResult, err = mergeWithResult(result, dstResult) + if err != nil { + logrus.Errorf("Failed to merge results: %v", err) + return nil + } + logrus.Infof("addRoutes: %s", prettyPrint(dstResult)) + return dstResult +} func cmdAdd(args *skel.CmdArgs) error { logrus.Infof("ovn4nfvk8s-cni: cmdAdd ") @@ -289,12 +288,12 @@ func cmdAdd(args *skel.CmdArgs) error { return fmt.Errorf("Error while obtaining pod annotations") } result := addMultipleInterfaces(args, ovnAnnotation, namespace, podName) - // Add Routes to the pod if annotation found for routes - ovnRouteAnnotation, ok := annotation["ovnNetworkRoutes"] - if ok { - logrus.Infof("ovn4nfvk8s-cni: ovnNetworkRoutes Annotation Found %+v", ovnRouteAnnotation) - result = addRoutes(args, ovnRouteAnnotation, result) - } + // Add Routes to the pod if annotation found for routes + ovnRouteAnnotation, ok := annotation["ovnNetworkRoutes"] + if ok { + logrus.Infof("ovn4nfvk8s-cni: ovnNetworkRoutes Annotation Found %+v", ovnRouteAnnotation) + result = addRoutes(args, ovnRouteAnnotation, result) + } return result.Print() } diff --git a/cmd/ovn4nfvk8s-cni/ovn4nfvk8s-cni_test.go b/cmd/ovn4nfvk8s-cni/ovn4nfvk8s-cni_test.go index e1190ca..16296e3 100644 --- a/cmd/ovn4nfvk8s-cni/ovn4nfvk8s-cni_test.go +++ b/cmd/ovn4nfvk8s-cni/ovn4nfvk8s-cni_test.go @@ -3,14 +3,14 @@ package main import ( - "encoding/json" + "encoding/json" "github.com/containernetworking/cni/pkg/skel" - "github.com/containernetworking/cni/pkg/types" + "github.com/containernetworking/cni/pkg/types" "github.com/containernetworking/cni/pkg/types/current" - "net" + "net" "ovn4nfv-k8s-plugin/cmd/ovn4nfvk8s-cni/app" - "reflect" + "reflect" "testing" ) @@ -26,11 +26,11 @@ func TestAddMultipleInterfaces(t *testing.T) { Sandbox: "102103104", }}, nil } - oldConfigureRoute := app.ConfigureRoute - defer func() { app.ConfigureRoute = oldConfigureRoute }() - app.ConfigureRoute = func(args *skel.CmdArgs, dst, gw, dev string) error { - return nil - } + oldConfigureRoute := app.ConfigureRoute + defer func() { app.ConfigureRoute = oldConfigureRoute }() + app.ConfigureRoute = func(args *skel.CmdArgs, dst, gw, dev string) error { + return nil + } args := &skel.CmdArgs{"102103104", "default", "eth0", "", "", nil} ovnAnnotation := "[{\"ip_address\":\"172.16.24.2/24\", \"mac_address\":\"0a:00:00:00:00:0c\", \"gateway_ip\": \"172.16.24.1\",\"interface\":\"net0\"}] " @@ -38,7 +38,7 @@ func TestAddMultipleInterfaces(t *testing.T) { if result == nil { t.Errorf("Failed addMultipleInterfaces %+v", ovnAnnotation) } - resultSave := result + resultSave := result ovnAnnotation = "[{\"ip_address\":\"172.16.24.2/24\", \"mac_address\":\"0a:00:00:00:00:0c\", \"gateway_ip\": \"172.16.24.1\",\"defaultGateway\":\"true\",\"interface\":\"net0\"}] " result = addMultipleInterfaces(args, ovnAnnotation, "default", "pod") if result == nil { @@ -64,63 +64,63 @@ func TestAddMultipleInterfaces(t *testing.T) { if result == nil { t.Errorf("Failed addMultipleInterfaces %+v", ovnAnnotation) } - // Test add route feature - ovnRoutesAnnotation := "[{ \"dst\": \"172.16.29.0/24\", \"gw\": \"172.16.24.1\", \"dev\": \"eth0\" }]" - result = addRoutes(args, ovnRoutesAnnotation, resultSave) - if result == nil { - t.Errorf("Failed addRoutes %+v", ovnRoutesAnnotation) - } + // Test add route feature + ovnRoutesAnnotation := "[{ \"dst\": \"172.16.29.0/24\", \"gw\": \"172.16.24.1\", \"dev\": \"eth0\" }]" + result = addRoutes(args, ovnRoutesAnnotation, resultSave) + if result == nil { + t.Errorf("Failed addRoutes %+v", ovnRoutesAnnotation) + } - ovnRoutesAnnotation = "[{ \"dst\": \"172.16.30.0/24\", \"gw\": \"172.16.25.1\", \"dev\": \"eth0\"}, { \"dst\": \"172.16.31.0/24\", \"gw\": \"172.16.26.1\", \"dev\": \"eth1\" }]" - result = addRoutes(args, ovnRoutesAnnotation, resultSave) - if result == nil { - t.Errorf("Failed addRoutes %+v", ovnRoutesAnnotation) - } - newResult, err := current.NewResultFromResult(result) - if err != nil { - t.Errorf("Failed addMultipleInterfaces %+v", newResult) - } - addr1, addrNet1, _ := net.ParseCIDR("172.16.24.2/24") - addr2, addrNet2, _ := net.ParseCIDR("172.16.29.0/24") - addr3, addrNet3, _ := net.ParseCIDR("172.16.30.0/24") - addr4, addrNet4, _ := net.ParseCIDR("172.16.31.0/24") - expectedResult := ¤t.Result{ - CNIVersion: "0.3.1", - Interfaces: []*current.Interface{ - { - Name: "pod", - Mac: "0a:00:00:00:00:0c", - Sandbox: "102103104", - }, - }, - IPs: []*current.IPConfig{ - { - Version: "4", - Interface: current.Int(1), - Address: net.IPNet{IP: addr1, Mask: addrNet1.Mask}, - Gateway: net.ParseIP("172.16.24.1"), - }, - }, - Routes: []*types.Route{ - { - Dst: net.IPNet{IP: addr2, Mask: addrNet2.Mask}, - GW: net.ParseIP("172.16.24.1"), - }, - { - Dst: net.IPNet{IP: addr3, Mask: addrNet3.Mask}, - GW: net.ParseIP("172.16.25.1"), - }, - { - Dst: net.IPNet{IP: addr4, Mask: addrNet4.Mask}, - GW: net.ParseIP("172.16.26.1"), - }, - }, - DNS: types.DNS{}, - } - jsonBytes1, err := json.Marshal(newResult.Routes) - jsonBytes2, err := json.Marshal(expectedResult.Routes) - if !reflect.DeepEqual(jsonBytes1, jsonBytes2) { - t.Errorf("Routes are not correct") - } + ovnRoutesAnnotation = "[{ \"dst\": \"172.16.30.0/24\", \"gw\": \"172.16.25.1\", \"dev\": \"eth0\"}, { \"dst\": \"172.16.31.0/24\", \"gw\": \"172.16.26.1\", \"dev\": \"eth1\" }]" + result = addRoutes(args, ovnRoutesAnnotation, resultSave) + if result == nil { + t.Errorf("Failed addRoutes %+v", ovnRoutesAnnotation) + } + newResult, err := current.NewResultFromResult(result) + if err != nil { + t.Errorf("Failed addMultipleInterfaces %+v", newResult) + } + addr1, addrNet1, _ := net.ParseCIDR("172.16.24.2/24") + addr2, addrNet2, _ := net.ParseCIDR("172.16.29.0/24") + addr3, addrNet3, _ := net.ParseCIDR("172.16.30.0/24") + addr4, addrNet4, _ := net.ParseCIDR("172.16.31.0/24") + expectedResult := ¤t.Result{ + CNIVersion: "0.3.1", + Interfaces: []*current.Interface{ + { + Name: "pod", + Mac: "0a:00:00:00:00:0c", + Sandbox: "102103104", + }, + }, + IPs: []*current.IPConfig{ + { + Version: "4", + Interface: current.Int(1), + Address: net.IPNet{IP: addr1, Mask: addrNet1.Mask}, + Gateway: net.ParseIP("172.16.24.1"), + }, + }, + Routes: []*types.Route{ + { + Dst: net.IPNet{IP: addr2, Mask: addrNet2.Mask}, + GW: net.ParseIP("172.16.24.1"), + }, + { + Dst: net.IPNet{IP: addr3, Mask: addrNet3.Mask}, + GW: net.ParseIP("172.16.25.1"), + }, + { + Dst: net.IPNet{IP: addr4, Mask: addrNet4.Mask}, + GW: net.ParseIP("172.16.26.1"), + }, + }, + DNS: types.DNS{}, + } + jsonBytes1, err := json.Marshal(newResult.Routes) + jsonBytes2, err := json.Marshal(expectedResult.Routes) + if !reflect.DeepEqual(jsonBytes1, jsonBytes2) { + t.Errorf("Routes are not correct") + } } diff --git a/internal/pkg/config/config.go b/internal/pkg/config/config.go index b73dd9d..002ad80 100644 --- a/internal/pkg/config/config.go +++ b/internal/pkg/config/config.go @@ -10,7 +10,7 @@ import ( "github.com/urfave/cli" gcfg "gopkg.in/gcfg.v1" - "k8s.io/client-go/kubernetes" + "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" ) diff --git a/internal/pkg/ovn/pods.go b/internal/pkg/ovn/pods.go index fcd258e..6db6b43 100644 --- a/internal/pkg/ovn/pods.go +++ b/internal/pkg/ovn/pods.go @@ -113,10 +113,10 @@ func (oc *Controller) addLogicalPortWithSwitch(pod *kapi.Pod, logicalSwitch, ipA logicalSwitch, portName, "--", "lsp-set-addresses", portName, fmt.Sprintf("%s %s", macAddress, ipAddress), "--", "--if-exists", "clear", "logical_switch_port", portName, "dynamic_addresses", "--", "set", - "logical_switch_port", portName, - "external-ids:namespace="+pod.Namespace, - "external-ids:logical_switch="+logicalSwitch, - "external-ids:pod=true") + "logical_switch_port", portName, + "external-ids:namespace="+pod.Namespace, + "external-ids:logical_switch="+logicalSwitch, + "external-ids:pod=true") if err != nil { logrus.Errorf("Failed to add logical port to switch "+ "stdout: %q, stderr: %q (%v)", |