FIX: Factor out specModifier construction into function

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2022-04-06 15:18:12 +02:00
parent e6730fd0f0
commit 11aa1d2a7d

View File

@ -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)
specModifier, err := newSpecModifier(logger, cfg)
if err != nil {
return nil, fmt.Errorf("failed to construct experimental modifier: %v", err)
}
} else {
specModifier = modifier.NewStableRuntimeModifier(logger)
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)
}