diff --git a/Makefile b/Makefile index ddc7e3e..58ff977 100644 --- a/Makefile +++ b/Makefile @@ -109,6 +109,7 @@ image: | $(BASE) ; $(info Building Docker image...) ## Build conatiner image .PHONY: clean clean: ; $(info Cleaning...) ## Cleanup everything + @$(GO) clean -modcache @rm -rf $(GOPATH) @rm -rf $(BUILDDIR) @rm -rf test diff --git a/cmd/ib-sriov-cni/main.go b/cmd/ib-sriov-cni/main.go index 3350516..42eb105 100644 --- a/cmd/ib-sriov-cni/main.go +++ b/cmd/ib-sriov-cni/main.go @@ -15,6 +15,7 @@ import ( "github.com/Mellanox/ib-sriov-cni/pkg/config" "github.com/Mellanox/ib-sriov-cni/pkg/sriov" + localtypes "github.com/Mellanox/ib-sriov-cni/pkg/types" "github.com/Mellanox/ib-sriov-cni/pkg/utils" ) @@ -32,25 +33,35 @@ func init() { runtime.LockOSThread() } +func getGUIDFromConf(netConf *localtypes.NetConf) (string, error) { + // Take from runtime config if available + if netConf.RuntimeConfig.InfinibandGUID != "" { + return netConf.RuntimeConfig.InfinibandGUID, nil + } + // Take from CNI_ARGS if available + if guid, ok := netConf.Args.CNI["guid"]; ok { + return guid, nil + } + + return "", fmt.Errorf( + "infiniBand SRIOV-CNI failed, no guid found from runtimeConfig/CNI_ARGS, please check mellanox ib-kubernets") +} + func cmdAdd(args *skel.CmdArgs) error { netConf, err := config.LoadConf(args.StdinData) if err != nil { return fmt.Errorf("infiniBand SRI-OV CNI failed to load netconf: %v", err) } - cniArgs := netConf.Args.CNI - if cniArgs[infiniBandAnnotation] != configuredInfiniBand { + if netConf.Args.CNI[infiniBandAnnotation] != configuredInfiniBand { return fmt.Errorf( "infiniBand SRIOV-CNI failed, InfiniBand status \"%s\" is not \"%s\" please check mellanox ib-kubernets", infiniBandAnnotation, configuredInfiniBand) } - guid, ok := cniArgs["guid"] - if !ok { - return fmt.Errorf( - "infiniBand SRIOV-CNI failed, no guid found from cni-args, please check mellanox ib-kubernets") + if netConf.GUID, err = getGUIDFromConf(netConf); err != nil { + return err } - netConf.GUID = guid if netConf.RdmaIso { err = utils.EnsureRdmaSystemMode() diff --git a/pkg/types/types.go b/pkg/types/types.go index aa419ec..e9f2880 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -19,7 +19,7 @@ type NetConf struct { HostIFNames string // VF netdevice name(s) HostIFGUID string // VF netdevice GUID ContIFNames string // VF names after in the container; used during deletion - GUID string `json:"-"` // VF Guid is allowed only read from cni-args of network attachment + GUID string `json:"-"` // Taken from either CNI_ARGS "guid" attribute or from RuntimeConfig PKey string `json:"pkey"` LinkState string `json:"link_state,omitempty"` // auto|enable|disable RdmaIso bool `json:"rdmaIsolation,omitempty"` @@ -27,6 +27,12 @@ type NetConf struct { Args struct { CNI map[string]string `json:"cni"` } `json:"args"` + RuntimeConfig RuntimeConf `json:"runtimeConfig,omitempty"` +} + +// RuntimeConf represents the plugin's runtime configurations +type RuntimeConf struct { + InfinibandGUID string `json:"infinibandGUID"` } // Manager provides interface invoke sriov nic related operations