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 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 containers/podman#8893

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed Jan 21, 2021
1 parent d460e2e commit db28447
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
5 changes: 3 additions & 2 deletions util/types.go
Original file line number Diff line number Diff line change
@@ -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.
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.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
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", "crun", defaultRuntime)
}
defaultRuntime = "myoci"
os.Setenv("BUILDAH_RUNTIME", defaultRuntime)
runtime = Runtime()
if runtime != defaultRuntime {
t.Fatalf("expected %v, got %v", "crun", defaultRuntime)
}
}

0 comments on commit db28447

Please sign in to comment.