From c7eb4ce82795dfb3ab79dba62da0f87942f5ab11 Mon Sep 17 00:00:00 2001 From: Gianluca Arbezzano Date: Wed, 7 Aug 2019 12:13:54 +0200 Subject: [PATCH] Added exponential backoff during image pull Signed-off-by: Gianluca Arbezzano --- docker.go | 8 +++++++- go.mod | 1 + go.sum | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docker.go b/docker.go index 0748633b8c..f8e1c2dc87 100644 --- a/docker.go +++ b/docker.go @@ -10,6 +10,7 @@ import ( "os/exec" "strings" + "github.com/cenkalti/backoff" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/mount" @@ -258,7 +259,12 @@ func (p *DockerProvider) CreateContainer(ctx context.Context, req ContainerReque if req.RegistryCred != "" { pullOpt.RegistryAuth = req.RegistryCred } - pull, err := p.client.ImagePull(ctx, req.Image, pullOpt) + var pull io.ReadCloser + err := backoff.Retry(func() error { + var err error + pull, err = p.client.ImagePull(ctx, req.Image, pullOpt) + return err + }, backoff.NewExponentialBackOff()) if err != nil { return nil, err } diff --git a/go.mod b/go.mod index f5730933e8..bb0b37ae2e 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ replace github.com/docker/docker => github.com/docker/engine v0.0.0-201907171610 require ( github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect github.com/Microsoft/go-winio v0.4.11 // indirect + github.com/cenkalti/backoff v2.2.1+incompatible github.com/docker/distribution v2.7.1-0.20190205005809-0d3efadf0154+incompatible // indirect github.com/docker/docker v0.7.3-0.20190506211059-b20a14b54661 github.com/docker/go-connections v0.4.0 diff --git a/go.sum b/go.sum index ac3148ff13..1e74868c26 100644 --- a/go.sum +++ b/go.sum @@ -3,6 +3,8 @@ github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7O github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= github.com/Microsoft/go-winio v0.4.11 h1:zoIOcVf0xPN1tnMVbTtEdI+P8OofVk3NObnwOQ6nK2Q= github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA= +github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= +github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=