Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retry pruning when skaffold could not prune local images due running containers #3643

Merged
merged 4 commits into from
Feb 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion pkg/skaffold/docker/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ import (
"sort"
"strings"
"sync"
"time"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/client"
"github.com/docker/docker/errdefs"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/pkg/progress"
"github.com/docker/docker/pkg/streamformatter"
Expand All @@ -39,6 +41,11 @@ import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/util"
)

const (
retries = 5
sleepTime = 1 * time.Second
)

type ContainerRun struct {
Image string
User string
Expand Down Expand Up @@ -384,7 +391,17 @@ func (l *localDaemon) ImageInspectWithRaw(ctx context.Context, image string) (ty
}

func (l *localDaemon) ImageRemove(ctx context.Context, image string, opts types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) {
return l.apiClient.ImageRemove(ctx, image, opts)
for i := 0; i < retries; i++ {
resp, err := l.apiClient.ImageRemove(ctx, image, opts)
if err == nil {
return resp, nil
}
if _, ok := err.(errdefs.ErrConflict); !ok {
return nil, err
}
time.Sleep(sleepTime)
}
return nil, fmt.Errorf("could not remove image after %d retries", retries)
}

// GetBuildArgs gives the build args flags for docker build.
Expand Down