Skip to content

Commit

Permalink
Merge pull request #2926 from rhatdan/crun
Browse files Browse the repository at this point in the history
Pick default OCI Runtime from containers.conf
  • Loading branch information
openshift-merge-robot authored Jan 22, 2021
2 parents 371e4ca + f4424ca commit 1a04337
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 1a04337

Please sign in to comment.