mirror of
https://github.com/k8snetworkplumbingwg/multus-cni.git
synced 2025-07-21 11:00:41 +00:00
Prototype for namespace support, addresses #15
This commit is contained in:
parent
393d5f47e5
commit
ebb19edfc3
@ -294,6 +294,31 @@ func getPodNetworkAnnotation(client *kubernetes.Clientset, k8sArgs K8sArgs) (str
|
|||||||
return pod.Annotations["kubernetes.cni.cncf.io/networks"], nil
|
return pod.Annotations["kubernetes.cni.cncf.io/networks"], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parsePodNetworkObjectName(podnetwork string) (string, string, string, error) {
|
||||||
|
var netNsName string
|
||||||
|
var netIfName string
|
||||||
|
var networkName string
|
||||||
|
|
||||||
|
slashItems := strings.Split(podnetwork, "/")
|
||||||
|
if len(slashItems) == 2 {
|
||||||
|
netNsName = strings.TrimSpace(slashItems[0])
|
||||||
|
networkName = slashItems[1]
|
||||||
|
} else if len(slashItems) == 1 {
|
||||||
|
networkName = slashItems[0]
|
||||||
|
} else {
|
||||||
|
return "", "", "", fmt.Errorf("Invalid network object (failed at '/')")
|
||||||
|
}
|
||||||
|
|
||||||
|
atItems := strings.Split(networkName, "@")
|
||||||
|
networkName = strings.TrimSpace(atItems[0])
|
||||||
|
if len(atItems) == 2 {
|
||||||
|
netIfName = strings.TrimSpace(atItems[1])
|
||||||
|
} else if len(atItems) != 1 {
|
||||||
|
return "", "", "", fmt.Errorf("Invalid network object (failed at '@')")
|
||||||
|
}
|
||||||
|
return netNsName, networkName, netIfName, nil
|
||||||
|
}
|
||||||
|
|
||||||
func parsePodNetworkObject(podnetwork string) ([]map[string]interface{}, error) {
|
func parsePodNetworkObject(podnetwork string) ([]map[string]interface{}, error) {
|
||||||
var podNet []map[string]interface{}
|
var podNet []map[string]interface{}
|
||||||
|
|
||||||
@ -307,12 +332,20 @@ func parsePodNetworkObject(podnetwork string) ([]map[string]interface{}, error)
|
|||||||
commaItems := strings.Split(podnetwork, ",")
|
commaItems := strings.Split(podnetwork, ",")
|
||||||
// Build a map from the comma delimited items.
|
// Build a map from the comma delimited items.
|
||||||
for i := range commaItems {
|
for i := range commaItems {
|
||||||
atItems := strings.Split(commaItems[i], "@")
|
// Parse network name (i.e. <namespace>/<network name>@<ifname>)
|
||||||
m := make(map[string]interface{})
|
netNsName, networkName, netIfName, err := parsePodNetworkObjectName(commaItems[i])
|
||||||
m["name"] = strings.TrimSpace(atItems[0])
|
if err != nil {
|
||||||
if len(atItems) == 2 {
|
return nil, fmt.Errorf("parsePodNetworkObject: %v", err)
|
||||||
m["interfaceRequest"] = atItems[1]
|
|
||||||
}
|
}
|
||||||
|
m := make(map[string]interface{})
|
||||||
|
m["name"] = networkName
|
||||||
|
if netNsName != "" {
|
||||||
|
m["namespace"] = netNsName
|
||||||
|
}
|
||||||
|
if netIfName != "" {
|
||||||
|
m["interfaceRequest"] = netIfName
|
||||||
|
}
|
||||||
|
|
||||||
podNet = append(podNet, m)
|
podNet = append(podNet, m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -361,7 +394,12 @@ func getnetplugin(client *kubernetes.Clientset, networkinfo map[string]interface
|
|||||||
return "", fmt.Errorf("getnetplugin: network name can't be empty")
|
return "", fmt.Errorf("getnetplugin: network name can't be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
tprclient := fmt.Sprintf("/apis/cni.cncf.io/v1/namespaces/default/networks/%s", networkname)
|
netNsName := "default"
|
||||||
|
if networkinfo["namespace"] != nil {
|
||||||
|
netNsName = networkinfo["namespace"].(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
tprclient := fmt.Sprintf("/apis/cni.cncf.io/v1/namespaces/%s/networks/%s", netNsName, networkname)
|
||||||
|
|
||||||
netobjdata, err := client.ExtensionsV1beta1().RESTClient().Get().AbsPath(tprclient).DoRaw()
|
netobjdata, err := client.ExtensionsV1beta1().RESTClient().Get().AbsPath(tprclient).DoRaw()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user