@@ -48,6 +48,14 @@ const (
4848 toolkitPidFilename = "toolkit.pid"
4949)
5050
51+ type cdiOptions struct {
52+ Enabled bool
53+ outputDir string
54+ kind string
55+ vendor string
56+ class string
57+ }
58+
5159type Options struct {
5260 DriverRoot string
5361 DevRoot string
@@ -67,11 +75,8 @@ type Options struct {
6775
6876 ContainerCLIDebug string
6977
70- cdiEnabled bool
71- cdiOutputDir string
72- cdiKind string
73- cdiVendor string
74- cdiClass string
78+ // CDI stores the CDI options for the toolkit.
79+ CDI cdiOptions
7580
7681 createDeviceNodes cli.StringSlice
7782
@@ -174,21 +179,21 @@ func Flags(opts *Options) []cli.Flag {
174179 Name : "cdi-enabled" ,
175180 Aliases : []string {"enable-cdi" },
176181 Usage : "enable the generation of a CDI specification" ,
177- Destination : & opts .cdiEnabled ,
182+ Destination : & opts .CDI . Enabled ,
178183 EnvVars : []string {"CDI_ENABLED" , "ENABLE_CDI" },
179184 },
180185 & cli.StringFlag {
181186 Name : "cdi-output-dir" ,
182187 Usage : "the directory where the CDI output files are to be written. If this is set to '', no CDI specification is generated." ,
183188 Value : "/var/run/cdi" ,
184- Destination : & opts .cdiOutputDir ,
189+ Destination : & opts .CDI . outputDir ,
185190 EnvVars : []string {"CDI_OUTPUT_DIR" },
186191 },
187192 & cli.StringFlag {
188193 Name : "cdi-kind" ,
189194 Usage : "the vendor string to use for the generated CDI specification" ,
190195 Value : "management.nvidia.com/gpu" ,
191- Destination : & opts .cdiKind ,
196+ Destination : & opts .CDI . kind ,
192197 EnvVars : []string {"CDI_KIND" },
193198 },
194199 & cli.BoolFlag {
@@ -221,19 +226,19 @@ func ValidateOptions(opts *Options, toolkitRoot string) error {
221226 return fmt .Errorf ("invalid --toolkit-root option: %v" , toolkitRoot )
222227 }
223228
224- vendor , class := parser .ParseQualifier (opts .cdiKind )
229+ vendor , class := parser .ParseQualifier (opts .CDI . kind )
225230 if err := parser .ValidateVendorName (vendor ); err != nil {
226231 return fmt .Errorf ("invalid CDI vendor name: %v" , err )
227232 }
228233 if err := parser .ValidateClassName (class ); err != nil {
229234 return fmt .Errorf ("invalid CDI class name: %v" , err )
230235 }
231- opts .cdiVendor = vendor
232- opts .cdiClass = class
236+ opts .CDI . vendor = vendor
237+ opts .CDI . class = class
233238
234- if opts .cdiEnabled && opts .cdiOutputDir == "" {
239+ if opts .CDI . Enabled && opts .CDI . outputDir == "" {
235240 log .Warning ("Skipping CDI spec generation (no output directory specified)" )
236- opts .cdiEnabled = false
241+ opts .CDI . Enabled = false
237242 }
238243
239244 isDisabled := false
@@ -246,7 +251,7 @@ func ValidateOptions(opts *Options, toolkitRoot string) error {
246251 break
247252 }
248253 }
249- if ! opts .cdiEnabled && ! isDisabled {
254+ if ! opts .CDI . Enabled && ! isDisabled {
250255 log .Info ("disabling device node creation since --cdi-enabled=false" )
251256 isDisabled = true
252257 }
@@ -761,7 +766,7 @@ func createDeviceNodes(opts *Options) error {
761766
762767// generateCDISpec generates a CDI spec for use in management containers
763768func generateCDISpec (opts * Options , nvidiaCDIHookPath string ) error {
764- if ! opts .cdiEnabled {
769+ if ! opts .CDI . Enabled {
765770 return nil
766771 }
767772 log .Info ("Generating CDI spec for management containers" )
@@ -770,8 +775,8 @@ func generateCDISpec(opts *Options, nvidiaCDIHookPath string) error {
770775 nvcdi .WithDriverRoot (opts .DriverRootCtrPath ),
771776 nvcdi .WithDevRoot (opts .DevRootCtrPath ),
772777 nvcdi .WithNVIDIACDIHookPath (nvidiaCDIHookPath ),
773- nvcdi .WithVendor (opts .cdiVendor ),
774- nvcdi .WithClass (opts .cdiClass ),
778+ nvcdi .WithVendor (opts .CDI . vendor ),
779+ nvcdi .WithClass (opts .CDI . class ),
775780 )
776781 if err != nil {
777782 return fmt .Errorf ("failed to create CDI library for management containers: %v" , err )
@@ -796,7 +801,7 @@ func generateCDISpec(opts *Options, nvidiaCDIHookPath string) error {
796801 if err != nil {
797802 return fmt .Errorf ("failed to generate CDI name for management containers: %v" , err )
798803 }
799- err = spec .Save (filepath .Join (opts .cdiOutputDir , name ))
804+ err = spec .Save (filepath .Join (opts .CDI . outputDir , name ))
800805 if err != nil {
801806 return fmt .Errorf ("failed to save CDI spec for management containers: %v" , err )
802807 }
0 commit comments