k8sclient: update for removal of Plugin field from NetworkAttachmentDefinition

Plugin went away, replaced by a minimal Spec.Config field so that the CNI
version the thick plugin supports could be indicated. This means we need
to also inject the network name into the minimal CNI JSON config when
loading the Spec.Config if the network name isn't there already.
This commit is contained in:
Dan Williams
2018-07-19 11:21:31 -05:00
committed by Kuralamudhan Ramakrishnan
parent 4f8c285520
commit 6e440b4fa8
4 changed files with 71 additions and 95 deletions

View File

@@ -30,7 +30,7 @@ const (
)
// Convert raw CNI JSON into a DelegateNetConf structure
func LoadDelegateNetConf(bytes []byte) (*DelegateNetConf, error) {
func LoadDelegateNetConf(bytes []byte, ifnameRequest string) (*DelegateNetConf, error) {
delegateConf := &DelegateNetConf{}
if err := json.Unmarshal(bytes, delegateConf); err != nil {
return nil, fmt.Errorf("error unmarshalling delegate config: %v", err)
@@ -42,6 +42,10 @@ func LoadDelegateNetConf(bytes []byte) (*DelegateNetConf, error) {
return nil, fmt.Errorf("delegate must have the 'type' field")
}
if ifnameRequest != "" {
delegateConf.IfnameRequest = ifnameRequest
}
return delegateConf, nil
}
@@ -98,7 +102,7 @@ func LoadNetConf(bytes []byte) (*NetConf, error) {
if err != nil {
return nil, fmt.Errorf("error marshalling delegate %d config: %v", idx, err)
}
delegateConf, err := LoadDelegateNetConf(bytes)
delegateConf, err := LoadDelegateNetConf(bytes, "")
if err != nil {
return nil, fmt.Errorf("failed to load delegate %d config: %v", idx, err)
}

View File

@@ -75,17 +75,6 @@ type NetworkAttachmentDefinitionSpec struct {
// Plugin.
// +optional
Config string `json:"config"`
// Plugin contains the name of a CNI plugin on-disk in a
// runtime-defined path (eg /opt/cni/bin and/or other paths.
// This plugin should be executed with a basic CNI JSON
// configuration on stdin containing the Network object
// name and the plugin:
// { “cniVersion”: “0.3.1”, “type”: <Plugin>, “name”: <Network.Name> }
// and any additional “runtimeConfig” field per the
// CNI specification and conventions.
// +optional
Plugin string `json:"plugin"`
}
// NetworkSelectionElement represents one element of the JSON format