mirror of
https://github.com/k8snetworkplumbingwg/multus-cni.git
synced 2025-10-21 23:48:25 +00:00
Add CNIDeviceFile in RuntimeConfig
DPDeviceFile is used by Device Plugins to pass device data to CNIs, as defined in the device-info-spec. The name of the DPDeviceFile is defined by the device-info-spec as: <ResourceName>-<DeviceID>-device.json If the DPDeviceFile exists, the NPWG implementation makes a copy of the file and passes the name of the file to the delegate CNI via capabilityArgs as CNIDeviceFile. If the DPDeviceFile does not exist, the filename is still passed to the CNI. The CNI can create the file and popluate it if a device is created within the CNI. The name of the CNIDeviceFile is not defined by device-info-spec, but to ensure the name does not clash it is formed by the following unique triplet: [networkName, PodUUID, ifName] k8snetworkplumbingwg/network-attachment-definition-client repo has utility functions to abstract some of this functionality so it can be reused across Device Plugins, NPWG implementations and CNIs. Signed-off-by: Billy McFall <22157057+Billy99@users.noreply.github.com>
This commit is contained in:
@@ -455,11 +455,19 @@ func delPlugins(exec invoke.Exec, pod *v1.Pod, args *skel.CmdArgs, k8sArgs *type
|
||||
var errorstrings []string
|
||||
for idx := lastIdx; idx >= 0; idx-- {
|
||||
ifName := getIfname(delegates[idx], args.IfName, idx)
|
||||
rt := types.CreateCNIRuntimeConf(args, k8sArgs, ifName, netRt, delegates[idx])
|
||||
rt, cniDeviceInfoPath := types.CreateCNIRuntimeConf(args, k8sArgs, ifName, netRt, delegates[idx])
|
||||
// Attempt to delete all but do not error out, instead, collect all errors.
|
||||
if err := delegateDel(exec, pod, ifName, delegates[idx], rt, binDir); err != nil {
|
||||
errorstrings = append(errorstrings, err.Error())
|
||||
}
|
||||
if cniDeviceInfoPath != "" {
|
||||
err := nadutils.CleanDeviceInfoForCNI(cniDeviceInfoPath)
|
||||
// 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.
|
||||
if err != nil {
|
||||
logging.Debugf("delPlugins: CleanDeviceInfoForCNI returned an error - err=%v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check if we had any errors, and send them all back.
|
||||
@@ -565,8 +573,16 @@ func cmdAdd(args *skel.CmdArgs, exec invoke.Exec, kubeClient *k8s.ClientInfo) (c
|
||||
cniArgs := os.Getenv("CNI_ARGS")
|
||||
for idx, delegate := range n.Delegates {
|
||||
ifName := getIfname(delegate, args.IfName, idx)
|
||||
rt, cniDeviceInfoPath := types.CreateCNIRuntimeConf(args, k8sArgs, ifName, n.RuntimeConfig, delegate)
|
||||
if cniDeviceInfoPath != "" {
|
||||
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.
|
||||
if err != nil {
|
||||
logging.Debugf("cmdAdd: CopyDeviceInfoForCNIFromDP returned an error - err=%v", err)
|
||||
}
|
||||
}
|
||||
|
||||
rt := types.CreateCNIRuntimeConf(args, k8sArgs, ifName, n.RuntimeConfig, delegate)
|
||||
tmpResult, err = delegateAdd(exec, kubeClient, pod, ifName, delegate, rt, n.BinDir, cniArgs)
|
||||
if err != nil {
|
||||
// If the add failed, tear down all networks we already added
|
||||
@@ -658,7 +674,7 @@ func cmdCheck(args *skel.CmdArgs, exec invoke.Exec, kubeClient *k8s.ClientInfo)
|
||||
for idx, delegate := range in.Delegates {
|
||||
ifName := getIfname(delegate, args.IfName, idx)
|
||||
|
||||
rt := types.CreateCNIRuntimeConf(args, k8sArgs, ifName, in.RuntimeConfig, delegate)
|
||||
rt, _ := types.CreateCNIRuntimeConf(args, k8sArgs, ifName, in.RuntimeConfig, delegate)
|
||||
err = delegateCheck(exec, ifName, delegate, rt, in.BinDir)
|
||||
if err != nil {
|
||||
return err
|
||||
|
Reference in New Issue
Block a user