From 11aa1d2a7d5f725f79eb12318e06aadcc6d2ad2a Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Wed, 6 Apr 2022 15:18:12 +0200 Subject: [PATCH] FIX: Factor out specModifier construction into function Signed-off-by: Evan Lezar --- .../runtime_factory.go | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/cmd/nvidia-container-runtime/runtime_factory.go b/cmd/nvidia-container-runtime/runtime_factory.go index 9ae9a572..8eb23302 100644 --- a/cmd/nvidia-container-runtime/runtime_factory.go +++ b/cmd/nvidia-container-runtime/runtime_factory.go @@ -44,14 +44,9 @@ func newNVIDIAContainerRuntime(logger *logrus.Logger, cfg *config.Config, argv [ return nil, fmt.Errorf("error constructing low-level runtime: %v", err) } - var specModifier oci.SpecModifier - if cfg.NVIDIAContainerRuntimeConfig.Experimental { - specModifier, err = modifier.NewExperimentalModifier(logger, cfg) - if err != nil { - return nil, fmt.Errorf("failed to construct experimental modifier: %v", err) - } - } else { - specModifier = modifier.NewStableRuntimeModifier(logger) + specModifier, err := newSpecModifier(logger, cfg) + if err != nil { + return nil, fmt.Errorf("failed to construct OCI spec modifier: %v", err) } // Create the wrapping runtime with the specified modifier @@ -64,3 +59,12 @@ func newNVIDIAContainerRuntime(logger *logrus.Logger, cfg *config.Config, argv [ return r, nil } + +// newSpecModifier is a factory method that creates constructs an OCI spec modifer based on the provided config. +func newSpecModifier(logger *logrus.Logger, cfg *config.Config) (oci.SpecModifier, error) { + if !cfg.NVIDIAContainerRuntimeConfig.Experimental { + return modifier.NewStableRuntimeModifier(logger), nil + } + + return modifier.NewExperimentalModifier(logger, cfg) +}