Skip to content

Commit

Permalink
fix: clean up stale snapshots on container start
Browse files Browse the repository at this point in the history
I wasn't able to reproduce this case, but looks like containerd can get
into a state when the snapshot was left behind, but container record is
missing. This prevents the container from being started with the error:

```
failed to create container kubelet: snapshot kubelet: already exists
```

This PR should help to fix this issue by trying to remove the snapshot
by name even if the container record is not found.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
  • Loading branch information
smira authored and talos-bot committed May 31, 2021
1 parent c036b94 commit f112a54
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/containerd/containerd"
"github.com/containerd/containerd/cio"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/oci"

Expand Down Expand Up @@ -84,6 +85,10 @@ func (c *containerdRunner) Open(ctx context.Context) error {
}
}

if err = c.client.SnapshotService("").Remove(c.ctx, c.args.ID); err != nil && !errdefs.IsNotFound(err) {
return fmt.Errorf("error cleaning up stale snapshot: %w", err)
}

// Create the container.
specOpts := c.newOCISpecOpts(image)
containerOpts := c.newContainerOpts(image, specOpts)
Expand Down

0 comments on commit f112a54

Please sign in to comment.