From cbdbcd87ffef9971053ad59e76578a9565e33e0a Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Tue, 8 Aug 2023 14:31:39 +0200 Subject: [PATCH] Add sorter to simplifying transformer Signed-off-by: Evan Lezar --- pkg/nvcdi/transform/merged-device_test.go | 24 +++++++++++------------ pkg/nvcdi/transform/simplify.go | 6 +++++- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/pkg/nvcdi/transform/merged-device_test.go b/pkg/nvcdi/transform/merged-device_test.go index d8ef7244..10328530 100644 --- a/pkg/nvcdi/transform/merged-device_test.go +++ b/pkg/nvcdi/transform/merged-device_test.go @@ -163,6 +163,18 @@ func TestMergedDevice(t *testing.T) { }, expectedSpec: &specs.Spec{ 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", 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"}, - }, - }, - }, - }, }, }, }, diff --git a/pkg/nvcdi/transform/simplify.go b/pkg/nvcdi/transform/simplify.go index a2162ad6..ddc6f597 100644 --- a/pkg/nvcdi/transform/simplify.go +++ b/pkg/nvcdi/transform/simplify.go @@ -29,7 +29,11 @@ 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 { - return &simplify{} + return Merge( + dedupe{}, + simplify{}, + sorter{}, + ) } // Transform simplifies the supplied spec.