mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
daemon: cleanupContainer(): pass ContainerRmConfig as parameter
We already have this config, so might as well pass it, instead of passing each option as a separate argument. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
4430992af8
commit
f3bce92a24
2 changed files with 10 additions and 6 deletions
|
@ -153,8 +153,12 @@ func (daemon *Daemon) create(opts createOpts) (retC *container.Container, retErr
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if retErr != nil {
|
if retErr != nil {
|
||||||
if err := daemon.cleanupContainer(ctr, true, true); err != nil {
|
err = daemon.cleanupContainer(ctr, types.ContainerRmConfig{
|
||||||
logrus.Errorf("failed to cleanup container on create error: %v", err)
|
ForceRemove: true,
|
||||||
|
RemoveVolume: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
logrus.WithError(err).Error("failed to cleanup container on create error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
|
@ -43,7 +43,7 @@ func (daemon *Daemon) ContainerRm(name string, config *types.ContainerRmConfig)
|
||||||
return daemon.rmLink(ctr, name)
|
return daemon.rmLink(ctr, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = daemon.cleanupContainer(ctr, config.ForceRemove, config.RemoveVolume)
|
err = daemon.cleanupContainer(ctr, *config)
|
||||||
containerActions.WithValues("delete").UpdateSince(start)
|
containerActions.WithValues("delete").UpdateSince(start)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
@ -77,9 +77,9 @@ func (daemon *Daemon) rmLink(container *container.Container, name string) error
|
||||||
|
|
||||||
// cleanupContainer unregisters a container from the daemon, stops stats
|
// cleanupContainer unregisters a container from the daemon, stops stats
|
||||||
// collection and cleanly removes contents and metadata from the filesystem.
|
// collection and cleanly removes contents and metadata from the filesystem.
|
||||||
func (daemon *Daemon) cleanupContainer(container *container.Container, forceRemove, removeVolume bool) error {
|
func (daemon *Daemon) cleanupContainer(container *container.Container, config types.ContainerRmConfig) error {
|
||||||
if container.IsRunning() {
|
if container.IsRunning() {
|
||||||
if !forceRemove {
|
if !config.ForceRemove {
|
||||||
state := container.StateString()
|
state := container.StateString()
|
||||||
procedure := "Stop the container before attempting removal or force remove"
|
procedure := "Stop the container before attempting removal or force remove"
|
||||||
if state == "paused" {
|
if state == "paused" {
|
||||||
|
@ -135,7 +135,7 @@ func (daemon *Daemon) cleanupContainer(container *container.Container, forceRemo
|
||||||
daemon.idIndex.Delete(container.ID)
|
daemon.idIndex.Delete(container.ID)
|
||||||
daemon.containers.Delete(container.ID)
|
daemon.containers.Delete(container.ID)
|
||||||
daemon.containersReplica.Delete(container)
|
daemon.containersReplica.Delete(container)
|
||||||
if err := daemon.removeMountPoints(container, removeVolume); err != nil {
|
if err := daemon.removeMountPoints(container, config.RemoveVolume); err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
for _, name := range linkNames {
|
for _, name := range linkNames {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue