From 23fbd3ad0e9dd1ad20acb31becf126ef38b7750e Mon Sep 17 00:00:00 2001 From: Tejal Desai Date: Tue, 4 Feb 2020 16:12:57 -0800 Subject: [PATCH 1/4] retry removing error when skaffolf could not prune local images due to other running containers --- pkg/skaffold/docker/image.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/skaffold/docker/image.go b/pkg/skaffold/docker/image.go index 542fd021e6c..d3d4b21d5ec 100644 --- a/pkg/skaffold/docker/image.go +++ b/pkg/skaffold/docker/image.go @@ -20,10 +20,12 @@ import ( "context" "encoding/json" "fmt" + "github.com/docker/docker/errdefs" "io" "sort" "strings" "sync" + "time" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/mount" @@ -39,6 +41,11 @@ import ( "github.com/GoogleContainerTools/skaffold/pkg/skaffold/util" ) +const ( + retrials = 5 + sleepTime = 1 * time.Second +) + type ContainerRun struct { Image string User string @@ -210,6 +217,7 @@ func (l *localDaemon) Build(ctx context.Context, out io.Writer, workspace string if imageID == "" { // Maybe this version of Docker doesn't return the digest of the image // that has been built. + logrus.Debugf("This version of docker does not return the digest.") imageID, err = l.ImageID(ctx, ref) if err != nil { return "", errors.Wrap(err, "getting digest") @@ -384,7 +392,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 < retrials; 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 for %d re-trails", retrials) } // GetBuildArgs gives the build args flags for docker build. From 92e3b4a4cde13bc256b955e96ed11fcd24e9cfae Mon Sep 17 00:00:00 2001 From: Tejal Desai Date: Tue, 4 Feb 2020 16:55:38 -0800 Subject: [PATCH 2/4] fix lint --- pkg/skaffold/docker/image.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/skaffold/docker/image.go b/pkg/skaffold/docker/image.go index d3d4b21d5ec..820574d3388 100644 --- a/pkg/skaffold/docker/image.go +++ b/pkg/skaffold/docker/image.go @@ -20,7 +20,6 @@ import ( "context" "encoding/json" "fmt" - "github.com/docker/docker/errdefs" "io" "sort" "strings" @@ -30,6 +29,7 @@ import ( "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" @@ -42,7 +42,7 @@ import ( ) const ( - retrials = 5 + retrials = 5 sleepTime = 1 * time.Second ) @@ -217,7 +217,6 @@ func (l *localDaemon) Build(ctx context.Context, out io.Writer, workspace string if imageID == "" { // Maybe this version of Docker doesn't return the digest of the image // that has been built. - logrus.Debugf("This version of docker does not return the digest.") imageID, err = l.ImageID(ctx, ref) if err != nil { return "", errors.Wrap(err, "getting digest") From bf7f963bdd09e1373a5f19fb77cb93d13473c518 Mon Sep 17 00:00:00 2001 From: Tejal Desai Date: Fri, 7 Feb 2020 08:43:05 -0800 Subject: [PATCH 3/4] Update pkg/skaffold/docker/image.go Co-Authored-By: Balint Pato --- pkg/skaffold/docker/image.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/skaffold/docker/image.go b/pkg/skaffold/docker/image.go index 820574d3388..e47a4230922 100644 --- a/pkg/skaffold/docker/image.go +++ b/pkg/skaffold/docker/image.go @@ -401,7 +401,7 @@ func (l *localDaemon) ImageRemove(ctx context.Context, image string, opts types. } time.Sleep(sleepTime) } - return nil, fmt.Errorf("could not remove image for %d re-trails", retrials) + return nil, fmt.Errorf("could not remove image after %d retries", retrials) } // GetBuildArgs gives the build args flags for docker build. From b317fbeab2599d2d57a249f1073a484b2bdbb774 Mon Sep 17 00:00:00 2001 From: Tejal Desai Date: Fri, 7 Feb 2020 11:35:35 -0800 Subject: [PATCH 4/4] fix lints --- pkg/skaffold/docker/image.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/skaffold/docker/image.go b/pkg/skaffold/docker/image.go index e47a4230922..ba4a2e89c70 100644 --- a/pkg/skaffold/docker/image.go +++ b/pkg/skaffold/docker/image.go @@ -29,7 +29,7 @@ import ( "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/errdefs" "github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/pkg/progress" "github.com/docker/docker/pkg/streamformatter" @@ -42,7 +42,7 @@ import ( ) const ( - retrials = 5 + retries = 5 sleepTime = 1 * time.Second ) @@ -391,7 +391,7 @@ 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) { - for i := 0; i < retrials; i++ { + for i := 0; i < retries; i++ { resp, err := l.apiClient.ImageRemove(ctx, image, opts) if err == nil { return resp, nil @@ -401,7 +401,7 @@ func (l *localDaemon) ImageRemove(ctx context.Context, image string, opts types. } time.Sleep(sleepTime) } - return nil, fmt.Errorf("could not remove image after %d retries", retrials) + return nil, fmt.Errorf("could not remove image after %d retries", retries) } // GetBuildArgs gives the build args flags for docker build.