diff --git a/CHANGELOG.md b/CHANGELOG.md index ed7c5099..095cd76f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## 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. * 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. diff --git a/pkg/nvcdi/spec/builder.go b/pkg/nvcdi/spec/builder.go index bdf68fe2..78df7c17 100644 --- a/pkg/nvcdi/spec/builder.go +++ b/pkg/nvcdi/spec/builder.go @@ -19,6 +19,7 @@ package spec import ( "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/specs-go" ) @@ -31,6 +32,7 @@ type builder struct { deviceSpecs []specs.Device edits specs.ContainerEdits format string + noSimplify bool } // newBuilder creates a new spec builder with the supplied options @@ -76,6 +78,13 @@ func (o *builder) Build() (*spec, error) { 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{ Spec: raw, format: o.format, @@ -128,3 +137,10 @@ func WithFormat(format string) Option { o.format = format } } + +// WithNoSimplify sets whether the spec must be simplified +func WithNoSimplify(noSimplify bool) Option { + return func(o *builder) { + o.noSimplify = noSimplify + } +} diff --git a/pkg/nvcdi/transform/simplify.go b/pkg/nvcdi/transform/simplify.go index 8bdac371..a2162ad6 100644 --- a/pkg/nvcdi/transform/simplify.go +++ b/pkg/nvcdi/transform/simplify.go @@ -28,8 +28,8 @@ var _ Transformer = (*simplify)(nil) // 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. -func NewSimplifier() (Transformer, error) { - return &simplify{}, nil +func NewSimplifier() Transformer { + return &simplify{} } // Transform simplifies the supplied spec.