From 5b4c3efe651cd4be19a987fde0be3565b50ef2a2 Mon Sep 17 00:00:00 2001 From: VZ Cambria Date: Tue, 27 Dec 2016 15:58:31 -0500 Subject: [PATCH] More cleanup, sample cni config --- 20-macvlan0.conf | 33 +++++++++++++++++++++++++++++ plugins/ipam/vz-local/config.go | 37 ++++++++++++++++++++------------- 2 files changed, 56 insertions(+), 14 deletions(-) create mode 100644 20-macvlan0.conf diff --git a/20-macvlan0.conf b/20-macvlan0.conf new file mode 100644 index 0000000..cee25bd --- /dev/null +++ b/20-macvlan0.conf @@ -0,0 +1,33 @@ +{ + "cniVersion": "0.2.0", + "name": "macvlan0", + "type": "macvlan", + "master": "eth0", + "args" : { + "org.apache.mesos" : { + "network_info" : { + "name" : "mynet", + "labels" : { + "labels" : [ + { "key" : "app", "value" : "myapp" }, + { "key" : "mccKey1", "value" : "mccVal1" }, + { "key" : "bs", "value" : "bsVal" }, + { "key" : "StaticIP", "value" : "172.19.0.209" }, + { "key" : "mccKey2", "value" : "mccVal2" }, + { "key" : "env", "value" : "prod" } + ] + } + } + } + }, + "ipam": { + "type": "vz-local", + "subnet": "172.19.0.0/16", + "gateway": "172.19.0.1", + "routes": [ + { "dst": "0.0.0.0/0" }, + { "dst": "10.6.7.0/24", "gw": "172.19.0.199" } + ] + } +} + diff --git a/plugins/ipam/vz-local/config.go b/plugins/ipam/vz-local/config.go index 61ceab3..355b340 100644 --- a/plugins/ipam/vz-local/config.go +++ b/plugins/ipam/vz-local/config.go @@ -99,16 +99,16 @@ func LoadIPAMConfig(bytes []byte, args string) (*IPAMConfig, error) { // Copy net name into IPAM so not to drag Net struct around n.IPAM.Name = n.Name -/* - * Example of getting an environment variable supplied to the IPAM plugin - */ + /* + * Example of getting an environment variable supplied to the IPAM plugin + */ mccval := os.Getenv("MCCVAL") println("mccval is: ", mccval) -/* - * Get values for supplied labels - * Ensure that IPAM args (e.g. CNI_ARGS) isn't confused with args passed to CNI itself - */ + /* + * Get values for supplied labels + * Ensure that IPAM args (e.g. CNI_ARGS) isn't confused with args passed to CNI itself + */ labels := map[string]string{} if args != "" { @@ -119,6 +119,8 @@ func LoadIPAMConfig(bytes []byte, args string) (*IPAMConfig, error) { println("Map k (for)", k) println("Map k (for)", k, label.Key, label.Value) } + + println("CNI Args: Net Name: ", n.ARGS.Mesos.NetworkInfo.Name) } } @@ -126,13 +128,20 @@ func LoadIPAMConfig(bytes []byte, args string) (*IPAMConfig, error) { println("Key:", key, "Value:", value) } - if n.ARGS != nil { - println("CNI Args: Net Name: ", n.ARGS.Mesos.NetworkInfo.Name) - println("CNI Args: IPAM Name: ", n.IPAM.Name) - args_ip := n.IPAM.Args.IP - uplink := n.IPAM.Args.UPLINK - log.Println("IPAM args: n.IPAM.IP is:", args_ip) - log.Println("IPAM args: n.IPAM.UPLINK is:", uplink) + println("CNI IPAM Name: ", n.IPAM.Name) + + if n.IPAM.Args != nil { + var args_ip net.IP + if n.IPAM.Args.IP != nil { + args_ip = n.IPAM.Args.IP + log.Println("IPAM args: n.IPAM.IP is:", args_ip) + } + + var uplink types.UnmarshallableString + if n.IPAM.Args.UPLINK != "" { + uplink = n.IPAM.Args.UPLINK + log.Println("IPAM args: n.IPAM.UPLINK is:", uplink) + } } staticIP, found := labels["StaticIP"] -- 2.44.0