Merge pull request #5018 from mheon/new_anon_field

Deprecate & remove IsCtrSpecific in favor of IsAnon
This commit is contained in:
OpenShift Merge Robot
2020-01-29 14:01:52 -08:00
committed by GitHub
6 changed files with 21 additions and 24 deletions

View File

@ -137,7 +137,7 @@ func (c *Container) Commit(ctx context.Context, destImage string, options Contai
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "volume %s used in container %s has been removed", v.Name, c.ID()) return nil, errors.Wrapf(err, "volume %s used in container %s has been removed", v.Name, c.ID())
} }
if vol.IsCtrSpecific() { if vol.Anonymous() {
importBuilder.AddVolume(v.Dest) importBuilder.AddVolume(v.Dest)
} }
} }

View File

@ -1546,17 +1546,16 @@ func WithVolumeGID(gid int) VolumeCreateOption {
} }
} }
// withSetCtrSpecific sets a bool notifying libpod that a volume was created // withSetAnon sets a bool notifying libpod that this volume is anonymous and
// specifically for a container. // should be removed when containers using it are removed and volumes are
// These volumes will be removed when the container is removed and volumes are // specified for removal.
// also specified for removal. func withSetAnon() VolumeCreateOption {
func withSetCtrSpecific() VolumeCreateOption {
return func(volume *Volume) error { return func(volume *Volume) error {
if volume.valid { if volume.valid {
return define.ErrVolumeFinalized return define.ErrVolumeFinalized
} }
volume.config.IsCtrSpecific = true volume.config.IsAnon = true
return nil return nil
} }

View File

@ -319,7 +319,7 @@ func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (c *Contai
// The volume does not exist, so we need to create it. // The volume does not exist, so we need to create it.
volOptions := []VolumeCreateOption{WithVolumeName(vol.Name), WithVolumeUID(ctr.RootUID()), WithVolumeGID(ctr.RootGID())} volOptions := []VolumeCreateOption{WithVolumeName(vol.Name), WithVolumeUID(ctr.RootUID()), WithVolumeGID(ctr.RootGID())}
if isAnonymous { if isAnonymous {
volOptions = append(volOptions, withSetCtrSpecific()) volOptions = append(volOptions, withSetAnon())
} }
newVol, err := r.newVolume(ctx, volOptions...) newVol, err := r.newVolume(ctx, volOptions...)
if err != nil { if err != nil {
@ -569,7 +569,7 @@ func (r *Runtime) removeContainer(ctx context.Context, c *Container, force bool,
for _, v := range c.config.NamedVolumes { for _, v := range c.config.NamedVolumes {
if volume, err := runtime.state.Volume(v.Name); err == nil { if volume, err := runtime.state.Volume(v.Name); err == nil {
if !volume.IsCtrSpecific() { if !volume.Anonymous() {
continue continue
} }
if err := runtime.removeVolume(ctx, volume, false); err != nil && errors.Cause(err) != define.ErrNoSuchVolume { if err := runtime.removeVolume(ctx, volume, false); err != nil && errors.Cause(err) != define.ErrNoSuchVolume {
@ -707,7 +707,7 @@ func (r *Runtime) evictContainer(ctx context.Context, idOrName string, removeVol
for _, v := range c.config.NamedVolumes { for _, v := range c.config.NamedVolumes {
if volume, err := r.state.Volume(v.Name); err == nil { if volume, err := r.state.Volume(v.Name); err == nil {
if !volume.IsCtrSpecific() { if !volume.Anonymous() {
continue continue
} }
if err := r.removeVolume(ctx, volume, false); err != nil && err != define.ErrNoSuchVolume && err != define.ErrVolumeBeingUsed { if err := r.removeVolume(ctx, volume, false); err != nil && err != define.ErrNoSuchVolume && err != define.ErrVolumeBeingUsed {

View File

@ -261,7 +261,7 @@ func (r *Runtime) removePod(ctx context.Context, p *Pod, removeCtrs, force bool)
logrus.Errorf("Error retrieving volume %s: %v", volName, err) logrus.Errorf("Error retrieving volume %s: %v", volName, err)
continue continue
} }
if !volume.IsCtrSpecific() { if !volume.Anonymous() {
continue continue
} }
if err := r.removeVolume(ctx, volume, false); err != nil { if err := r.removeVolume(ctx, volume, false); err != nil {

View File

@ -38,9 +38,8 @@ type VolumeConfig struct {
// a list of mount options. For other drivers, they are passed to the // a list of mount options. For other drivers, they are passed to the
// volume driver handling the volume. // volume driver handling the volume.
Options map[string]string `json:"volumeOptions,omitempty"` Options map[string]string `json:"volumeOptions,omitempty"`
// Whether this volume was created for a specific container and will be // Whether this volume is anonymous (will be removed on container exit)
// removed with it. IsAnon bool `json:"isAnon"`
IsCtrSpecific bool `json:"ctrSpecific"`
// UID the volume will be created as. // UID the volume will be created as.
UID int `json:"uid"` UID int `json:"uid"`
// GID the volume will be created as. // GID the volume will be created as.
@ -106,11 +105,10 @@ func (v *Volume) Options() map[string]string {
return options return options
} }
// IsCtrSpecific returns whether this volume was created specifically for a // Anonymous returns whether this volume is anonymous. Anonymous volumes were
// given container. Images with this set to true will be removed when the // created with a container, and will be removed when that container is removed.
// container is removed with the Volumes parameter set to true. func (v *Volume) Anonymous() bool {
func (v *Volume) IsCtrSpecific() bool { return v.config.IsAnon
return v.config.IsCtrSpecific
} }
// UID returns the UID the volume will be created as. // UID returns the UID the volume will be created as.

View File

@ -37,10 +37,10 @@ type InspectVolumeData struct {
UID int `json:"UID,omitempty"` UID int `json:"UID,omitempty"`
// GID is the GID that the volume was created with. // GID is the GID that the volume was created with.
GID int `json:"GID,omitempty"` GID int `json:"GID,omitempty"`
// ContainerSpecific indicates that the volume was created as part of a // Anonymous indicates that the volume was created as an anonymous
// specific container, and will be removed when that container is // volume for a specific container, and will be be removed when any
// removed. // container using it is removed.
ContainerSpecific bool `json:"ContainerSpecific,omitempty"` Anonymous bool `json:"Anonymous,omitempty"`
} }
// Inspect provides detailed information about the configuration of the given // Inspect provides detailed information about the configuration of the given
@ -67,7 +67,7 @@ func (v *Volume) Inspect() (*InspectVolumeData, error) {
} }
data.UID = v.config.UID data.UID = v.config.UID
data.GID = v.config.GID data.GID = v.config.GID
data.ContainerSpecific = v.config.IsCtrSpecific data.Anonymous = v.config.IsAnon
return data, nil return data, nil
} }