Generate a simplified CDI spec by default

As simplified CDI spec has no duplicate entities in any single set of container edits.
Furthermore, contianer edits defined at a spec-level are not included in the container
edits for a device.

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2023-03-15 12:46:34 +02:00
parent 5ff206e1a9
commit 33f6fe0217
3 changed files with 19 additions and 2 deletions

View File

@ -2,6 +2,7 @@
## v1.13.0-rc.3 ## v1.13.0-rc.3
* Generate a simplified CDI specification by default. This means that entities in the common edits in a spec are not included in device definitions.
* Add transformers to deduplicate and simplify CDI specifications. * Add transformers to deduplicate and simplify CDI specifications.
* Fix the generation of CDI specifications for management containers when the driver libraries are not in the LDCache. * Fix the generation of CDI specifications for management containers when the driver libraries are not in the LDCache.
* Prefer /run over /var/run when locating nvidia-persistenced and nvidia-fabricmanager sockets. * Prefer /run over /var/run when locating nvidia-persistenced and nvidia-fabricmanager sockets.

View File

@ -19,6 +19,7 @@ package spec
import ( import (
"fmt" "fmt"
"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/cdi"
"github.com/container-orchestrated-devices/container-device-interface/specs-go" "github.com/container-orchestrated-devices/container-device-interface/specs-go"
) )
@ -31,6 +32,7 @@ type builder struct {
deviceSpecs []specs.Device deviceSpecs []specs.Device
edits specs.ContainerEdits edits specs.ContainerEdits
format string format string
noSimplify bool
} }
// newBuilder creates a new spec builder with the supplied options // newBuilder creates a new spec builder with the supplied options
@ -76,6 +78,13 @@ func (o *builder) Build() (*spec, error) {
raw.Version = minVersion raw.Version = minVersion
} }
if !o.noSimplify {
err := transform.NewSimplifier().Transform(raw)
if err != nil {
return nil, fmt.Errorf("failed to simplify spec: %v", err)
}
}
s := spec{ s := spec{
Spec: raw, Spec: raw,
format: o.format, format: o.format,
@ -128,3 +137,10 @@ func WithFormat(format string) Option {
o.format = format o.format = format
} }
} }
// WithNoSimplify sets whether the spec must be simplified
func WithNoSimplify(noSimplify bool) Option {
return func(o *builder) {
o.noSimplify = noSimplify
}
}

View File

@ -28,8 +28,8 @@ var _ Transformer = (*simplify)(nil)
// NewSimplifier creates a simplifier transformer. // NewSimplifier creates a simplifier transformer.
// This transoformer ensures that entities in the spec are deduplicated and that common edits are removed from device-specific edits. // This transoformer ensures that entities in the spec are deduplicated and that common edits are removed from device-specific edits.
func NewSimplifier() (Transformer, error) { func NewSimplifier() Transformer {
return &simplify{}, nil return &simplify{}
} }
// Transform simplifies the supplied spec. // Transform simplifies the supplied spec.