From 8033e5a051d9cb30d2f79e4f4e1a55d409c4a6c8 Mon Sep 17 00:00:00 2001 From: Halvard Skogsrud Date: Fri, 12 Nov 2021 01:02:22 +1100 Subject: [PATCH] fix(ko): Display correct tag Display the expected tag after successfully building a ko image, for both sideloaded and published images. Also handles the `tagPolicy.sha256` scenarios. Fixes: #6835 Tracking: #6041 --- integration/ko_test.go | 3 ++- pkg/skaffold/build/ko/build.go | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/integration/ko_test.go b/integration/ko_test.go index a35b6a454ee..d48d935bbd0 100644 --- a/integration/ko_test.go +++ b/integration/ko_test.go @@ -70,7 +70,8 @@ func TestBuildAndPushKoImageProgrammatically(t *testing.T) { Workspace: exampleAppDir, } imageName := fmt.Sprintf("%s/%s", registryAddr, "skaffold-ko") - digest, err := b.Build(context.Background(), &imageFullNameBuffer, artifact, imageName) + imageNameWithTag := fmt.Sprintf("%s:%s", imageName, "latest") + digest, err := b.Build(context.Background(), &imageFullNameBuffer, artifact, imageNameWithTag) if err != nil { t.Fatalf("b.Build(): %+v", err) } diff --git a/pkg/skaffold/build/ko/build.go b/pkg/skaffold/build/ko/build.go index 7d826d9254f..0ba062347bf 100644 --- a/pkg/skaffold/build/ko/build.go +++ b/pkg/skaffold/build/ko/build.go @@ -52,7 +52,13 @@ func (b *Builder) Build(ctx context.Context, out io.Writer, a *latestV1.Artifact if err != nil { return "", fmt.Errorf("could not build and publish ko image %q: %w", a.ImageName, err) } - fmt.Fprintln(out, imageRef.Name()) + + outputRef := ref + if strings.HasSuffix(ref, ":latest") { + // handle tagPolicy sha256 + outputRef = imageRef.Name() + } + fmt.Fprintln(out, outputRef) return b.getImageIdentifier(ctx, imageRef, ref) }