From f2c9937ca8775df2cdbe8a8c2fce5db585e0db25 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Fri, 25 Aug 2023 16:15:30 +0200 Subject: [PATCH] Use cdi parser package Signed-off-by: Evan Lezar --- cmd/nvidia-ctk/cdi/generate/generate.go | 2 +- pkg/nvcdi/spec/builder.go | 3 ++- pkg/nvcdi/transform/merged-device.go | 4 +++- tools/container/toolkit/toolkit.go | 7 ++++--- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cmd/nvidia-ctk/cdi/generate/generate.go b/cmd/nvidia-ctk/cdi/generate/generate.go index 6adb0936..47b6c711 100644 --- a/cmd/nvidia-ctk/cdi/generate/generate.go +++ b/cmd/nvidia-ctk/cdi/generate/generate.go @@ -28,7 +28,7 @@ import ( "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" + cdi "github.com/container-orchestrated-devices/container-device-interface/pkg/parser" "github.com/urfave/cli/v2" ) diff --git a/pkg/nvcdi/spec/builder.go b/pkg/nvcdi/spec/builder.go index bfefff93..610cb8ce 100644 --- a/pkg/nvcdi/spec/builder.go +++ b/pkg/nvcdi/spec/builder.go @@ -22,6 +22,7 @@ import ( "github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/transform" "github.com/container-orchestrated-devices/container-device-interface/pkg/cdi" + "github.com/container-orchestrated-devices/container-device-interface/pkg/parser" "github.com/container-orchestrated-devices/container-device-interface/specs-go" ) @@ -47,7 +48,7 @@ func newBuilder(opts ...Option) *builder { } if s.raw != nil { s.noSimplify = true - vendor, class := cdi.ParseQualifier(s.raw.Kind) + vendor, class := parser.ParseQualifier(s.raw.Kind) s.vendor = vendor s.class = class } diff --git a/pkg/nvcdi/transform/merged-device.go b/pkg/nvcdi/transform/merged-device.go index 4b744155..6730afeb 100644 --- a/pkg/nvcdi/transform/merged-device.go +++ b/pkg/nvcdi/transform/merged-device.go @@ -20,7 +20,9 @@ import ( "fmt" "github.com/NVIDIA/nvidia-container-toolkit/internal/edits" + "github.com/container-orchestrated-devices/container-device-interface/pkg/cdi" + "github.com/container-orchestrated-devices/container-device-interface/pkg/parser" "github.com/container-orchestrated-devices/container-device-interface/specs-go" ) @@ -64,7 +66,7 @@ func NewMergedDevice(opts ...MergedDeviceOption) (Transformer, error) { } m.simplifier = NewSimplifier() - if err := cdi.ValidateDeviceName(m.name); err != nil { + if err := parser.ValidateDeviceName(m.name); err != nil { return nil, fmt.Errorf("invalid device name %q: %v", m.name, err) } diff --git a/tools/container/toolkit/toolkit.go b/tools/container/toolkit/toolkit.go index b05062f3..971916ae 100644 --- a/tools/container/toolkit/toolkit.go +++ b/tools/container/toolkit/toolkit.go @@ -27,6 +27,7 @@ import ( "github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi" "github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/transform" "github.com/container-orchestrated-devices/container-device-interface/pkg/cdi" + "github.com/container-orchestrated-devices/container-device-interface/pkg/parser" toml "github.com/pelletier/go-toml" log "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" @@ -238,11 +239,11 @@ func validateOptions(c *cli.Context, opts *options) error { return fmt.Errorf("invalid --toolkit-root option: %v", opts.toolkitRoot) } - vendor, class := cdi.ParseQualifier(opts.cdiKind) - if err := cdi.ValidateVendorName(vendor); err != nil { + vendor, class := parser.ParseQualifier(opts.cdiKind) + if err := parser.ValidateVendorName(vendor); err != nil { return fmt.Errorf("invalid CDI vendor name: %v", err) } - if err := cdi.ValidateClassName(class); err != nil { + if err := parser.ValidateClassName(class); err != nil { return fmt.Errorf("invalid CDI class name: %v", err) } opts.cdiVendor = vendor