Skip to content

Commit 2baf633

Browse files
committed
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 <[email protected]>
1 parent 1d77539 commit 2baf633

File tree

2 files changed

+25
-21
lines changed

2 files changed

+25
-21
lines changed

cmd/nvidia-device-plugin/main.go

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ import (
4141
)
4242

4343
type options struct {
44-
flags []cli.Flag
45-
configFile string
46-
kubeletSocket string
44+
flags []cli.Flag
45+
configFile string
46+
kubeletSocket string
47+
cdiFeatureFlags cli.StringSlice
4748
}
4849

4950
func main() {
@@ -115,19 +116,6 @@ func main() {
115116
Usage: "ensure that containers that request NVIDIA GPU resources are started with MOFED support",
116117
EnvVars: []string{"MOFED_ENABLED"},
117118
},
118-
&cli.StringFlag{
119-
Name: "kubelet-socket",
120-
Value: pluginapi.KubeletSocket,
121-
Usage: "specify the socket for communicating with the kubelet; if this is empty, no connection with the kubelet is attempted",
122-
Destination: &o.kubeletSocket,
123-
EnvVars: []string{"KUBELET_SOCKET"},
124-
},
125-
&cli.StringFlag{
126-
Name: "config-file",
127-
Usage: "the path to a config file as an alternative to command line options or environment variables",
128-
Destination: &o.configFile,
129-
EnvVars: []string{"CONFIG_FILE"},
130-
},
131119
&cli.StringFlag{
132120
Name: "cdi-annotation-prefix",
133121
Value: spec.DefaultCDIAnnotationPrefix,
@@ -169,10 +157,25 @@ func main() {
169157
Usage: "The specified IMEX channels are required",
170158
EnvVars: []string{"IMEX_REQUIRED"},
171159
},
160+
// The following CLI flags do not have equivalents in the config file.
161+
&cli.StringFlag{
162+
Name: "kubelet-socket",
163+
Value: pluginapi.KubeletSocket,
164+
Usage: "specify the socket for communicating with the kubelet; if this is empty, no connection with the kubelet is attempted",
165+
Destination: &o.kubeletSocket,
166+
EnvVars: []string{"KUBELET_SOCKET"},
167+
},
168+
&cli.StringFlag{
169+
Name: "config-file",
170+
Usage: "the path to a config file as an alternative to command line options or environment variables",
171+
Destination: &o.configFile,
172+
EnvVars: []string{"CONFIG_FILE"},
173+
},
172174
&cli.StringSliceFlag{
173-
Name: "cdi-feature-flags",
174-
Usage: "A set of feature flags to be passed to the CDI spec generation logic",
175-
EnvVars: []string{"CDI_FEATURE_FLAGS"},
175+
Name: "cdi-feature-flags",
176+
Usage: "A set of feature flags to be passed to the CDI spec generation logic",
177+
EnvVars: []string{"CDI_FEATURE_FLAGS"},
178+
Destination: &o.cdiFeatureFlags,
176179
},
177180
}
178181
o.flags = c.Flags
@@ -364,7 +367,7 @@ func startPlugins(c *cli.Context, o *options) ([]plugin.Interface, bool, error)
364367

365368
// Get the set of plugins.
366369
klog.Info("Retrieving plugins.")
367-
plugins, err := GetPlugins(c.Context, infolib, nvmllib, devicelib, config)
370+
plugins, err := GetPlugins(c.Context, infolib, nvmllib, devicelib, config, o)
368371
if err != nil {
369372
return nil, false, fmt.Errorf("error getting plugins: %v", err)
370373
}

cmd/nvidia-device-plugin/plugin-manager.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
)
3232

3333
// GetPlugins returns a set of plugins for the specified configuration.
34-
func GetPlugins(ctx context.Context, infolib info.Interface, nvmllib nvml.Interface, devicelib device.Interface, config *spec.Config) ([]plugin.Interface, error) {
34+
func GetPlugins(ctx context.Context, infolib info.Interface, nvmllib nvml.Interface, devicelib device.Interface, config *spec.Config, o *options) ([]plugin.Interface, error) {
3535
// TODO: We could consider passing this as an argument since it should already be used to construct nvmllib.
3636
driverRoot := root(*config.Flags.Plugin.ContainerDriverRoot)
3737

@@ -58,6 +58,7 @@ func GetPlugins(ctx context.Context, infolib info.Interface, nvmllib nvml.Interf
5858
cdi.WithGdsEnabled(*config.Flags.GDSEnabled),
5959
cdi.WithMofedEnabled(*config.Flags.MOFEDEnabled),
6060
cdi.WithImexChannels(imexChannels),
61+
cdi.WithFeatureFlags(o.cdiFeatureFlags.Value()...),
6162
)
6263
if err != nil {
6364
return nil, fmt.Errorf("unable to create cdi handler: %v", err)

0 commit comments

Comments
 (0)