diff --git a/util/types.go b/util/types.go index dc5f4b6c8e7..ca0f315327d 100644 --- a/util/types.go +++ b/util/types.go @@ -1,7 +1,7 @@ package util const ( - // DefaultRuntime is the default command to use to run the container. + // Deprecated: Default runtime should come from containers.conf DefaultRuntime = "runc" // DefaultCNIPluginPath is the default location of CNI plugin helpers. DefaultCNIPluginPath = "/usr/libexec/cni:/opt/cni/bin" diff --git a/util/util.go b/util/util.go index 99f68d9e1ce..9e0cea1a363 100644 --- a/util/util.go +++ b/util/util.go @@ -263,7 +263,12 @@ func Runtime() string { return "crun" } - return DefaultRuntime + conf, err := config.Default() + if err != nil { + logrus.Warnf("Error loading container config when searching for local runtime: %v", err) + return DefaultRuntime + } + return conf.Engine.OCIRuntime } // StringInSlice returns a boolean indicating if the exact value s is present diff --git a/util/util_test.go b/util/util_test.go index 5454b86dda8..abeb6f96431 100644 --- a/util/util_test.go +++ b/util/util_test.go @@ -2,7 +2,10 @@ package util import ( "fmt" + "os" "testing" + + "github.com/containers/common/pkg/config" ) func TestMergeEnv(t *testing.T) { @@ -37,3 +40,18 @@ func TestMergeEnv(t *testing.T) { }) } } +func TestRuntime(t *testing.T) { + os.Setenv("CONTAINERS_CONF", "/dev/null") + conf, _ := config.Default() + defaultRuntime := conf.Engine.OCIRuntime + runtime := Runtime() + if runtime != defaultRuntime { + t.Fatalf("expected %v, got %v", runtime, defaultRuntime) + } + defaultRuntime = "myoci" + os.Setenv("BUILDAH_RUNTIME", defaultRuntime) + runtime = Runtime() + if runtime != defaultRuntime { + t.Fatalf("expected %v, got %v", runtime, defaultRuntime) + } +}