feat(engine): Add debug logs for Docker.Destroy errors (#20)
* feat(engine): Add debug logs for Docker.Destroy errors This doesn't change the current behaviour of ignoring the errors, but adds some debug logging to help identify issues with the underlying Docker engine when stopping and cleeaning up containers, volumes and networks. Signed-off-by: Javier Palomo <javier.palomo@grafana.com> * feat(engine): check for ErrNotFound and Conflict Co-authored-by: Marko Gaćeša <markogacesa@hotmail.com> Co-authored-by: Marko Gaćeša <markogacesa@hotmail.com>
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
"github.com/docker/docker/api/types/network"
|
||||
"github.com/docker/docker/api/types/volume"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/docker/docker/errdefs"
|
||||
)
|
||||
|
||||
// Opts configures the Docker engine.
|
||||
@@ -135,12 +136,22 @@ func (e *Docker) Destroy(ctx context.Context, specv runtime.Spec) error {
|
||||
|
||||
// stop all containers
|
||||
for _, step := range append(spec.Steps, spec.Internal...) {
|
||||
e.client.ContainerKill(ctx, step.ID, "9")
|
||||
if err := e.client.ContainerKill(ctx, step.ID, "9"); err != nil && !client.IsErrNotFound(err) && !errdefs.IsConflict(err) {
|
||||
logger.FromContext(ctx).
|
||||
WithError(err).
|
||||
WithField("container", step.ID).
|
||||
Debugln("cannot kill container")
|
||||
}
|
||||
}
|
||||
|
||||
// cleanup all containers
|
||||
for _, step := range append(spec.Steps, spec.Internal...) {
|
||||
e.client.ContainerRemove(ctx, step.ID, removeOpts)
|
||||
if err := e.client.ContainerRemove(ctx, step.ID, removeOpts); err != nil && !client.IsErrNotFound(err) {
|
||||
logger.FromContext(ctx).
|
||||
WithError(err).
|
||||
WithField("container", step.ID).
|
||||
Debugln("cannot remove container")
|
||||
}
|
||||
}
|
||||
|
||||
// cleanup all volumes
|
||||
@@ -153,11 +164,21 @@ func (e *Docker) Destroy(ctx context.Context, specv runtime.Spec) error {
|
||||
if vol.EmptyDir.Medium == "memory" {
|
||||
continue
|
||||
}
|
||||
e.client.VolumeRemove(ctx, vol.EmptyDir.ID, true)
|
||||
if err := e.client.VolumeRemove(ctx, vol.EmptyDir.ID, true); err != nil {
|
||||
logger.FromContext(ctx).
|
||||
WithError(err).
|
||||
WithField("volume", vol.EmptyDir.ID).
|
||||
Debugln("cannot remove volume")
|
||||
}
|
||||
}
|
||||
|
||||
// cleanup the network
|
||||
e.client.NetworkRemove(ctx, spec.Network.ID)
|
||||
if err := e.client.NetworkRemove(ctx, spec.Network.ID); err != nil {
|
||||
logger.FromContext(ctx).
|
||||
WithError(err).
|
||||
WithField("network", spec.Network.ID).
|
||||
Debugln("cannot remove network")
|
||||
}
|
||||
|
||||
// notice that we never collect or return any errors.
|
||||
// this is because we silently ignore cleanup failures
|
||||
|
||||
Reference in New Issue
Block a user