Skip to content

Commit

Permalink
Have kind.local test use --platform=all (#208)
Browse files Browse the repository at this point in the history
Fix --platform=all with kind.local
  • Loading branch information
mattmoor authored Sep 29, 2020
1 parent 0f5a478 commit 61fbde8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
39 changes: 37 additions & 2 deletions pkg/publish/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package publish
import (
"fmt"
"log"
"os"
"strings"

"github.com/google/go-containerregistry/pkg/name"
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 61fbde8

Please sign in to comment.