k8sclient: remove 'masterplugin'/primary

This is handled now by multus.go instead.
This commit is contained in:
Dan Williams
2018-06-14 22:47:01 -05:00
committed by Kuralamudhan Ramakrishnan
parent fddbbdeae8
commit 591a687b42

View File

@@ -160,7 +160,7 @@ func parsePodNetworkObject(podnetwork string) ([]map[string]interface{}, error)
return podNet, nil return podNet, nil
} }
func getCNIConfig(name string, primary bool, ifname string, confdir string) (string, error) { func getCNIConfig(name string, ifname string, confdir string) (string, error) {
// In the absence of valid keys in a Spec, the runtime (or // In the absence of valid keys in a Spec, the runtime (or
// meta-plugin) should load and execute a CNI .configlist // meta-plugin) should load and execute a CNI .configlist
@@ -191,7 +191,7 @@ func getCNIConfig(name string, primary bool, ifname string, confdir string) (str
return "", fmt.Errorf("Error loading CNI config file %s: no 'type'; perhaps this is a .conflist?", confFile) return "", fmt.Errorf("Error loading CNI config file %s: no 'type'; perhaps this is a .conflist?", confFile)
} }
return getConfig(string(conf.Bytes[:]), primary, ifname), nil return getConfig(string(conf.Bytes[:]), ifname), nil
} }
} }
@@ -199,15 +199,11 @@ func getCNIConfig(name string, primary bool, ifname string, confdir string) (str
return "", fmt.Errorf("no network available in the name %s in cni dir %s", name, confdir) return "", fmt.Errorf("no network available in the name %s in cni dir %s", name, confdir)
} }
func getPlugin(plugin string, name string, primary bool, ifname string) string { func getPlugin(plugin string, name string, ifname string) string {
tmpconfig := []string{} tmpconfig := []string{}
tmpconfig = append(tmpconfig, fmt.Sprintf(`{"cniVersion": "0.3.1" , "name": "%s", "type": "%s"`, name, plugin)) tmpconfig = append(tmpconfig, fmt.Sprintf(`{"cniVersion": "0.3.1" , "name": "%s", "type": "%s"`, name, plugin))
if primary != false {
tmpconfig = append(tmpconfig, `, "masterplugin": true`)
}
if ifname != "" { if ifname != "" {
tmpconfig = append(tmpconfig, fmt.Sprintf(`, "ifnameRequest": "%s"`, ifname)) tmpconfig = append(tmpconfig, fmt.Sprintf(`, "ifnameRequest": "%s"`, ifname))
} }
@@ -218,16 +214,12 @@ func getPlugin(plugin string, name string, primary bool, ifname string) string {
} }
func getConfig(config string, primary bool, ifname string) string { func getConfig(config string, ifname string) string {
tmpconfig := []string{} tmpconfig := []string{}
config = strings.TrimSpace(config) config = strings.TrimSpace(config)
tmpconfig = append(tmpconfig, config[:1]) tmpconfig = append(tmpconfig, config[:1])
if primary != false {
tmpconfig = append(tmpconfig, ` "masterplugin": true,`)
}
if ifname != "" { if ifname != "" {
tmpconfig = append(tmpconfig, fmt.Sprintf(` "ifnameRequest": "%s",`, ifname)) tmpconfig = append(tmpconfig, fmt.Sprintf(` "ifnameRequest": "%s",`, ifname))
} }
@@ -238,7 +230,7 @@ func getConfig(config string, primary bool, ifname string) string {
} }
func getNetSpec(ns types.NetworkSpec, name string, primary bool, ifname string) (string, error) { func getNetSpec(ns types.NetworkSpec, name string, ifname string) (string, error) {
if ns.Plugin == "" && ns.Config == "" { if ns.Plugin == "" && ns.Config == "" {
return "", fmt.Errorf("Network Object spec plugin and config can't be empty") return "", fmt.Errorf("Network Object spec plugin and config can't be empty")
@@ -257,28 +249,28 @@ func getNetSpec(ns types.NetworkSpec, name string, primary bool, ifname string)
// { “cniVersion”: “0.3.1”, “type”: <Plugin>, “name”: <Network.Name> } // { “cniVersion”: “0.3.1”, “type”: <Plugin>, “name”: <Network.Name> }
// and any additional “runtimeConfig” field per the // and any additional “runtimeConfig” field per the
// CNI specification and conventions. // CNI specification and conventions.
return getPlugin(ns.Plugin, name, primary, ifname), nil return getPlugin(ns.Plugin, name, ifname), nil
} }
// Config contains a standard JSON-encoded CNI configuration // Config contains a standard JSON-encoded CNI configuration
// or configuration list which defines the plugin chain to // or configuration list which defines the plugin chain to
// execute. If present, this key takes precedence over // execute. If present, this key takes precedence over
// Plugin. // Plugin.
return getConfig(ns.Config, primary, ifname), nil return getConfig(ns.Config, ifname), nil
} }
func getNetObject(net types.Network, primary bool, ifname string, confdir string) (string, error) { func getNetObject(net types.Network, ifname string, confdir string) (string, error) {
var config string var config string
var err error var err error
if (types.NetworkSpec{}) == net.Spec { if (types.NetworkSpec{}) == net.Spec {
config, err = getCNIConfig(net.Metadata.Name, primary, ifname, confdir) config, err = getCNIConfig(net.Metadata.Name, ifname, confdir)
if err != nil { if err != nil {
return "", fmt.Errorf("getNetObject: err in getCNIConfig: %v", err) return "", fmt.Errorf("getNetObject: err in getCNIConfig: %v", err)
} }
} else { } else {
config, err = getNetSpec(net.Spec, net.Metadata.Name, primary, ifname) config, err = getNetSpec(net.Spec, net.Metadata.Name, ifname)
if err != nil { if err != nil {
return "", fmt.Errorf("getNetObject: err in getNetSpec: %v", err) return "", fmt.Errorf("getNetObject: err in getNetSpec: %v", err)
} }
@@ -287,7 +279,7 @@ func getNetObject(net types.Network, primary bool, ifname string, confdir string
return config, nil return config, nil
} }
func getnetplugin(client KubeClient, networkinfo map[string]interface{}, primary bool, confdir, defaultNamespace string) (string, error) { func getnetplugin(client KubeClient, networkinfo map[string]interface{}, confdir, defaultNamespace string) (string, error) {
networkname := networkinfo["name"].(string) networkname := networkinfo["name"].(string)
if networkname == "" { if networkname == "" {
return "", fmt.Errorf("getnetplugin: network name can't be empty") return "", fmt.Errorf("getnetplugin: network name can't be empty")
@@ -315,7 +307,7 @@ func getnetplugin(client KubeClient, networkinfo map[string]interface{}, primary
ifnameRequest = networkinfo["interfaceRequest"].(string) ifnameRequest = networkinfo["interfaceRequest"].(string)
} }
netargs, err := getNetObject(netobj, primary, ifnameRequest, confdir) netargs, err := getNetObject(netobj, ifnameRequest, confdir)
if err != nil { if err != nil {
return "", err return "", err
} }
@@ -332,13 +324,7 @@ func getPodNetworkObj(client KubeClient, netObjs []map[string]interface{}, confd
str.WriteString("[") str.WriteString("[")
for index, net := range netObjs { for index, net := range netObjs {
var primary bool np, err = getnetplugin(client, net, confdir, defaultNamespace)
if index == 0 {
primary = true
}
np, err = getnetplugin(client, net, primary, confdir, defaultNamespace)
if err != nil { if err != nil {
return "", fmt.Errorf("getPodNetworkObj: failed in getting the netplugin: %v", err) return "", fmt.Errorf("getPodNetworkObj: failed in getting the netplugin: %v", err)
} }