1
0
mirror of https://github.com/ko-build/ko.git synced 2025-02-07 19:30:23 +02:00

Have kind.local test use --platform=all (#208)

Fix --platform=all with kind.local
This commit is contained in:
Matt Moore 2020-09-29 10:11:15 -07:00 committed by GitHub
parent 0f5a478d75
commit 61fbde832a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 3 deletions

View File

@ -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."

View File

@ -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)
}