From: VZ Cambria Date: Thu, 2 Mar 2017 13:40:03 +0000 (-0500) Subject: Add viaIP label and use viaIP when adding route X-Git-Url: https://git.halfball.org/?a=commitdiff_plain;h=b158d62691059c0e450281004437ac5e41a7f8f4;p=cni.git Add viaIP label and use viaIP when adding route --- diff --git a/20-macvlan0.conf b/20-macvlan0.conf index 67a8d85..0c7e526 100644 --- a/20-macvlan0.conf +++ b/20-macvlan0.conf @@ -2,7 +2,7 @@ "cniVersion": "0.2.0", "name": "macvlan0", "type": "macvlan", - "master": "em1", + "master": "eth1p0", "args" : { "org.apache.mesos" : { "network_info" : { @@ -13,7 +13,8 @@ { "key" : "mccKey1", "value" : "mccVal1" }, { "key" : "bs", "value" : "bsVal" }, { "key" : "StaticIP", "value" : "172.19.0.209" }, - { "key" : "viaIP", "value" : "eth1p0" }, + { "key" : "Uplink", "value" : "eth1p0" }, + { "key" : "viaIP", "value" : "172.19.0.1" }, { "key" : "mccKey2", "value" : "mccVal2" }, { "key" : "env", "value" : "prod" } ] diff --git a/mcc-manual-add-static-env.sh b/mcc-manual-add-static-env.sh index cfc47ab..0cf31e9 100755 --- a/mcc-manual-add-static-env.sh +++ b/mcc-manual-add-static-env.sh @@ -1,8 +1,8 @@ #/bin/bash export DEBUG=1 export NETCONFPATH=/etc/cni/net.d/ -#export CNI_PATH=/home/mcambria/go/src/github.com/containernetworking/cni/bin/ -export CNI_PATH=/home/mcambria/go2/src/stash.verizon.com/cni/bin +export CNI_PATH=/home/mcambria/go/src/github.com/containernetworking/cni/bin/ +#export CNI_PATH=/home/mcambria/go2/src/stash.verizon.com/cni/bin export NETCONFPATH=${NETCONFPATH-/etc/cni/net.d} export CNI_COMMAND=ADD export CNI_NETNS=/var/run/netns/mcc-cni-test0 diff --git a/mcc-manual-del-static-env.sh b/mcc-manual-del-static-env.sh index 83bbd05..499ac16 100755 --- a/mcc-manual-del-static-env.sh +++ b/mcc-manual-del-static-env.sh @@ -1,8 +1,8 @@ #/bin/bash export DEBUG=1 export NETCONFPATH=/etc/cni/net.d/ -#export CNI_PATH=/home/mcambria/go/src/github.com/containernetworking/cni/bin/ -export CNI_PATH=/home/mcambria/go2/src/stash.verizon.com/cni/bin +export CNI_PATH=/home/mcambria/go/src/github.com/containernetworking/cni/bin/ +#export CNI_PATH=/home/mcambria/go2/src/stash.verizon.com/cni/bin export NETCONFPATH=${NETCONFPATH-/etc/cni/net.d} export CNI_COMMAND=DEL export CNI_NETNS=/var/run/netns/mcc-cni-test0 diff --git a/plugins/ipam/vz-local/backend/allocator/allocator.go b/plugins/ipam/vz-local/backend/allocator/allocator.go index abf9951..64b685d 100644 --- a/plugins/ipam/vz-local/backend/allocator/allocator.go +++ b/plugins/ipam/vz-local/backend/allocator/allocator.go @@ -187,11 +187,11 @@ func (a *IPAllocator) Get(id string) (*current.IPConfig, []*types.Route, error) return nil, nil, err } - //gw := advertise_route + viaIP := a.conf.Args.VIAIP route := netlink.Route{ Dst: dst, LinkIndex: link.Attrs().Index, - // Gw: gw + Gw: viaIP, } if err := netlink.RouteAdd(&route); err != nil { @@ -279,11 +279,11 @@ func (a *IPAllocator) Release(id string) error { return err } - // gw := advertise_route + viaIP := a.conf.Args.VIAIP route := netlink.Route{ Dst: dst, LinkIndex: link.Attrs().Index, - //Gw: gw + Gw: viaIP, } if err := netlink.RouteDel(&route); err != nil { diff --git a/plugins/ipam/vz-local/backend/allocator/config.go b/plugins/ipam/vz-local/backend/allocator/config.go index ad95ce6..9211809 100644 --- a/plugins/ipam/vz-local/backend/allocator/config.go +++ b/plugins/ipam/vz-local/backend/allocator/config.go @@ -42,6 +42,7 @@ type IPAMConfig struct { type IPAMArgs struct { types.CommonArgs IP net.IP `json:"ip,omitempty"` + VIAIP net.IP `json:"viaip,omitempty"` UPLINK types.UnmarshallableString `json:"uplink,omitempty"` } @@ -129,7 +130,7 @@ func LoadIPAMConfig(bytes []byte, args string) (*IPAMConfig, string, error) { println("Map k (for)", k, label.Key, label.Value) } - println("CNI Args: Net Name: ", n.ARGS.Mesos.NetworkInfo.Name) + println("CNI Args NetworkInfo: Net Name: ", n.ARGS.Mesos.NetworkInfo.Name) } for key, value := range labels { @@ -145,6 +146,12 @@ func LoadIPAMConfig(bytes []byte, args string) (*IPAMConfig, string, error) { log.Println("IPAM args: n.IPAM.IP is:", args_ip) } + var via_ip net.IP + if n.IPAM.Args.VIAIP != nil { + via_ip = n.IPAM.Args.VIAIP + log.Println("IPAM args: n.IPAM.VIAIP is:", via_ip) + } + var uplink types.UnmarshallableString if n.IPAM.Args.UPLINK != "" { uplink = n.IPAM.Args.UPLINK @@ -166,13 +173,21 @@ func LoadIPAMConfig(bytes []byte, args string) (*IPAMConfig, string, error) { if found { println("viaIP is: ", viaIP) log.Println("viaIP is: ", viaIP) - n.IPAM.Args.UPLINK= types.UnmarshallableString(viaIP) - log.Println("IPAM args: n.IPAM.UPLINK is:", n.IPAM.Args.UPLINK) + n.IPAM.Args.VIAIP = net.ParseIP(viaIP) + log.Println("IPAM args: n.IPAM.VIAIP is:", n.IPAM.Args.VIAIP) } else { println("viaIP label NOT set") - } - + } + Uplink, found := labels["Uplink"] + if found { + println("Uplink is: ", Uplink) + log.Println("Uplink is: ", Uplink) + n.IPAM.Args.UPLINK= types.UnmarshallableString(Uplink) + log.Println("IPAM args: n.IPAM.UPLINK is:", n.IPAM.Args.UPLINK) + } else { + println("Uplink label NOT set") + } bull, found := labels["bull"] if !found {