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

Allow mounts to be specified in containers.conf #1584

Merged
merged 1 commit into from
Jul 26, 2023
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
7 changes: 7 additions & 0 deletions docs/containers.conf.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,13 @@ limit is never exceeded.

Default format tag for container log messages. This is useful for creating a specific tag for container log messages. Container log messages default to using the truncated container ID as a tag.

**mounts**=[]

List of mounts.
Specified as "type=TYPE,source=<directory-on-host>,destination=<directory-in-container>,<options>"
vrothberg marked this conversation as resolved.
Show resolved Hide resolved

Example: [ "type=bind,source=/var/lib/foobar,destination=/var/lib/foobar,ro", ]

**netns**="private"

Default way to to create a NET namespace for the container.
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ type ContainersConfig struct {
// Containers logs default to truncated container ID as a tag.
LogTag string `toml:"log_tag,omitempty"`

// Mount to add to all containers
Mounts []string `toml:"mounts,omitempty"`

// NetNS indicates how to create a network namespace for the container
NetNS string `toml:"netns,omitempty"`

Expand Down
6 changes: 6 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ image_copy_tmp_dir="storage"`
"TERM=xterm",
}

mounts := []string{
"type=glob,source=/tmp/test2*,ro=true",
"type=bind,source=/etc/services,destination=/etc/services,ro",
}

volumes := []string{
"$HOME:$HOME",
}
Expand All @@ -265,6 +270,7 @@ image_copy_tmp_dir="storage"`
gomega.Expect(err).To(gomega.BeNil())
gomega.Expect(defaultConfig.Engine.CgroupManager).To(gomega.Equal("systemd"))
gomega.Expect(defaultConfig.Containers.Env).To(gomega.BeEquivalentTo(envs))
gomega.Expect(defaultConfig.Containers.Mounts).To(gomega.BeEquivalentTo(mounts))
gomega.Expect(defaultConfig.Containers.PidsLimit).To(gomega.BeEquivalentTo(2048))
gomega.Expect(defaultConfig.Network.CNIPluginDirs).To(gomega.Equal(pluginDirs))
gomega.Expect(defaultConfig.Network.NetavarkPluginDirs).To(gomega.Equal([]string{"/usr/netavark"}))
Expand Down
9 changes: 8 additions & 1 deletion pkg/config/containers.conf
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ default_sysctls = [
#
#log_tag = ""

# List of mounts. Specified as
# "type=TYPE,source=<directory-on-host>,destination=<directory-in-container>,<options>", for example:
# "type=bind,source=/var/lib/foobar,destination=/var/lib/foobar,ro".
# If it is empty or commented out, no mounts will be added
#
#mounts = []

# Default way to to create a Network namespace for the container
# Options are:
# `private` Create private Network Namespace for the container.
Expand Down Expand Up @@ -276,7 +283,7 @@ default_sysctls = [
# If it is empty or commented out, no volumes will be added
#
#volumes = []
#

#[engine.platform_to_oci_runtime]
#"wasi/wasm" = ["crun-wasm"]
#"wasi/wasm32" = ["crun-wasm"]
Expand Down
22 changes: 14 additions & 8 deletions pkg/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,18 @@ func DefaultConfig() (*Config, error) {

return &Config{
Containers: ContainersConfig{
Devices: []string{},
Volumes: []string{},
Annotations: []string{},
ApparmorProfile: DefaultApparmorProfile,
BaseHostsFile: "",
CgroupNS: cgroupNS,
Cgroups: getDefaultCgroupsMode(),
DNSOptions: []string{},
DNSSearches: []string{},
DNSServers: []string{},
DefaultCapabilities: DefaultCapabilities,
DefaultSysctls: []string{},
DefaultUlimits: getDefaultProcessLimits(),
DNSServers: []string{},
DNSOptions: []string{},
DNSSearches: []string{},
Devices: []string{},
EnableKeyring: true,
EnableLabeling: selinuxEnabled(),
Env: []string{
Expand All @@ -207,20 +206,22 @@ func DefaultConfig() (*Config, error) {
},
EnvHost: false,
HTTPProxy: true,
IPCNS: "shareable",
Init: false,
InitPath: "",
IPCNS: "shareable",
LogDriver: defaultLogDriver(),
LogSizeMax: DefaultLogSizeMax,
Mounts: []string{},
NetNS: "private",
NoHosts: false,
PidsLimit: DefaultPidsLimit,
PidNS: "private",
PidsLimit: DefaultPidsLimit,
ShmSize: DefaultShmSize,
TZ: "",
Umask: "0022",
UTSNS: "private",
Umask: "0022",
UserNSSize: DefaultUserNSSize, // Deprecated
Volumes: []string{},
},
Network: NetworkConfig{
DefaultNetwork: "podman",
Expand Down Expand Up @@ -500,6 +501,11 @@ func (c *Config) Volumes() []string {
return c.Containers.Volumes
}

// Mounts returns the default set of mounts that should be mounted in containers.
func (c *Config) Mounts() []string {
return c.Containers.Mounts
}

// Devices returns the default additional devices for containers.
func (c *Config) Devices() []string {
return c.Containers.Devices
Expand Down
5 changes: 5 additions & 0 deletions pkg/config/testdata/containers_default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ label = true
# limit is never exceeded.
log_size_max = -1

mounts= [
"type=glob,source=/tmp/test2*,ro=true",
"type=bind,source=/etc/services,destination=/etc/services,ro",
]

oom_score_adj = 750

# Maximum number of processes allowed in a container.
Expand Down