From f787b475d538cdd4e440897ef2cadd61c1d367d9 Mon Sep 17 00:00:00 2001 From: Gyanendra Mishra Date: Mon, 3 Jul 2023 10:48:25 +0100 Subject: [PATCH 01/12] lets go and see what happens --- .../docker/docker_manager/docker_manager.go | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go b/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go index e13b44a8d9..296dab85fa 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go @@ -25,6 +25,7 @@ import ( "io/ioutil" "math" "net" + "runtime" "strings" "time" ) @@ -114,6 +115,9 @@ const ( emptyNetworkAlias = "" isDockerNetworkAttachable = true + + linuxAmd64 = "linux/amd64" + arm64 = "arm64" ) /* @@ -990,6 +994,12 @@ func (manager *DockerManager) FetchImage(ctx context.Context, dockerImage string logrus.Tracef("Image doesn't exist locally, so attempting to pull it...") err = manager.PullImage(ctx, dockerImage) if err != nil { + // if we are on ARM we try pulling the amd64 image as backup + if runtime.GOARCH == arm64 { + if err = manager.PullLinuxAmd64Image(ctx, dockerImage); err != nil { + return stacktrace.Propagate(err, "Had failed to pull image '%v' so tried pulling '%v' version of the image but that failed as well", dockerImage, linuxAmd64) + } + } return stacktrace.Propagate(err, "Failed to pull Docker image '%v' from remote image repository", dockerImage) } logrus.Tracef("Image successfully pulled from remote to local") @@ -1017,6 +1027,26 @@ func (manager *DockerManager) PullImage(context context.Context, imageName strin return nil } +// PullLinuxAmd64Image This function is a fallback incase we aren't able to pull an amd64 image for M1/M2s +func (manager *DockerManager) PullLinuxAmd64Image(context context.Context, imageName string) (err error) { + logrus.Infof("Pulling image '%s'...", imageName) + out, err := manager.dockerClient.ImagePull(context, imageName, types.ImagePullOptions{ + All: false, + RegistryAuth: "", + PrivilegeFunc: nil, + Platform: linuxAmd64, + }) + if err != nil { + return stacktrace.Propagate(err, "Failed to pull image %s", imageName) + } + defer out.Close() + _, err = io.Copy(ioutil.Discard, out) + if err != nil { + return stacktrace.Propagate(err, "An error occurred discarding the output") + } + return nil +} + func (manager *DockerManager) CreateContainerExec(context context.Context, containerId string, cmd []string) (*types.HijackedResponse, error) { config := types.ExecConfig{ User: "", From 45c27586eb3bccd5a08b20df41a26812d8f0f89d Mon Sep 17 00:00:00 2001 From: Gyanendra Mishra Date: Tue, 4 Jul 2023 14:08:00 +0100 Subject: [PATCH 02/12] fix platform\ --- .../docker/docker_manager/docker_manager.go | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go b/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go index 296dab85fa..d119ea7aee 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go @@ -994,12 +994,6 @@ func (manager *DockerManager) FetchImage(ctx context.Context, dockerImage string logrus.Tracef("Image doesn't exist locally, so attempting to pull it...") err = manager.PullImage(ctx, dockerImage) if err != nil { - // if we are on ARM we try pulling the amd64 image as backup - if runtime.GOARCH == arm64 { - if err = manager.PullLinuxAmd64Image(ctx, dockerImage); err != nil { - return stacktrace.Propagate(err, "Had failed to pull image '%v' so tried pulling '%v' version of the image but that failed as well", dockerImage, linuxAmd64) - } - } return stacktrace.Propagate(err, "Failed to pull Docker image '%v' from remote image repository", dockerImage) } logrus.Tracef("Image successfully pulled from remote to local") @@ -1017,26 +1011,12 @@ func (manager *DockerManager) PullImage(context context.Context, imageName strin Platform: "", }) if err != nil { - return stacktrace.Propagate(err, "Failed to pull image %s", imageName) - } - defer out.Close() - _, err = io.Copy(ioutil.Discard, out) - if err != nil { - return stacktrace.Propagate(err, "An error occurred discarding the output") - } - return nil -} - -// PullLinuxAmd64Image This function is a fallback incase we aren't able to pull an amd64 image for M1/M2s -func (manager *DockerManager) PullLinuxAmd64Image(context context.Context, imageName string) (err error) { - logrus.Infof("Pulling image '%s'...", imageName) - out, err := manager.dockerClient.ImagePull(context, imageName, types.ImagePullOptions{ - All: false, - RegistryAuth: "", - PrivilegeFunc: nil, - Platform: linuxAmd64, - }) - if err != nil { + // if we are on ARM we try pulling the amd64 image as backup + if runtime.GOARCH == arm64 { + if err = manager.pullLinuxAmd64Image(context, imageName); err != nil { + return stacktrace.Propagate(err, "Had failed to pull image '%v' so tried pulling '%v' version of the image but that failed as well", imageName, linuxAmd64) + } + } return stacktrace.Propagate(err, "Failed to pull image %s", imageName) } defer out.Close() @@ -1418,6 +1398,26 @@ func (manager *DockerManager) killContainerWithRetriesWhenErrorResponseFromDeamo return stacktrace.Propagate(err, "An error occurred killing container with ID '%v'", containerId) } +// pullLinuxAmd64Image This function is a fallback incase we aren't able to pull an amd64 image for M1/M2s +func (manager *DockerManager) pullLinuxAmd64Image(context context.Context, imageName string) (err error) { + logrus.Infof("Pulling image '%s'...", imageName) + out, err := manager.dockerClient.ImagePull(context, imageName, types.ImagePullOptions{ + All: false, + RegistryAuth: "", + PrivilegeFunc: nil, + Platform: linuxAmd64, + }) + if err != nil { + return stacktrace.Propagate(err, "Failed to pull image %s", imageName) + } + defer out.Close() + _, err = io.Copy(ioutil.Discard, out) + if err != nil { + return stacktrace.Propagate(err, "An error occurred discarding the output") + } + return nil +} + // Takes in a PortMap (as reported by Docker container inspect) and returns a map of the used ports -> host port binding on the expected interface // If no bindings for the interface are found, len(output) < len(input) func getHostPortBindingsOnExpectedInterface(hostPortBindingsOnAllInterfaces nat.PortMap) map[nat.Port]*nat.PortBinding { From d9e3b939a1d8faf9e1e822e20bad1a3ca08fb614 Mon Sep 17 00:00:00 2001 From: Gyanendra Mishra Date: Tue, 4 Jul 2023 14:25:38 +0100 Subject: [PATCH 03/12] change loggin --- .../lib/backend_impls/docker/docker_manager/docker_manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go b/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go index d119ea7aee..e36a404e04 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go @@ -1400,7 +1400,7 @@ func (manager *DockerManager) killContainerWithRetriesWhenErrorResponseFromDeamo // pullLinuxAmd64Image This function is a fallback incase we aren't able to pull an amd64 image for M1/M2s func (manager *DockerManager) pullLinuxAmd64Image(context context.Context, imageName string) (err error) { - logrus.Infof("Pulling image '%s'...", imageName) + logrus.Infof("Pulling backup linux amd64 image '%s'...", imageName) out, err := manager.dockerClient.ImagePull(context, imageName, types.ImagePullOptions{ All: false, RegistryAuth: "", From 5d85909d2d0a05dac6fe781287246a9431bb02d1 Mon Sep 17 00:00:00 2001 From: Gyanendra Mishra Date: Tue, 4 Jul 2023 14:27:01 +0100 Subject: [PATCH 04/12] yet naother log line --- .../lib/backend_impls/docker/docker_manager/docker_manager.go | 1 + 1 file changed, 1 insertion(+) diff --git a/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go b/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go index e36a404e04..960b802980 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go @@ -1019,6 +1019,7 @@ func (manager *DockerManager) PullImage(context context.Context, imageName strin } return stacktrace.Propagate(err, "Failed to pull image %s", imageName) } + logrus.Infof("It didn't error for '%v'", imageName) defer out.Close() _, err = io.Copy(ioutil.Discard, out) if err != nil { From 0e97cfcb1bc0ab41ac67777a1ec44a69ec49b88d Mon Sep 17 00:00:00 2001 From: Gyanendra Mishra Date: Tue, 4 Jul 2023 14:29:15 +0100 Subject: [PATCH 05/12] nicer logging --- .../backend_impls/docker/docker_manager/docker_manager.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go b/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go index 960b802980..d6d6cbbb8c 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go @@ -1019,9 +1019,10 @@ func (manager *DockerManager) PullImage(context context.Context, imageName strin } return stacktrace.Propagate(err, "Failed to pull image %s", imageName) } - logrus.Infof("It didn't error for '%v'", imageName) defer out.Close() - _, err = io.Copy(ioutil.Discard, out) + buf := new(strings.Builder) + _, err = io.Copy(buf, out) + logrus.Infof("It didn't error for '%v' and had output '%v'", imageName, out) if err != nil { return stacktrace.Propagate(err, "An error occurred discarding the output") } From 69a3331b9c24640b1de6eaaf704c50b427af79f8 Mon Sep 17 00:00:00 2001 From: Gyanendra Mishra Date: Tue, 4 Jul 2023 14:37:55 +0100 Subject: [PATCH 06/12] lets go --- .../lib/backend_impls/docker/docker_manager/docker_manager.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go b/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go index d6d6cbbb8c..a3d169300a 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go @@ -1022,7 +1022,7 @@ func (manager *DockerManager) PullImage(context context.Context, imageName strin defer out.Close() buf := new(strings.Builder) _, err = io.Copy(buf, out) - logrus.Infof("It didn't error for '%v' and had output '%v'", imageName, out) + logrus.Infof("It didn't error for '%v' and had output '%s'", imageName, out) if err != nil { return stacktrace.Propagate(err, "An error occurred discarding the output") } From 55e08bde42ce37d9ca74706a4cef93f149ff1115 Mon Sep 17 00:00:00 2001 From: Gyanendra Mishra Date: Tue, 4 Jul 2023 16:25:18 +0100 Subject: [PATCH 07/12] this looks good to me --- .../docker/docker_manager/docker_manager.go | 81 +++++++++---------- .../types/image_pull_response.go | 18 +++++ 2 files changed, 56 insertions(+), 43 deletions(-) create mode 100644 container-engine-lib/lib/backend_impls/docker/docker_manager/types/image_pull_response.go diff --git a/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go b/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go index a3d169300a..fa3bbb9b3a 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go @@ -7,6 +7,7 @@ package docker_manager import ( "context" + "encoding/json" "fmt" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" @@ -14,6 +15,7 @@ import ( "github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/volume" "github.com/docker/docker/client" + "github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/pkg/stdcopy" "github.com/docker/go-connections/nat" "github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/consts" @@ -22,10 +24,8 @@ import ( "github.com/kurtosis-tech/stacktrace" "github.com/sirupsen/logrus" "io" - "io/ioutil" "math" "net" - "runtime" "strings" "time" ) @@ -116,8 +116,9 @@ const ( isDockerNetworkAttachable = true - linuxAmd64 = "linux/amd64" - arm64 = "arm64" + linuxAmd64 = "linux/amd64" + defaultPlatform = "" + architectureErrorString = "no matching manifest for linux/arm64/v8" ) /* @@ -1004,27 +1005,17 @@ func (manager *DockerManager) FetchImage(ctx context.Context, dockerImage string func (manager *DockerManager) PullImage(context context.Context, imageName string) (err error) { logrus.Infof("Pulling image '%s'...", imageName) - out, err := manager.dockerClient.ImagePull(context, imageName, types.ImagePullOptions{ - All: false, - RegistryAuth: "", - PrivilegeFunc: nil, - Platform: "", - }) - if err != nil { - // if we are on ARM we try pulling the amd64 image as backup - if runtime.GOARCH == arm64 { - if err = manager.pullLinuxAmd64Image(context, imageName); err != nil { - return stacktrace.Propagate(err, "Had failed to pull image '%v' so tried pulling '%v' version of the image but that failed as well", imageName, linuxAmd64) - } - } - return stacktrace.Propagate(err, "Failed to pull image %s", imageName) + err, retryWithLinuxAmd64 := pullImage(context, manager.dockerClient, imageName, defaultPlatform) + if err == nil { + return nil } - defer out.Close() - buf := new(strings.Builder) - _, err = io.Copy(buf, out) - logrus.Infof("It didn't error for '%v' and had output '%s'", imageName, out) + if err != nil && !retryWithLinuxAmd64 { + return stacktrace.Propagate(err, "Tried pulling image '%v' but failed", imageName) + } + // we retry with linux/amd64 + err, _ = pullImage(context, manager.dockerClient, imageName, linuxAmd64) if err != nil { - return stacktrace.Propagate(err, "An error occurred discarding the output") + return stacktrace.Propagate(err, "Had previously failed with a manifest error so tried pulling image '%v' for platform '%v' but failed", imageName, linuxAmd64) } return nil } @@ -1400,26 +1391,6 @@ func (manager *DockerManager) killContainerWithRetriesWhenErrorResponseFromDeamo return stacktrace.Propagate(err, "An error occurred killing container with ID '%v'", containerId) } -// pullLinuxAmd64Image This function is a fallback incase we aren't able to pull an amd64 image for M1/M2s -func (manager *DockerManager) pullLinuxAmd64Image(context context.Context, imageName string) (err error) { - logrus.Infof("Pulling backup linux amd64 image '%s'...", imageName) - out, err := manager.dockerClient.ImagePull(context, imageName, types.ImagePullOptions{ - All: false, - RegistryAuth: "", - PrivilegeFunc: nil, - Platform: linuxAmd64, - }) - if err != nil { - return stacktrace.Propagate(err, "Failed to pull image %s", imageName) - } - defer out.Close() - _, err = io.Copy(ioutil.Discard, out) - if err != nil { - return stacktrace.Propagate(err, "An error occurred discarding the output") - } - return nil -} - // Takes in a PortMap (as reported by Docker container inspect) and returns a map of the used ports -> host port binding on the expected interface // If no bindings for the interface are found, len(output) < len(input) func getHostPortBindingsOnExpectedInterface(hostPortBindingsOnAllInterfaces nat.PortMap) map[nat.Port]*nat.PortBinding { @@ -1707,3 +1678,27 @@ func getEndpointSettingsForIpAddress(ipAddress string, alias string) *network.En return config } + +func pullImage(ctx context.Context, dockerClient *client.Client, imageName string, platform string) (error, bool) { + out, err := dockerClient.ImagePull(ctx, imageName, types.ImagePullOptions{ + All: false, + RegistryAuth: "", + PrivilegeFunc: nil, + Platform: platform, + }) + if err != nil { + return stacktrace.Propagate(err, "Tried pulling image '%v' with platform '%v' but failed", imageName, platform), false + } + defer out.Close() + responseDecoder := json.NewDecoder(out) + var jsonMessage *jsonmessage.JSONMessage + for { + if err = responseDecoder.Decode(&jsonMessage); err != nil { + if err == io.EOF { + break + } + return stacktrace.Propagate(err, "ImagePull failed with the following error '%v'", jsonMessage.Error.Message), strings.HasPrefix(jsonMessage.Error.Message, architectureErrorString) + } + } + return nil, false +} diff --git a/container-engine-lib/lib/backend_impls/docker/docker_manager/types/image_pull_response.go b/container-engine-lib/lib/backend_impls/docker/docker_manager/types/image_pull_response.go new file mode 100644 index 0000000000..642f5c0b1d --- /dev/null +++ b/container-engine-lib/lib/backend_impls/docker/docker_manager/types/image_pull_response.go @@ -0,0 +1,18 @@ +package types + +import "strings" + +const ( + m1ErrorString = "no matching manifest for linux/arm64/v8" +) + +type ImagePullResponse struct { + Error string `json:"error"` +} + +func (resp *ImagePullResponse) IsArchitectureError() bool { + if resp.Error == "" { + return false + } + return strings.HasPrefix(resp.Error, m1ErrorString) +} From 7b9acd252b8bbaa31f1f82a05a65c3b675c2026e Mon Sep 17 00:00:00 2001 From: Gyanendra Mishra Date: Tue, 4 Jul 2023 16:25:30 +0100 Subject: [PATCH 08/12] removed unused class --- .../types/image_pull_response.go | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 container-engine-lib/lib/backend_impls/docker/docker_manager/types/image_pull_response.go diff --git a/container-engine-lib/lib/backend_impls/docker/docker_manager/types/image_pull_response.go b/container-engine-lib/lib/backend_impls/docker/docker_manager/types/image_pull_response.go deleted file mode 100644 index 642f5c0b1d..0000000000 --- a/container-engine-lib/lib/backend_impls/docker/docker_manager/types/image_pull_response.go +++ /dev/null @@ -1,18 +0,0 @@ -package types - -import "strings" - -const ( - m1ErrorString = "no matching manifest for linux/arm64/v8" -) - -type ImagePullResponse struct { - Error string `json:"error"` -} - -func (resp *ImagePullResponse) IsArchitectureError() bool { - if resp.Error == "" { - return false - } - return strings.HasPrefix(resp.Error, m1ErrorString) -} From b31eabb4723ff62e4897afd61a0131b37a0730f6 Mon Sep 17 00:00:00 2001 From: Gyanendra Mishra Date: Tue, 4 Jul 2023 16:32:34 +0100 Subject: [PATCH 09/12] cleanup --- cli/cli/go.mod | 5 ++++- cli/cli/go.sum | 10 ++++++++++ container-engine-lib/go.mod | 1 + container-engine-lib/go.sum | 2 ++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cli/cli/go.mod b/cli/cli/go.mod index e8ef3660a7..084715500a 100644 --- a/cli/cli/go.mod +++ b/cli/cli/go.mod @@ -31,7 +31,7 @@ require ( github.com/spf13/cobra v1.6.1-0.20230225213037-567ea8ebc9b4 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.8.1 - golang.org/x/crypto v0.7.0 + golang.org/x/crypto v0.7.0 // indirect google.golang.org/grpc v1.41.0 google.golang.org/protobuf v1.29.1 k8s.io/apimachinery v0.27.2 @@ -53,6 +53,7 @@ require ( ) require ( + github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect github.com/Microsoft/go-winio v0.4.17 // indirect github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect @@ -86,8 +87,10 @@ require ( github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-colorable v0.1.9 // indirect github.com/moby/spdystream v0.2.0 // indirect + github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/morikuni/aec v1.0.0 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/nwaples/rardecode v1.1.3 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect diff --git a/cli/cli/go.sum b/cli/cli/go.sum index e57ae75a83..154a9d5f2d 100644 --- a/cli/cli/go.sum +++ b/cli/cli/go.sum @@ -7,7 +7,9 @@ dmitri.shuralyov.com/html/belt v0.0.0-20180602232347-f7d459c86be0/go.mod h1:JLBr dmitri.shuralyov.com/service/change v0.0.0-20181023043359-a85b471d5412/go.mod h1:a1inKt/atXimZ4Mv927x+r7UpyzRUf4emIoiiSC2TN4= dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D6DFvNNtx+9ybjezNCa8XF0xaYcETyp6rHWU= git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg= +github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0= +github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc= github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= @@ -50,6 +52,8 @@ github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWH github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/creack/pty v1.1.11 h1:07n33Z8lZxZ2qwegKbObQohDhXDQxiMMz1NOUGYlesw= +github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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= @@ -230,6 +234,7 @@ github.com/microcosm-cc/bluemonday v1.0.1/go.mod h1:hsXNsILzKxV+sX77C5b8FSuKF00v github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8= github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c= github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae h1:O4SWKdcHVCvYqyDV+9CJA1fcDN2L11Bule0iFy3YlAI= +github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae/go.mod h1:E2VnQOmVuvZB6UYnnDB0qG5Nq/1tD9acaOpo6xmt0Kw= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -237,6 +242,7 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= +github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo= @@ -307,6 +313,7 @@ github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d/go.mod h1:Udh github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod h1:HuIsMU8RRBOtsCgI77wP899iHVBQpCmg4ErYMZB+2IA= github.com/spf13/cobra v1.6.1-0.20230225213037-567ea8ebc9b4 h1:Lz7CkhugL9Vx4mZwiEYS0VmG3z/g07fQf0oNkIvoSRk= github.com/spf13/cobra v1.6.1-0.20230225213037-567ea8ebc9b4/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8= @@ -445,6 +452,7 @@ golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -473,6 +481,7 @@ golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= @@ -554,6 +563,7 @@ gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk= gotest.tools/v3 v3.3.0 h1:MfDY1b1/0xN1CyMlQDac0ziEy9zJQd9CXBRRDHw2jJo= grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o= honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/container-engine-lib/go.mod b/container-engine-lib/go.mod index 8ce7dca911..8d8151069f 100644 --- a/container-engine-lib/go.mod +++ b/container-engine-lib/go.mod @@ -12,6 +12,7 @@ require ( github.com/sirupsen/logrus v1.8.1 github.com/stretchr/testify v1.8.1 go.etcd.io/bbolt v1.3.6 + golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 golang.org/x/sync v0.1.0 gopkg.in/yaml.v3 v3.0.1 k8s.io/api v0.27.2 diff --git a/container-engine-lib/go.sum b/container-engine-lib/go.sum index 968431b7a2..666b928f73 100644 --- a/container-engine-lib/go.sum +++ b/container-engine-lib/go.sum @@ -9,6 +9,7 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPd github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/creack/pty v1.1.11 h1:07n33Z8lZxZ2qwegKbObQohDhXDQxiMMz1NOUGYlesw= github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -150,6 +151,7 @@ go.etcd.io/bbolt v1.3.6 h1:/ecaJf0sk1l4l6V4awd65v2C3ILy7MSj+s/x1ADCIMU= go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= From 1aa40b7dd75e68f45d378cd2c836df1fb4337053 Mon Sep 17 00:00:00 2001 From: Gyanendra Mishra Date: Tue, 4 Jul 2023 17:26:35 +0100 Subject: [PATCH 10/12] cleaned up and added a unit test --- .../docker/docker_manager/docker_manager.go | 5 ++++- .../docker_manager/docker_manager_test.go | 22 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go b/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go index fa3bbb9b3a..4b219c5238 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager.go @@ -1697,8 +1697,11 @@ func pullImage(ctx context.Context, dockerClient *client.Client, imageName strin if err == io.EOF { break } - return stacktrace.Propagate(err, "ImagePull failed with the following error '%v'", jsonMessage.Error.Message), strings.HasPrefix(jsonMessage.Error.Message, architectureErrorString) } + if jsonMessage.Error == nil { + continue + } + return stacktrace.NewError("ImagePull failed with the following error '%v'", jsonMessage.Error.Message), strings.HasPrefix(jsonMessage.Error.Message, architectureErrorString) } return nil, false } diff --git a/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager_test.go b/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager_test.go index 75e8bc7750..4c366a01c0 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager_test.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager_test.go @@ -1,15 +1,19 @@ package docker_manager import ( + "context" "github.com/docker/docker/api/types" + "github.com/docker/docker/client" "github.com/docker/go-connections/nat" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "runtime" "testing" ) const ( - labelSearchFilterKey = "label" + labelSearchFilterKey = "label" + testImageNotAvailableOnArm64 = "ethpandaops/ethereum-genesis-generator:1.2.6" ) func TestGetLabelsFilterList(t *testing.T) { @@ -141,3 +145,19 @@ func TestCorrectSelectionWhenTwoOfSameIPs(t *testing.T) { require.Equal(t, "127.0.0.1", publicBinding2.HostIP) require.Equal(t, "9711", publicBinding2.HostPort) } + +func TestPullImageWithRetries(t *testing.T) { + if runtime.GOARCH != "arm64" { + t.Skip("Skipping the test as this is not running on arm64") + } + dockerClient, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) + require.NoError(t, err) + require.NotNil(t, dockerClient) + ctx := context.Background() + err, retry := pullImage(ctx, dockerClient, testImageNotAvailableOnArm64, defaultPlatform) + require.Error(t, err) + require.True(t, retry) + err, retry = pullImage(ctx, dockerClient, testImageNotAvailableOnArm64, linuxAmd64) + require.NoError(t, err) + require.False(t, retry) +} From d79ffac3af9df82691ec4a6e42a3cbc4e0eaaccc Mon Sep 17 00:00:00 2001 From: Gyanendra Mishra Date: Tue, 4 Jul 2023 17:34:52 +0100 Subject: [PATCH 11/12] added a better skip for test --- .../backend_impls/docker/docker_manager/docker_manager_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager_test.go b/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager_test.go index 4c366a01c0..34c8923adb 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager_test.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager_test.go @@ -14,6 +14,7 @@ import ( const ( labelSearchFilterKey = "label" testImageNotAvailableOnArm64 = "ethpandaops/ethereum-genesis-generator:1.2.6" + arm64ArchitectureString = "arm64" ) func TestGetLabelsFilterList(t *testing.T) { @@ -147,7 +148,7 @@ func TestCorrectSelectionWhenTwoOfSameIPs(t *testing.T) { } func TestPullImageWithRetries(t *testing.T) { - if runtime.GOARCH != "arm64" { + if runtime.GOARCH != arm64ArchitectureString { t.Skip("Skipping the test as this is not running on arm64") } dockerClient, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) From 7386518747ffb7ac34bb1a8c5ee3aca699e47d96 Mon Sep 17 00:00:00 2001 From: Gyanendra Mishra Date: Tue, 4 Jul 2023 17:47:40 +0100 Subject: [PATCH 12/12] using a tinier image --- .../docker/docker_manager/docker_manager_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager_test.go b/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager_test.go index 34c8923adb..8a34021676 100644 --- a/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager_test.go +++ b/container-engine-lib/lib/backend_impls/docker/docker_manager/docker_manager_test.go @@ -12,9 +12,9 @@ import ( ) const ( - labelSearchFilterKey = "label" - testImageNotAvailableOnArm64 = "ethpandaops/ethereum-genesis-generator:1.2.6" - arm64ArchitectureString = "arm64" + labelSearchFilterKey = "label" + tinyTestImageNotAvailableOnArm64 = "clearlinux:base" + arm64ArchitectureString = "arm64" ) func TestGetLabelsFilterList(t *testing.T) { @@ -155,10 +155,10 @@ func TestPullImageWithRetries(t *testing.T) { require.NoError(t, err) require.NotNil(t, dockerClient) ctx := context.Background() - err, retry := pullImage(ctx, dockerClient, testImageNotAvailableOnArm64, defaultPlatform) + err, retry := pullImage(ctx, dockerClient, tinyTestImageNotAvailableOnArm64, defaultPlatform) require.Error(t, err) require.True(t, retry) - err, retry = pullImage(ctx, dockerClient, testImageNotAvailableOnArm64, linuxAmd64) + err, retry = pullImage(ctx, dockerClient, tinyTestImageNotAvailableOnArm64, linuxAmd64) require.NoError(t, err) require.False(t, retry) }