From f71c419cfb54f3002cf09b5f1ac59d2ee1cc296c Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Tue, 7 Feb 2023 21:24:44 +0100 Subject: [PATCH] Move modifying OCI runtime wrapper to oci package Signed-off-by: Evan Lezar --- cmd/nvidia-container-runtime/runtime_factory.go | 3 +-- internal/{runtime => oci}/runtime_modifier.go | 15 +++++++-------- .../{runtime => oci}/runtime_modifier_test.go | 15 +++++++-------- 3 files changed, 15 insertions(+), 18 deletions(-) rename internal/{runtime => oci}/runtime_modifier.go (86%) rename internal/{runtime => oci}/runtime_modifier_test.go (92%) diff --git a/cmd/nvidia-container-runtime/runtime_factory.go b/cmd/nvidia-container-runtime/runtime_factory.go index 1754e525..21c96cd8 100644 --- a/cmd/nvidia-container-runtime/runtime_factory.go +++ b/cmd/nvidia-container-runtime/runtime_factory.go @@ -23,7 +23,6 @@ import ( "github.com/NVIDIA/nvidia-container-toolkit/internal/info" "github.com/NVIDIA/nvidia-container-toolkit/internal/modifier" "github.com/NVIDIA/nvidia-container-toolkit/internal/oci" - "github.com/NVIDIA/nvidia-container-toolkit/internal/runtime" "github.com/sirupsen/logrus" ) @@ -50,7 +49,7 @@ func newNVIDIAContainerRuntime(logger *logrus.Logger, cfg *config.Config, argv [ } // Create the wrapping runtime with the specified modifier - r := runtime.NewModifyingRuntimeWrapper( + r := oci.NewModifyingRuntimeWrapper( logger, lowLevelRuntime, ociSpec, diff --git a/internal/runtime/runtime_modifier.go b/internal/oci/runtime_modifier.go similarity index 86% rename from internal/runtime/runtime_modifier.go rename to internal/oci/runtime_modifier.go index d11fda82..2a61445d 100644 --- a/internal/runtime/runtime_modifier.go +++ b/internal/oci/runtime_modifier.go @@ -14,27 +14,26 @@ # limitations under the License. */ -package runtime +package oci import ( "fmt" - "github.com/NVIDIA/nvidia-container-toolkit/internal/oci" log "github.com/sirupsen/logrus" ) type modifyingRuntimeWrapper struct { logger *log.Logger - runtime oci.Runtime - ociSpec oci.Spec - modifier oci.SpecModifier + runtime Runtime + ociSpec Spec + modifier SpecModifier } -var _ oci.Runtime = (*modifyingRuntimeWrapper)(nil) +var _ Runtime = (*modifyingRuntimeWrapper)(nil) // NewModifyingRuntimeWrapper creates a runtime wrapper that applies the specified modifier to the OCI specification // before invoking the wrapped runtime. If the modifier is nil, the input runtime is returned. -func NewModifyingRuntimeWrapper(logger *log.Logger, runtime oci.Runtime, spec oci.Spec, modifier oci.SpecModifier) oci.Runtime { +func NewModifyingRuntimeWrapper(logger *log.Logger, runtime Runtime, spec Spec, modifier SpecModifier) Runtime { if modifier == nil { logger.Infof("Using low-level runtime with no modification") return runtime @@ -52,7 +51,7 @@ func NewModifyingRuntimeWrapper(logger *log.Logger, runtime oci.Runtime, spec oc // Exec checks whether a modification of the OCI specification is required and modifies it accordingly before exec-ing // into the wrapped runtime. func (r *modifyingRuntimeWrapper) Exec(args []string) error { - if oci.HasCreateSubcommand(args) { + if HasCreateSubcommand(args) { err := r.modify() if err != nil { return fmt.Errorf("could not apply required modification to OCI specification: %v", err) diff --git a/internal/runtime/runtime_modifier_test.go b/internal/oci/runtime_modifier_test.go similarity index 92% rename from internal/runtime/runtime_modifier_test.go rename to internal/oci/runtime_modifier_test.go index bd07bf24..47aebc8d 100644 --- a/internal/runtime/runtime_modifier_test.go +++ b/internal/oci/runtime_modifier_test.go @@ -14,13 +14,12 @@ # limitations under the License. */ -package runtime +package oci import ( "fmt" "testing" - "github.com/NVIDIA/nvidia-container-toolkit/internal/oci" "github.com/opencontainers/runtime-spec/specs-go" testlog "github.com/sirupsen/logrus/hooks/test" "github.com/stretchr/testify/require" @@ -38,7 +37,7 @@ func TestExec(t *testing.T) { args []string modifyError error writeError error - modifer oci.SpecModifier + modifer SpecModifier }{ { description: "no args forwards", @@ -92,9 +91,9 @@ func TestExec(t *testing.T) { hook.Reset() t.Run(tc.description, func(t *testing.T) { - runtimeMock := &oci.RuntimeMock{} - specMock := &oci.SpecMock{ - ModifyFunc: func(specModifier oci.SpecModifier) error { + runtimeMock := &RuntimeMock{} + specMock := &SpecMock{ + ModifyFunc: func(specModifier SpecModifier) error { return tc.modifyError }, FlushFunc: func() error { @@ -144,8 +143,8 @@ func TestExec(t *testing.T) { func TestNilModiferReturnsRuntime(t *testing.T) { logger, _ := testlog.NewNullLogger() - runtimeMock := &oci.RuntimeMock{} - specMock := &oci.SpecMock{} + runtimeMock := &RuntimeMock{} + specMock := &SpecMock{} shim := NewModifyingRuntimeWrapper( logger,