Skip to content

Commit

Permalink
Merge pull request containers#10220 from giuseppe/rm-volatile
Browse files Browse the repository at this point in the history
podman: set volatile storage flag for --rm containers
  • Loading branch information
openshift-merge-robot authored May 5, 2021
2 parents 7b50af4 + 68fe195 commit dbc4a5d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/podman/common/specgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions libpod/container_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions libpod/container_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions libpod/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
3 changes: 3 additions & 0 deletions pkg/specgen/generate/container_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions pkg/specgen/specgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dbc4a5d

Please sign in to comment.