From f6ff5622dc3c8383f1cc2b94a86d7cecee585203 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 runc because it was hard coded as the default for Buildah. 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 | 2 +- util/util.go | 7 ++++++- util/util_test.go | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) 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) + } +}