Add sorter to simplifying transformer

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2023-08-08 14:31:39 +02:00
parent 7a4d2cff67
commit cbdbcd87ff
2 changed files with 17 additions and 13 deletions

View File

@ -163,6 +163,18 @@ func TestMergedDevice(t *testing.T) {
}, },
expectedSpec: &specs.Spec{ expectedSpec: &specs.Spec{
Devices: []specs.Device{ Devices: []specs.Device{
{
Name: "all",
ContainerEdits: specs.ContainerEdits{
Hooks: []*specs.Hook{
{
HookName: "createContainer",
Path: "/usr/bin/nvidia-ctk",
Args: []string{"nvidia-ctk", "hook", "chmod", "--mode", "755", "--path", "/dev/dri"},
},
},
},
},
{ {
Name: "gpu0", Name: "gpu0",
ContainerEdits: specs.ContainerEdits{ ContainerEdits: specs.ContainerEdits{
@ -187,18 +199,6 @@ func TestMergedDevice(t *testing.T) {
}, },
}, },
}, },
{
Name: "all",
ContainerEdits: specs.ContainerEdits{
Hooks: []*specs.Hook{
{
HookName: "createContainer",
Path: "/usr/bin/nvidia-ctk",
Args: []string{"nvidia-ctk", "hook", "chmod", "--mode", "755", "--path", "/dev/dri"},
},
},
},
},
}, },
}, },
}, },

View File

@ -29,7 +29,11 @@ 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 { func NewSimplifier() Transformer {
return &simplify{} return Merge(
dedupe{},
simplify{},
sorter{},
)
} }
// Transform simplifies the supplied spec. // Transform simplifies the supplied spec.