From 61fbde832a7e6155115a54f1cddd3887697bd914 Mon Sep 17 00:00:00 2001 From: Matt Moore Date: Tue, 29 Sep 2020 10:11:15 -0700 Subject: [PATCH] Have kind.local test use --platform=all (#208) Fix --platform=all with kind.local --- integration_test.sh | 2 +- pkg/publish/kind.go | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/integration_test.sh b/integration_test.sh index b86a6422b3..a3e1312b51 100755 --- a/integration_test.sh +++ b/integration_test.sh @@ -12,7 +12,7 @@ ROOT_DIR="$(pwd)" echo "Running smoke test." go install ./cmd/ko # Travis runs this against a kind cluster so properly use the kind publisher. -KO_DOCKER_REPO=kind.local ko apply -f ./cmd/ko/test +KO_DOCKER_REPO=kind.local ko apply --platform=all -f ./cmd/ko/test kubectl wait --timeout=10s --for=condition=Ready pod/kodata echo "Moving GOPATH into /tmp/ to test modules behavior." diff --git a/pkg/publish/kind.go b/pkg/publish/kind.go index ce2bf8472b..21f9b9764c 100644 --- a/pkg/publish/kind.go +++ b/pkg/publish/kind.go @@ -17,6 +17,7 @@ package publish import ( "fmt" "log" + "os" "strings" "github.com/google/go-containerregistry/pkg/name" @@ -50,8 +51,42 @@ func (t *kindPublisher) Publish(br build.Result, s string) (name.Reference, erro s = strings.ToLower(s) // There's no way to write an index to a kind, so attempt to downcast it to an image. - img, ok := br.(v1.Image) - if !ok { + var img v1.Image + switch i := br.(type) { + case v1.Image: + img = i + case v1.ImageIndex: + im, err := i.IndexManifest() + if err != nil { + return nil, err + } + goos, goarch := os.Getenv("GOOS"), os.Getenv("GOARCH") + if goos == "" { + goos = "linux" + } + if goarch == "" { + goarch = "amd64" + } + for _, manifest := range im.Manifests { + if manifest.Platform == nil { + continue + } + if manifest.Platform.OS != goos { + continue + } + if manifest.Platform.Architecture != goarch { + continue + } + img, err = i.Image(manifest.Digest) + if err != nil { + return nil, err + } + break + } + if img == nil { + return nil, fmt.Errorf("failed to find %s/%s image in index for image: %v", goos, goarch, s) + } + default: return nil, fmt.Errorf("failed to interpret %s result as image: %v", s, br) }