Skip to content

Commit

Permalink
Find ociruntime instead of hard coding default
Browse files Browse the repository at this point in the history
Users could have any one of the OCI runtimes installed,
code will search for default.  This way they do not need
to modify defaults if they have "crun" installed.

Search order will be crun, runc, kata

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed Dec 15, 2020
1 parent 66511e8 commit e50a26f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 23 deletions.
5 changes: 3 additions & 2 deletions docs/containers.conf.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,11 @@ Pull image before running or creating a container. The default is **missing**.
Indicates whether the application should be running in remote mode. This flag modifies the
--remote option on container engines. Setting the flag to true will default `podman --remote=true` for access to the remote Podman service.

**runtime**="crun"
**runtime**=""

Default OCI specific runtime in runtimes that will be used by default. Must
refer to a member of the runtimes table.
refer to a member of the runtimes table. Default runtime will be searched for
on the system using the priority: "crun", "runc", "kata".

**runtime_supports_json**=["crun", "runc", "kata"]

Expand Down
16 changes: 16 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,22 @@ func (c *Config) Validate() error {
return nil
}

func (c *EngineConfig) findRuntime() string {
// Search for crun first followed by runc and kata
for _, name := range []string{"crun", "runc", "kata"} {
for _, v := range c.OCIRuntimes[name] {
if _, err := os.Stat(v); err == nil {
return name
}
}
if path, err := exec.LookPath(name); err == nil {
logrus.Warningf("Found default OCIruntime %s path which is missing from [engine.runtimes] in containers.conf", path)
return name
}
}
return ""
}

// Validate is the main entry point for Engine configuration validation
// It returns an `error` on validation failure, otherwise
// `nil`.
Expand Down
22 changes: 11 additions & 11 deletions pkg/config/containers.conf
Original file line number Diff line number Diff line change
Expand Up @@ -425,18 +425,8 @@ default_sysctls = [
# Path to file containing ssh identity key
# identity = "~/.ssh/id_rsa"

# Paths to look for a valid OCI runtime (runc, runv, kata, etc)
# Paths to look for a valid OCI runtime (crun, runc, kata, etc)
[engine.runtimes]
# runc = [
# "/usr/bin/runc",
# "/usr/sbin/runc",
# "/usr/local/bin/runc",
# "/usr/local/sbin/runc",
# "/sbin/runc",
# "/bin/runc",
# "/usr/lib/cri-o-runc/sbin/runc",
# ]

# crun = [
# "/usr/bin/crun",
# "/usr/sbin/crun",
Expand All @@ -447,6 +437,16 @@ default_sysctls = [
# "/run/current-system/sw/bin/crun",
# ]

# runc = [
# "/usr/bin/runc",
# "/usr/sbin/runc",
# "/usr/local/bin/runc",
# "/usr/local/sbin/runc",
# "/sbin/runc",
# "/bin/runc",
# "/usr/lib/cri-o-runc/sbin/runc",
# ]

# kata = [
# "/usr/bin/kata-runtime",
# "/usr/sbin/kata-runtime",
Expand Down
22 changes: 12 additions & 10 deletions pkg/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,22 @@ func defaultConfigFromMemory() (*EngineConfig, error) {
c.ImageDefaultTransport = _defaultTransport
c.StateType = BoltDBStateStore

c.OCIRuntime = "crun"
c.ImageBuildFormat = "oci"

c.CgroupManager = defaultCgroupManager()
c.StopTimeout = uint(10)

c.Remote = isRemote()
c.OCIRuntimes = map[string][]string{
"crun": {
"/usr/bin/crun",
"/usr/sbin/crun",
"/usr/local/bin/crun",
"/usr/local/sbin/crun",
"/sbin/crun",
"/bin/crun",
"/run/current-system/sw/bin/crun",
},
"runc": {
"/usr/bin/runc",
"/usr/sbin/runc",
Expand All @@ -260,15 +268,6 @@ func defaultConfigFromMemory() (*EngineConfig, error) {
"/usr/lib/cri-o-runc/sbin/runc",
"/run/current-system/sw/bin/runc",
},
"crun": {
"/usr/bin/crun",
"/usr/sbin/crun",
"/usr/local/bin/crun",
"/usr/local/sbin/crun",
"/sbin/crun",
"/bin/crun",
"/run/current-system/sw/bin/crun",
},
"kata": {
"/usr/bin/kata-runtime",
"/usr/sbin/kata-runtime",
Expand All @@ -280,6 +279,9 @@ func defaultConfigFromMemory() (*EngineConfig, error) {
"/usr/bin/kata-fc",
},
}
// Needs to be called after populating c.OCIRuntimes
c.OCIRuntime = c.findRuntime()

c.ConmonEnvVars = []string{
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
}
Expand Down

0 comments on commit e50a26f

Please sign in to comment.