From 8e4da0c8ec44162728437e16a20507b946c1f61a Mon Sep 17 00:00:00 2001 From: Maryam Tahhan Date: Tue, 14 Nov 2023 16:05:31 +0000 Subject: [PATCH] device-plugin: fix container env var setting for multiple devices Signed-off-by: Maryam Tahhan --- constants/constants.go | 4 ++-- internal/deviceplugin/poolManager.go | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/constants/constants.go b/constants/constants.go index 2f4b4f2..2a09077 100644 --- a/constants/constants.go +++ b/constants/constants.go @@ -40,7 +40,7 @@ var ( /* Devices */ devicesProhibited = []string{"eno", "eth", "lo", "docker", "flannel", "cni"} // interfaces we never add to a pool - devicesEnvVar = "AFXDP_DEVICES" // env var set in the end user application pod, lists AF_XDP devices attached + devicesEnvVarPrefix = "AFXDP_DEVICES_" // env var set in the end user application pod, lists AF_XDP devices attached deviceValidNameRegex = `^[a-zA-Z0-9_-]+$` // regex to check if a string is a valid device name deviceValidNameMin = 1 // minimum length of a device name deviceValidNameMax = 50 // maximum length of a device name @@ -286,7 +286,7 @@ func init() { Devices = devices{ Prohibited: devicesProhibited, - EnvVarList: devicesEnvVar, + EnvVarList: devicesEnvVarPrefix, ValidNameRegex: deviceValidNameRegex, ValidNameMin: deviceValidNameMin, ValidNameMax: deviceValidNameMax, diff --git a/internal/deviceplugin/poolManager.go b/internal/deviceplugin/poolManager.go index 1cbdebf..3952d07 100644 --- a/internal/deviceplugin/poolManager.go +++ b/internal/deviceplugin/poolManager.go @@ -277,11 +277,8 @@ func (pm *PoolManager) Allocate(ctx context.Context, } } - // MT this doesn't really work as the env var is being set per Allocate request - // Could leave the app to deduce the af_xdp device name from the path above - // or write the device name into a file in the same path as the xskmap - // or just drop altogher? - envs[constants.Devices.EnvVarList] = strings.Join(crqt.DevicesIDs[:], " ") + envVar := constants.Devices.EnvVarList + strings.ToUpper(pm.Name) + envs[envVar] = strings.Join(crqt.DevicesIDs[:], " ") envsPrint, err := tools.PrettyString(envs) if err != nil { logging.Errorf("Error printing container environment variables: %v", err)