diff --git a/README.md b/README.md index 8ef6644b6..d5537e72d 100644 --- a/README.md +++ b/README.md @@ -280,10 +280,10 @@ sriov-vlanid-l2enable-conf Network.v1.kubernetes-network.cni.cncf.io sriov-conf Network.v1.kubernetes-network.cni.cncf.io ``` ### Configuring Multus to use the kubeconfig -1. Create Multus CNI configuration file /etc/cni/net.d/multus-cni.conf with below content in minions. Use only the absolute path to point to the kubeconfig file (it may change depending upon your cluster env) and make sure all CNI binary files are in `\opt\cni\bin` dir +1. Create Multus CNI configuration file /etc/cni/net.d/multus-cni.conf with below content on the nodes. Use only the absolute path to point to the kubeconfig file (it may change depending upon your cluster env) and make sure all CNI binary files are in `\opt\cni\bin` dir ``` { - "name": "minion-cni-network", + "name": "node-cni-network", "type": "multus", "kubeconfig": "/etc/kubernetes/node-kubeconfig.yaml" } @@ -296,7 +296,7 @@ sriov-conf Network.v1.kubernetes-network.cni.cncf.io 1. Many user want default networking feature along with Network object. Refer [#14](https://github.com/Intel-Corp/multus-cni/issues/14) & [#17](https://github.com/Intel-Corp/multus-cni/issues/17) issues for more information. In this following config, Weave act as the default network in the absence of network field in the pod metadata annotation. ``` { - "name": "minion-cni-network", + "name": "node-cni-network", "type": "multus", "kubeconfig": "/etc/kubernetes/node-kubeconfig.yaml", "delegates": [{ diff --git a/multus/multus.go b/multus/multus.go index d7fdf95c6..db7b341b7 100644 --- a/multus/multus.go +++ b/multus/multus.go @@ -209,6 +209,12 @@ func delegateAdd(podif func() string, argif string, netconf map[string]interface } } + if netconf["ifnameRequest"] != nil { + if os.Setenv("CNI_IFNAME", netconf["ifnameRequest"].(string)) != nil { + return true, fmt.Errorf("Multus: error in setting CNI_IFNAME") + } + } + result, err := invoke.DelegateAdd(netconf["type"].(string), netconfBytes) if err != nil { return true, fmt.Errorf("Multus: error in invoke Delegate add - %q: %v", netconf["type"].(string), err) @@ -304,8 +310,12 @@ func parsePodNetworkObject(podnetwork string) ([]map[string]interface{}, error) commaItems := strings.Split(podnetwork, ",") // Build a map from the comma delimited items. for i := range commaItems { + atItems := strings.Split(commaItems[i], "@") m := make(map[string]interface{}) - m["name"] = strings.TrimSpace(commaItems[i]) + m["name"] = strings.TrimSpace(atItems[0]) + if len(atItems) == 2 { + m["interfaceRequest"] = atItems[1] + } podNet = append(podNet,m) } } @@ -313,7 +323,12 @@ func parsePodNetworkObject(podnetwork string) ([]map[string]interface{}, error) return podNet, nil } -func getpluginargs(name string, args string, primary bool) (string, error) { +func isJSON(str string) bool { + var js json.RawMessage + return json.Unmarshal([]byte(str), &js) == nil +} + +func getpluginargs(name string, args string, primary bool, ifname string) (string, error) { var netconf string var tmpargs []string @@ -322,11 +337,16 @@ func getpluginargs(name string, args string, primary bool) (string, error) { } if primary != false { - tmpargs = []string{`{"type": "`, name, `","masterplugin": true,`, args[strings.Index(args, "\"") : len(args)-1]} + tmpargs = []string{`{"type": "`, name, `","masterplugin": true,`} } else { - tmpargs = []string{`{"type": "`, name, `",`, args[strings.Index(args, "\"") : len(args)-1]} + tmpargs = []string{`{"type": "`, name, `",`} } + if ifname != "" { + tmpargs = append(tmpargs, fmt.Sprintf(`"ifnameRequest": "%s",`, ifname)) + } + tmpargs = append(tmpargs, args[strings.Index(args, "\"") : len(args)-1]) + var str bytes.Buffer for _, a := range tmpargs { @@ -338,7 +358,8 @@ func getpluginargs(name string, args string, primary bool) (string, error) { } -func getnetplugin(client *kubernetes.Clientset, networkname string, primary bool) (string, error) { +func getnetplugin(client *kubernetes.Clientset, networkinfo map[string]interface{}, primary bool) (string, error) { + networkname := networkinfo["name"].(string) if networkname == "" { return "", fmt.Errorf("getnetplugin: network name can't be empty") } @@ -355,7 +376,12 @@ func getnetplugin(client *kubernetes.Clientset, networkname string, primary bool return "", fmt.Errorf("getnetplugin: failed to get the netplugin data: %v", err) } - netargs, err := getpluginargs(np.Plugin, np.Args, primary) + ifnameRequest := "" + if networkinfo["interfaceRequest"] != nil { + ifnameRequest = networkinfo["interfaceRequest"].(string) + } + + netargs, err := getpluginargs(np.Plugin, np.Args, primary, ifnameRequest) if err != nil { return "", err } @@ -378,7 +404,7 @@ func getPodNetworkObj(client *kubernetes.Clientset, netObjs []map[string]interfa primary = true } - np, err = getnetplugin(client, net["name"].(string), primary) + np, err = getnetplugin(client, net, primary) if err != nil { return "", fmt.Errorf("getPodNetworkObj: failed in getting the netplugin: %v", err) }