diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2021-05-05 14:28:10 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-05 14:28:10 -0400 |
commit | dbc4a5d85bb948a41af710804d61cdba8aac8e0b (patch) | |
tree | b468b9cf7ce10a5e1be756656513274f4eda228d | |
parent | 7b50af42c30e6a0d80a20a4e55f6cc7d2c0110d5 (diff) | |
parent | 68fe1950fe5bad7e29b7a75bb1e94a54fd7e5360 (diff) | |
download | podman-dbc4a5d85bb948a41af710804d61cdba8aac8e0b.tar.gz podman-dbc4a5d85bb948a41af710804d61cdba8aac8e0b.tar.bz2 podman-dbc4a5d85bb948a41af710804d61cdba8aac8e0b.zip |
Merge pull request #10220 from giuseppe/rm-volatile
podman: set volatile storage flag for --rm containers
-rw-r--r-- | cmd/podman/common/specgen.go | 1 | ||||
-rw-r--r-- | libpod/container_config.go | 3 | ||||
-rw-r--r-- | libpod/container_internal.go | 2 | ||||
-rw-r--r-- | libpod/options.go | 13 | ||||
-rw-r--r-- | pkg/specgen/generate/container_create.go | 3 | ||||
-rw-r--r-- | pkg/specgen/specgen.go | 3 |
6 files changed, 25 insertions, 0 deletions
diff --git a/cmd/podman/common/specgen.go b/cmd/podman/common/specgen.go index f889a0169..d0b012090 100644 --- a/cmd/podman/common/specgen.go +++ b/cmd/podman/common/specgen.go @@ -646,6 +646,7 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string s.Umask = c.Umask s.Secrets = c.Secrets s.PidFile = c.PidFile + s.Volatile = c.Rm return nil } diff --git a/libpod/container_config.go b/libpod/container_config.go index ede6b1aab..da732c05b 100644 --- a/libpod/container_config.go +++ b/libpod/container_config.go @@ -151,6 +151,9 @@ type ContainerRootFSConfig struct { Secrets []*secrets.Secret `json:"secrets,omitempty"` // SecretPath is the secrets location in storage SecretsPath string `json:"secretsPath"` + // Volatile specifies whether the container storage can be optimized + // at the cost of not syncing all the dirty files in memory. + Volatile bool `json:"volatile,omitempty"` } // ContainerSecurityConfig is an embedded sub-config providing security configuration diff --git a/libpod/container_internal.go b/libpod/container_internal.go index 132012404..051fe4b9e 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -451,6 +451,8 @@ func (c *Container) setupStorage(ctx context.Context) error { options.MountOpts = newOptions } + options.Volatile = c.config.Volatile + c.setupStorageMapping(&options.IDMappingOptions, &c.config.IDMappings) containerInfo, err := c.runtime.storageService.CreateContainerStorage(ctx, c.runtime.imageContext, c.config.RootfsImageName, c.config.RootfsImageID, c.config.Name, c.config.ID, options) diff --git a/libpod/options.go b/libpod/options.go index 39415a817..391cf0147 100644 --- a/libpod/options.go +++ b/libpod/options.go @@ -2318,3 +2318,16 @@ func WithPodSlirp4netns(networkOptions map[string][]string) PodCreateOption { return nil } } + +// WithVolatile sets the volatile flag for the container storage. +// The option can potentially cause data loss when used on a container that must survive a machine reboot. +func WithVolatile() CtrCreateOption { + return func(ctr *Container) error { + if ctr.valid { + return define.ErrCtrFinalized + } + + ctr.config.Volatile = true + return nil + } +} diff --git a/pkg/specgen/generate/container_create.go b/pkg/specgen/generate/container_create.go index 01f939022..0090156c9 100644 --- a/pkg/specgen/generate/container_create.go +++ b/pkg/specgen/generate/container_create.go @@ -200,6 +200,9 @@ func createContainerOptions(ctx context.Context, rt *libpod.Runtime, s *specgen. if s.Umask != "" { options = append(options, libpod.WithUmask(s.Umask)) } + if s.Volatile { + options = append(options, libpod.WithVolatile()) + } useSystemd := false switch s.Systemd { diff --git a/pkg/specgen/specgen.go b/pkg/specgen/specgen.go index fdcb7a0e0..5ef2b0653 100644 --- a/pkg/specgen/specgen.go +++ b/pkg/specgen/specgen.go @@ -256,6 +256,9 @@ type ContainerStorageConfig struct { // Secrets are the secrets that will be added to the container // Optional. Secrets []string `json:"secrets,omitempty"` + // Volatile specifies whether the container storage can be optimized + // at the cost of not syncing all the dirty files in memory. + Volatile bool `json:"volatile,omitempty"` } // ContainerSecurityConfig is a container's security features, including |