Skip to content

Commit 9d2be93

Browse files
committed
Add default runtime parameters in config
Added a way to define default runtime parameters in config. Fixes: https://github.com/containers/common/issues/715 Default runtime parameters should be defined as shown below: [engine.runtimes_flags] runsc = [ "net-raw", ] crun = [ "debug", ] Signed-off-by: Rosvaldas Atstupėnas <[email protected]>
1 parent 3548ae1 commit 9d2be93

File tree

8 files changed

+45
-4
lines changed

8 files changed

+45
-4
lines changed

cmd/podman/common/build.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
enchelpers "github.com/containers/ocicrypt/helpers"
2525
"github.com/containers/podman/v5/cmd/podman/registry"
2626
"github.com/containers/podman/v5/cmd/podman/utils"
27+
"github.com/containers/podman/v5/libpod"
2728
"github.com/containers/podman/v5/pkg/domain/entities"
2829
"github.com/containers/podman/v5/pkg/env"
2930
"github.com/openshift/imagebuilder"
@@ -453,6 +454,12 @@ func buildFlagsWrapperToOptions(c *cobra.Command, contextDir string, flags *Buil
453454
runtimeFlags = append(runtimeFlags, "--systemd-cgroup")
454455
}
455456

457+
configIndex := libpod.RuntimeNameToConfigIndex(podmanConfig.RuntimePath)
458+
459+
for _, arg := range podmanConfig.ContainersConfDefaultsRO.Engine.OCIRuntimesFlags[configIndex] {
460+
runtimeFlags = append(runtimeFlags, "--"+arg)
461+
}
462+
456463
platforms, err := parse.PlatformsFromOptions(c)
457464
if err != nil {
458465
return nil, err

docs/source/markdown/options/runtime-flag.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66

77
Adds global flags for the container runtime. To list the supported flags, please consult the manpages of the selected container runtime.
88

9+
Default runtime flags can be added in containers.conf.
10+
911
Note: Do not pass the leading -- to the flag. To pass the runc flag --log-format json to buildah build, the option given is --runtime-flag log-format=json.

docs/source/markdown/podman.1.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ consult the manpages of the selected container runtime (`runc` is the default
147147
runtime, the manpage to consult is `runc(8)`. When the machine is configured
148148
for cgroup V2, the default runtime is `crun`, the manpage to consult is `crun(8)`.).
149149

150+
Default runtime flags can be added in containers.conf.
151+
150152
Note: Do not pass the leading `--` to the flag. To pass the runc flag `--log-format json`
151153
to podman build, the option given can be `--runtime-flag log-format=json`.
152154

libpod/oci_conmon_common.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ func newConmonOCIRuntime(name string, paths []string, conmonPath string, runtime
9393
supportsKVM[r] = true
9494
}
9595

96+
configIndex := RuntimeNameToConfigIndex(name)
97+
98+
for _, arg := range runtimeCfg.Engine.OCIRuntimesFlags[configIndex] {
99+
runtimeFlags = append(runtimeFlags, "--"+arg)
100+
}
101+
96102
runtime := new(ConmonOCIRuntime)
97103
runtime.name = name
98104
runtime.conmonPath = conmonPath
@@ -108,10 +114,9 @@ func newConmonOCIRuntime(name string, paths []string, conmonPath string, runtime
108114
// TODO: probe OCI runtime for feature and enable automatically if
109115
// available.
110116

111-
base := filepath.Base(name)
112-
runtime.supportsJSON = supportsJSON[base]
113-
runtime.supportsNoCgroups = supportsNoCgroups[base]
114-
runtime.supportsKVM = supportsKVM[base]
117+
runtime.supportsJSON = supportsJSON[configIndex]
118+
runtime.supportsNoCgroups = supportsNoCgroups[configIndex]
119+
runtime.supportsKVM = supportsKVM[configIndex]
115120

116121
foundPath := false
117122
for _, path := range paths {

libpod/util.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,7 @@ func isDirectory(path string) bool {
293293
}
294294
return info.IsDir()
295295
}
296+
297+
func RuntimeNameToConfigIndex(runtimeName string) string {
298+
return filepath.Base(runtimeName)
299+
}

vendor/github.com/containers/common/pkg/config/config.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/containers/common/pkg/config/containers.conf

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/containers/common/pkg/config/default.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)