From f27c33b45f41b86bfc04013bada8d37d8255ab18 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Tue, 28 Mar 2023 12:31:09 +0200 Subject: [PATCH] Remove target-driver-root from generate Signed-off-by: Evan Lezar --- cmd/nvidia-ctk/cdi/generate/generate.go | 49 +++++++------------------ 1 file changed, 13 insertions(+), 36 deletions(-) diff --git a/cmd/nvidia-ctk/cdi/generate/generate.go b/cmd/nvidia-ctk/cdi/generate/generate.go index 37bb562e..6ab27b00 100644 --- a/cmd/nvidia-ctk/cdi/generate/generate.go +++ b/cmd/nvidia-ctk/cdi/generate/generate.go @@ -26,7 +26,6 @@ import ( "github.com/NVIDIA/nvidia-container-toolkit/internal/edits" "github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi" "github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/spec" - "github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/transform" "github.com/container-orchestrated-devices/container-device-interface/pkg/cdi" specs "github.com/container-orchestrated-devices/container-device-interface/specs-go" "github.com/sirupsen/logrus" @@ -46,10 +45,8 @@ type config struct { format string deviceNameStrategy string driverRoot string - targetDriverRoot string nvidiaCTKPath string mode string - kind string vendor string class string } @@ -114,17 +111,18 @@ func (m command) build() *cli.Command { Destination: &cfg.nvidiaCTKPath, }, &cli.StringFlag{ - Name: "target-driver-root", - Usage: "Specify the NVIDIA GPU driver root to use in the generated CDI specification. Only used if not empty and differs from 'driver-root' used during discovery.", - Value: "", - Destination: &cfg.targetDriverRoot, + Name: "vendor", + Aliases: []string{"cdi-vendor"}, + Usage: "the vendor string to use for the generated CDI specification.", + Value: "nvidia.com", + Destination: &cfg.vendor, }, &cli.StringFlag{ - Name: "kind", - Aliases: []string{"cdi-kind"}, - Usage: "the vendor string to use for the generated CDI specification.", - Value: "nvidia.com/gpu", - Destination: &cfg.kind, + Name: "class", + Aliases: []string{"cdi-class"}, + Usage: "the class string to use for the generated CDI specification.", + Value: "gpu", + Destination: &cfg.class, }, } @@ -158,10 +156,6 @@ func (m command) validateFlags(c *cli.Context, cfg *config) error { cfg.nvidiaCTKPath = discover.FindNvidiaCTK(m.logger, cfg.nvidiaCTKPath) - if cfg.targetDriverRoot == "" { - cfg.targetDriverRoot = cfg.driverRoot - } - if outputFileFormat := formatFromFilename(cfg.output); outputFileFormat != "" { m.logger.Debugf("Inferred output format as %q from output file name", outputFileFormat) if !c.IsSet("format") { @@ -171,16 +165,12 @@ func (m command) validateFlags(c *cli.Context, cfg *config) error { } } - vendor, class := cdi.ParseQualifier(cfg.kind) - if err := cdi.ValidateVendorName(vendor); err != nil { + if err := cdi.ValidateVendorName(cfg.vendor); err != nil { return fmt.Errorf("invalid CDI vendor name: %v", err) } - if err := cdi.ValidateClassName(class); err != nil { + if err := cdi.ValidateClassName(cfg.class); err != nil { return fmt.Errorf("invalid CDI class name: %v", err) } - cfg.vendor = vendor - cfg.class = class - return nil } @@ -255,26 +245,13 @@ func (m command) generateSpec(cfg *config) (spec.Interface, error) { return nil, fmt.Errorf("failed to create edits common for entities: %v", err) } - spec, err := spec.New( + return spec.New( spec.WithVendor(cfg.vendor), spec.WithClass(cfg.class), spec.WithDeviceSpecs(deviceSpecs), spec.WithEdits(*commonEdits.ContainerEdits), spec.WithFormat(cfg.format), ) - if err != nil { - return nil, err - } - - err = transform.NewRootTransformer( - cfg.driverRoot, - cfg.targetDriverRoot, - ).Transform(spec.Raw()) - if err != nil { - return nil, fmt.Errorf("failed to transform driver root in CDI spec: %v", err) - } - - return spec, err } // MergeDeviceSpecs creates a device with the specified name which combines the edits from the previous devices.