Skip to content

Commit

Permalink
Pick default OCI Runtime from containers.conf
Browse files Browse the repository at this point in the history
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 containers/podman#8893

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed Jan 22, 2021
1 parent 371e4ca commit f4424ca
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion util/types.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
7 changes: 6 additions & 1 deletion util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package util

import (
"fmt"
"os"
"testing"

"github.com/containers/common/pkg/config"
)

func TestMergeEnv(t *testing.T) {
Expand Down Expand Up @@ -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)
}
}

0 comments on commit f4424ca

Please sign in to comment.