From 9e96c38ebeaf6f311b2559aee3ac14395f17682b Mon Sep 17 00:00:00 2001 From: Tomofumi Hayashi Date: Thu, 1 Apr 2021 02:22:54 +0900 Subject: [PATCH] Skip to call device-info related function if not required The case withot DeviceInfo/ResourceName, we could skip functions related to device info. This change skips to call these functions if delegates does not have DeviceInfo/ResourceName. --- pkg/multus/multus.go | 2 +- pkg/types/conf.go | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/pkg/multus/multus.go b/pkg/multus/multus.go index 81cdd37de..eba8f6d0b 100644 --- a/pkg/multus/multus.go +++ b/pkg/multus/multus.go @@ -584,7 +584,7 @@ func CmdAdd(args *skel.CmdArgs, exec invoke.Exec, kubeClient *k8s.ClientInfo) (c for idx, delegate := range n.Delegates { ifName := getIfname(delegate, args.IfName, idx) rt, cniDeviceInfoPath := types.CreateCNIRuntimeConf(args, k8sArgs, ifName, n.RuntimeConfig, delegate) - if cniDeviceInfoPath != "" { + if cniDeviceInfoPath != "" && delegate.ResourceName != "" && delegate.DeviceID != "" { err = nadutils.CopyDeviceInfoForCNIFromDP(cniDeviceInfoPath, delegate.ResourceName, delegate.DeviceID) // Even if the filename is set, file may not be present. Ignore error, // but log and in the future may need to filter on specific errors. diff --git a/pkg/types/conf.go b/pkg/types/conf.go index dc8b6f356..2a1a60ea6 100644 --- a/pkg/types/conf.go +++ b/pkg/types/conf.go @@ -188,13 +188,15 @@ func CreateCNIRuntimeConf(args *skel.CmdArgs, k8sArgs *K8sArgs, ifName string, r if delegate != nil { delegateRc = mergeCNIRuntimeConfig(rc, delegate) - if delegateRc.CNIDeviceInfoFile != "" { - logging.Debugf("Warning: Existing value of CNIDeviceInfoFile will be overwritten %s", delegateRc.CNIDeviceInfoFile) + if delegateRc.DeviceID != "" { + if delegateRc.CNIDeviceInfoFile != "" { + logging.Debugf("Warning: Existing value of CNIDeviceInfoFile will be overwritten %s", delegateRc.CNIDeviceInfoFile) + } + autoDeviceInfo := fmt.Sprintf("%s-%s_%s", delegate.Name, args.ContainerID, ifName) + delegateRc.CNIDeviceInfoFile = nadutils.GetCNIDeviceInfoPath(autoDeviceInfo) + cniDeviceInfoFile = delegateRc.CNIDeviceInfoFile + logging.Debugf("Adding auto-generated CNIDeviceInfoFile: %s", delegateRc.CNIDeviceInfoFile) } - autoDeviceInfo := fmt.Sprintf("%s-%s_%s", delegate.Name, args.ContainerID, ifName) - delegateRc.CNIDeviceInfoFile = nadutils.GetCNIDeviceInfoPath(autoDeviceInfo) - cniDeviceInfoFile = delegateRc.CNIDeviceInfoFile - logging.Debugf("Adding auto-generated CNIDeviceInfoFile: %s", delegateRc.CNIDeviceInfoFile) } else { delegateRc = rc }