From 2baf633ef241a20f6c7f66d25c1dd619a580ef38 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Thu, 11 Dec 2025 14:25:29 +0100 Subject: [PATCH] fix: Ensure that cdi.FeatureFlags are passed to CDI library Although the cdi.FeatureFlags were added as CLI arguments to the device plugin, these were not passed to the nvcdi library construction. This change ensures that these are properly captured. Signed-off-by: Evan Lezar --- cmd/nvidia-device-plugin/main.go | 43 ++++++++++++---------- cmd/nvidia-device-plugin/plugin-manager.go | 3 +- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/cmd/nvidia-device-plugin/main.go b/cmd/nvidia-device-plugin/main.go index 4c6754317..52b219e9c 100644 --- a/cmd/nvidia-device-plugin/main.go +++ b/cmd/nvidia-device-plugin/main.go @@ -41,9 +41,10 @@ import ( ) type options struct { - flags []cli.Flag - configFile string - kubeletSocket string + flags []cli.Flag + configFile string + kubeletSocket string + cdiFeatureFlags cli.StringSlice } func main() { @@ -115,19 +116,6 @@ func main() { Usage: "ensure that containers that request NVIDIA GPU resources are started with MOFED support", EnvVars: []string{"MOFED_ENABLED"}, }, - &cli.StringFlag{ - Name: "kubelet-socket", - Value: pluginapi.KubeletSocket, - Usage: "specify the socket for communicating with the kubelet; if this is empty, no connection with the kubelet is attempted", - Destination: &o.kubeletSocket, - EnvVars: []string{"KUBELET_SOCKET"}, - }, - &cli.StringFlag{ - Name: "config-file", - Usage: "the path to a config file as an alternative to command line options or environment variables", - Destination: &o.configFile, - EnvVars: []string{"CONFIG_FILE"}, - }, &cli.StringFlag{ Name: "cdi-annotation-prefix", Value: spec.DefaultCDIAnnotationPrefix, @@ -169,10 +157,25 @@ func main() { Usage: "The specified IMEX channels are required", EnvVars: []string{"IMEX_REQUIRED"}, }, + // The following CLI flags do not have equivalents in the config file. + &cli.StringFlag{ + Name: "kubelet-socket", + Value: pluginapi.KubeletSocket, + Usage: "specify the socket for communicating with the kubelet; if this is empty, no connection with the kubelet is attempted", + Destination: &o.kubeletSocket, + EnvVars: []string{"KUBELET_SOCKET"}, + }, + &cli.StringFlag{ + Name: "config-file", + Usage: "the path to a config file as an alternative to command line options or environment variables", + Destination: &o.configFile, + EnvVars: []string{"CONFIG_FILE"}, + }, &cli.StringSliceFlag{ - Name: "cdi-feature-flags", - Usage: "A set of feature flags to be passed to the CDI spec generation logic", - EnvVars: []string{"CDI_FEATURE_FLAGS"}, + Name: "cdi-feature-flags", + Usage: "A set of feature flags to be passed to the CDI spec generation logic", + EnvVars: []string{"CDI_FEATURE_FLAGS"}, + Destination: &o.cdiFeatureFlags, }, } o.flags = c.Flags @@ -364,7 +367,7 @@ func startPlugins(c *cli.Context, o *options) ([]plugin.Interface, bool, error) // Get the set of plugins. klog.Info("Retrieving plugins.") - plugins, err := GetPlugins(c.Context, infolib, nvmllib, devicelib, config) + plugins, err := GetPlugins(c.Context, infolib, nvmllib, devicelib, config, o) if err != nil { return nil, false, fmt.Errorf("error getting plugins: %v", err) } diff --git a/cmd/nvidia-device-plugin/plugin-manager.go b/cmd/nvidia-device-plugin/plugin-manager.go index 560ea0de9..677bc7956 100644 --- a/cmd/nvidia-device-plugin/plugin-manager.go +++ b/cmd/nvidia-device-plugin/plugin-manager.go @@ -31,7 +31,7 @@ import ( ) // GetPlugins returns a set of plugins for the specified configuration. -func GetPlugins(ctx context.Context, infolib info.Interface, nvmllib nvml.Interface, devicelib device.Interface, config *spec.Config) ([]plugin.Interface, error) { +func GetPlugins(ctx context.Context, infolib info.Interface, nvmllib nvml.Interface, devicelib device.Interface, config *spec.Config, o *options) ([]plugin.Interface, error) { // TODO: We could consider passing this as an argument since it should already be used to construct nvmllib. driverRoot := root(*config.Flags.Plugin.ContainerDriverRoot) @@ -58,6 +58,7 @@ func GetPlugins(ctx context.Context, infolib info.Interface, nvmllib nvml.Interf cdi.WithGdsEnabled(*config.Flags.GDSEnabled), cdi.WithMofedEnabled(*config.Flags.MOFEDEnabled), cdi.WithImexChannels(imexChannels), + cdi.WithFeatureFlags(o.cdiFeatureFlags.Value()...), ) if err != nil { return nil, fmt.Errorf("unable to create cdi handler: %v", err)