From 0fc745b4ce6d956663ed65518b37fe88f400cc53 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Thu, 21 Jan 2021 08:29:21 -0500 Subject: [PATCH] Pick default OCI Runtime from containers.conf Currently we have a weird situation where the user sets the default runtime in his containers.conf for podman but Buildah is still falling back to use crun because it was hard coded as the default for Buildah. We are changing the default to "crun" but this should ONLY be used when the containers.conf load fails, which should never happen. I would like to remove this default, but that would theoretically break the API promise of Buildah. This should fix https://github.com/containers/podman/issues/8893 Signed-off-by: Daniel J Walsh --- util/types.go | 5 +++-- util/util.go | 7 ++++++- util/util_test.go | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/util/types.go b/util/types.go index dc5f4b6c8e7..49f4989cae1 100644 --- a/util/types.go +++ b/util/types.go @@ -1,8 +1,9 @@ package util const ( - // DefaultRuntime is the default command to use to run the container. - DefaultRuntime = "runc" + // DefaultRuntime should no longer be used. + // Default runtime should come from containers.conf + DefaultRuntime = "crun" // DefaultCNIPluginPath is the default location of CNI plugin helpers. DefaultCNIPluginPath = "/usr/libexec/cni:/opt/cni/bin" // DefaultCNIConfigDir is the default location of CNI configuration files. diff --git a/util/util.go b/util/util.go index 99f68d9e1ce..e4dcface548 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.Debugf("Error loading container config when searching for local runtime.") + 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..5c8644dd1f4 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", "crun", defaultRuntime) + } + defaultRuntime = "myoci" + os.Setenv("BUILDAH_RUNTIME", defaultRuntime) + runtime = Runtime() + if runtime != defaultRuntime { + t.Fatalf("expected %v, got %v", "crun", defaultRuntime) + } +}