Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pick default OCI Runtime from containers.conf #2929

Merged
merged 1 commit into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}