From eaf9bdaeb489c0606a3f517e4d35267cfb52a1fa Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Thu, 19 Jan 2023 11:48:36 +0100 Subject: [PATCH] Determine the minumum required spec version This change uses functionality from the CDI package to determine the minimum required CDI spec version. This allows for a spec with the widest compatibility to be specified. Signed-off-by: Evan Lezar --- cmd/nvidia-ctk/cdi/generate/generate.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cmd/nvidia-ctk/cdi/generate/generate.go b/cmd/nvidia-ctk/cdi/generate/generate.go index f53ca4b8..c5986f46 100644 --- a/cmd/nvidia-ctk/cdi/generate/generate.go +++ b/cmd/nvidia-ctk/cdi/generate/generate.go @@ -249,15 +249,20 @@ func (m command) generateSpec(root string, nvidiaCTKPath string) (*specs.Spec, e allEdits.Append(commonEdits) - // Construct the spec - // TODO: Use the code to determine the minimal version + // We construct the spec and determine the minimum required version based on the specification. spec := specs.Spec{ - Version: "0.4.0", + Version: "NOT_SET", Kind: "nvidia.com/gpu", Devices: deviceSpecs, ContainerEdits: *allEdits.ContainerEdits, } + minVersion, err := cdi.MinimumRequiredVersion(&spec) + if err != nil { + return nil, fmt.Errorf("failed to get minumum required CDI spec version: %v", err) + } + spec.Version = minVersion + return &spec, nil }