Skip to content

Commit

Permalink
Support setting image_volume_mode in containers.conf
Browse files Browse the repository at this point in the history
Begins to fix containers/podman#14230

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed May 13, 2022
1 parent 7536bf6 commit b86f992
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/containers.conf.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,16 @@ Default transport method for pulling and pushing images.
Maximum number of image layers to be copied (pulled/pushed) simultaneously.
Not setting this field will fall back to containers/image defaults. (6)

**image_volume_mode**="bind"

Tells container engines how to handle the builtin image volumes.
• bind: An anonymous named volume will be created and mounted
into the container.
• tmpfs: The volume is mounted onto the container as a tmpfs,
which allows the users to create content that disappears when
the container is stopped.
• ignore: All volumes are just ignored and no action is taken.

**infra_command**="/pause"

Infra (pause) container image command for pod infra containers. When running a
Expand Down
21 changes: 21 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/BurntSushi/toml"
"github.com/containers/common/libnetwork/types"
"github.com/containers/common/pkg/capabilities"
"github.com/containers/common/pkg/util"
"github.com/containers/storage/pkg/unshare"
units "github.com/docker/go-units"
selinux "github.com/opencontainers/selinux/go-selinux"
Expand Down Expand Up @@ -46,6 +47,8 @@ const (
BoltDBStateStore RuntimeStateStore = iota
)

var validImageVolumeModes = []string{"bind", "tmpfs", "ignore"}

// ProxyEnv is a list of Proxy Environment variables
var ProxyEnv = []string{
"http_proxy",
Expand Down Expand Up @@ -294,6 +297,10 @@ type EngineConfig struct {
// Building/committing defaults to OCI.
ImageDefaultFormat string `toml:"image_default_format,omitempty"`

// ImageVolumeMode Tells container engines how to handle the builtin
// image volumes. Values bind, tmpfs, ignore
ImageVolumeMode string `toml:"image_volume_mode,omitempty"`

// InfraCommand is the command run to start up a pod infra container.
InfraCommand string `toml:"infra_command,omitempty"`

Expand Down Expand Up @@ -821,6 +828,9 @@ func (c *EngineConfig) Validate() error {
return err
}

if err := ValidateImageVolumeMode(c.ImageVolumeMode); err != nil {
return err
}
// Check if the pullPolicy from containers.conf is valid
// if it is invalid returns the error
pullPolicy := strings.ToLower(c.PullPolicy)
Expand Down Expand Up @@ -1305,3 +1315,14 @@ func (e eventsLogMaxSize) MarshalText() ([]byte, error) {
}
return []byte(fmt.Sprintf("%d", e)), nil
}

func ValidateImageVolumeMode(mode string) error {
if mode == "" {
return nil
}
if util.StringInSlice(mode, validImageVolumeModes) {
return nil
}

return fmt.Errorf("Invalid image volume mode %q required value: %s", mode, strings.Join(validImageVolumeModes, ", "))
}
11 changes: 11 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var _ = Describe("Config", func() {
gomega.Expect(defaultConfig.NetNS()).To(gomega.BeEquivalentTo("private"))
gomega.Expect(defaultConfig.IPCNS()).To(gomega.BeEquivalentTo("shareable"))
gomega.Expect(defaultConfig.Engine.InfraImage).To(gomega.BeEquivalentTo(""))
gomega.Expect(defaultConfig.Engine.ImageVolumeMode).To(gomega.BeEquivalentTo("bind"))
path, err := defaultConfig.ImageCopyTmpDir()
gomega.Expect(err).To(gomega.BeNil())
gomega.Expect(path).To(gomega.BeEquivalentTo("/var/tmp"))
Expand Down Expand Up @@ -378,6 +379,7 @@ image_copy_tmp_dir="storage"`
gomega.Expect(config.Containers.PidsLimit).To(gomega.BeEquivalentTo(2048))
gomega.Expect(config.Containers.BaseHostsFile).To(gomega.BeEquivalentTo("/etc/hosts2"))
gomega.Expect(config.Containers.HostContainersInternalIP).To(gomega.BeEquivalentTo("1.2.3.4"))
gomega.Expect(config.Engine.ImageVolumeMode).To(gomega.BeEquivalentTo("tmpfs"))
})

It("contents of passed-in file should override others", func() {
Expand Down Expand Up @@ -812,4 +814,13 @@ env=["foo=bar"]`
gomega.Expect(string(b)).To(gomega.
Equal("[containers]\n\n[engine]\n\n[machine]\n\n[network]\n\n[secrets]\n\n[configmaps]\n"))
})

It("validate ImageVolumeMode", func() {
for _, mode := range append(validImageVolumeModes, "") {
err := ValidateImageVolumeMode(mode)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
}
err := ValidateImageVolumeMode("bogus")
gomega.Expect(err).To(gomega.HaveOccurred())
})
})
10 changes: 10 additions & 0 deletions pkg/config/containers.conf
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,16 @@ default_sysctls = [
#
#image_parallel_copies = 0

# Tells container engines how to handle the builtin image volumes.
# • bind: An anonymous named volume will be created and mounted
# into the container.
# • tmpfs: The volume is mounted onto the container as a tmpfs,
# which allows the users to create content that disappears when
# the container is stopped.
# • ignore: All volumes are just ignored and no action is taken.
#
#image_volume_mode = ""

# Default command to run the infra container
#
#infra_command = "/pause"
Expand Down
4 changes: 4 additions & 0 deletions pkg/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ const (
// _defaultTransport is a prefix that we apply to an image name to check
// docker hub first for the image.
_defaultTransport = "docker://"

// _defaultImageVolumeMode is a mode to handle buildint image volumes
_defaultImageVolumeMode = "bind"
)

var (
Expand Down Expand Up @@ -294,6 +297,7 @@ func defaultConfigFromMemory() (*EngineConfig, error) {
}
c.HooksDir = DefaultHooksDirs
c.ImageDefaultTransport = _defaultTransport
c.ImageVolumeMode = _defaultImageVolumeMode
c.StateType = BoltDBStateStore

c.ImageBuildFormat = "oci"
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/testdata/containers_default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ conmon_env_vars = [

image_copy_tmp_dir="storage"

image_volume_mode = "tmpfs"


# Paths to look for the Conmon container manager binary
conmon_path = [
Expand Down

0 comments on commit b86f992

Please sign in to comment.