Skip to content

Commit

Permalink
Merge pull request #3643 from tejal29/re-try
Browse files Browse the repository at this point in the history
retry pruning when skaffold could not prune local images due running containers
  • Loading branch information
balopat authored Feb 7, 2020
2 parents 12581fe + b317fbe commit 8bdeebc
Showing 1 changed file with 18 additions and 1 deletion.
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

0 comments on commit 8bdeebc

Please sign in to comment.