Skip to content

Commit fce26c0

Browse files
authored
Merge pull request #281 from CowRules/default-runtime-flags
Add config to set default runtime flags
2 parents b181f45 + a7b2383 commit fce26c0

File tree

9 files changed

+113
-0
lines changed

9 files changed

+113
-0
lines changed

common/docs/containers.conf.5.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,12 @@ URI to access the Podman service
934934

935935
Path to file containing ssh identity key
936936

937+
**[engine.runtimes_flags]**
938+
939+
Lists of default runtime flags for each valid OCI runtime (crun, runc, kata, runsc, krun, etc).
940+
941+
To list the supported flags, please consult the documentation of the selected container runtime.
942+
937943
**[engine.volume_plugins]**
938944

939945
A table of all the enabled volume plugins on the system. Volume plugins can be

common/pkg/config/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,9 @@ type EngineConfig struct {
423423
// OCIRuntimes are the set of configured OCI runtimes (default is runc).
424424
OCIRuntimes map[string][]string `toml:"runtimes,omitempty"`
425425

426+
// OCIRuntimesFlags are the set of configured OCI runtimes' flags
427+
OCIRuntimesFlags map[string][]string `toml:"runtimes_flags,omitempty"`
428+
426429
// PlatformToOCIRuntime requests specific OCI runtime for a specified platform of image.
427430
PlatformToOCIRuntime map[string]string `toml:"platform_to_oci_runtime,omitempty"`
428431

@@ -858,6 +861,11 @@ func (c *EngineConfig) Validate() error {
858861
return err
859862
}
860863

864+
// Check if runtimes specified under [engine.runtimes_flags] can be found under [engine.runtimes]
865+
if err := c.validateRuntimeNames(); err != nil {
866+
return err
867+
}
868+
861869
return nil
862870
}
863871

common/pkg/config/config_local.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ func (c *EngineConfig) validatePaths() error {
3030
return nil
3131
}
3232

33+
func (c *EngineConfig) validateRuntimeNames() error {
34+
// Check if runtimes specified under [engine.runtimes_flags] can be found under [engine.runtimes]
35+
for runtime := range c.OCIRuntimesFlags {
36+
if _, exists := c.OCIRuntimes[runtime]; !exists {
37+
return fmt.Errorf("invalid runtime %q in [engine.runtimes_flags]: "+
38+
"not defined in [engine.runtimes]", runtime)
39+
}
40+
}
41+
return nil
42+
}
43+
3344
func (c *ContainersConfig) validateDevices() error {
3445
for _, d := range c.Devices.Get() {
3546
if parser.IsQualifiedName(d) {

common/pkg/config/config_local_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,4 +624,42 @@ var _ = Describe("Config Local", func() {
624624
gomega.Expect(err).ToNot(gomega.HaveOccurred())
625625
gomega.Expect(config2.Containers.LogPath).To(gomega.Equal("/var/log/containers"))
626626
})
627+
It("should parse OCIRuntimesFlags from config file", func() {
628+
// Given
629+
config, err := newLocked(&Options{}, &paths{})
630+
// Then
631+
gomega.Expect(err).ToNot(gomega.HaveOccurred())
632+
gomega.Expect(config.Engine.OCIRuntimesFlags).To(gomega.Equal(map[string][]string{}))
633+
634+
// Given non-empty OCIRuntimesFlags
635+
config2, err := newLocked(&Options{}, &paths{etc: "testdata/containers_default.conf"})
636+
// Then
637+
gomega.Expect(err).ToNot(gomega.HaveOccurred())
638+
gomega.Expect(config2.Engine.OCIRuntimesFlags).To(gomega.Equal(map[string][]string{
639+
"crun": {
640+
"debug",
641+
},
642+
"runsc": {
643+
"net-raw",
644+
},
645+
}))
646+
// When
647+
err = config2.Engine.Validate()
648+
// Then
649+
gomega.Expect(err).ToNot(gomega.HaveOccurred())
650+
651+
// Given OCIRuntimesFlags with invalid runtime names
652+
config2.Engine.OCIRuntimesFlags = map[string][]string{
653+
"curn": {
654+
"debug",
655+
},
656+
"does not exist": {
657+
"net-raw",
658+
},
659+
}
660+
// When
661+
err = config2.Engine.Validate()
662+
// Then
663+
gomega.Expect(err).To(gomega.HaveOccurred())
664+
})
627665
})

common/pkg/config/config_remote.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ func (c *EngineConfig) validatePaths() error {
1616
return nil
1717
}
1818

19+
func (c *EngineConfig) validateRuntimeNames() error {
20+
return nil
21+
}
22+
1923
func (c *ContainersConfig) validateDevices() error {
2024
return nil
2125
}

common/pkg/config/containers.conf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,23 @@ default_sysctls = [
863863
# "/usr/local/bin/krun",
864864
#]
865865

866+
# Default flags for a valid OCI runtime (crun, runc, kata, runsc, krun, etc)
867+
# Note: Do not pass the leading -- to the flag. To pass the runc flag --log-format json, the option given is log-format=json.
868+
[engine.runtimes_flags]
869+
#crun = []
870+
871+
#crun-vm = []
872+
873+
#kata = []
874+
875+
#runc = []
876+
877+
#runsc = []
878+
879+
#youki = []
880+
881+
#krun = []
882+
866883
[engine.volume_plugins]
867884
#testplugin = "/run/podman/plugins/test.sock"
868885

common/pkg/config/containers.conf-freebsd

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,23 @@ default_sysctls = [
669669
# "/usr/local/bin/krun",
670670
#]
671671

672+
# Default flags for a valid OCI runtime (crun, runc, kata, runsc, krun, etc)
673+
# Note: Do not pass the leading -- to the flag. To pass the runc flag --log-format json, the option given is log-format=json.
674+
[engine.runtimes_flags]
675+
#crun = []
676+
677+
#crun-vm = []
678+
679+
#kata = []
680+
681+
#runc = []
682+
683+
#runsc = []
684+
685+
#youki = []
686+
687+
#krun = []
688+
672689
[engine.volume_plugins]
673690
#testplugin = "/var/run/podman/plugins/test.sock"
674691

common/pkg/config/default.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ func defaultEngineConfig() (*EngineConfig, error) {
470470
"/usr/local/bin/ocijail",
471471
},
472472
}
473+
c.OCIRuntimesFlags = map[string][]string{}
473474
c.PlatformToOCIRuntime = map[string]string{
474475
"wasi/wasm": "crun-wasm",
475476
"wasi/wasm32": "crun-wasm",

common/pkg/config/testdata/containers_default.conf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,17 @@ crun = [
311311
"/usr/local/bin/crun",
312312
]
313313

314+
# Default flags for a valid OCI runtime (crun, runc, kata, runsc, krun, etc)
315+
# Note: Do not pass the leading -- to the flag. To pass the runc flag --log-format json, the option given is log-format=json.
316+
[engine.runtimes_flags]
317+
crun = [
318+
"debug"
319+
]
320+
321+
runsc = [
322+
"net-raw"
323+
]
324+
314325
[podmansh]
315326
# Shell to start in container. Default: /bin/sh.
316327
shell = "/bin/zsh"

0 commit comments

Comments
 (0)