From 7774527b5e20db12b51428f5e03a5d33798ad7b5 Mon Sep 17 00:00:00 2001 From: Adrian Lai Date: Thu, 27 Apr 2023 11:53:50 +0100 Subject: [PATCH] Fix kind image names with --bare Make the functionality match between: KO_DOCKER_REPO=ko.local/my-image ko build --bare And: KO_DOCKER_REPO=kind.local/my-image ko build --bare As it stands, `--bare` is broken with `kind.local/` as it just gets `kind.local` as the image name, and then it fails to tag because the registry is missing. --- pkg/commands/resolver.go | 2 +- pkg/publish/kind.go | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/commands/resolver.go b/pkg/commands/resolver.go index 966ba37dd2..ea48dad953 100644 --- a/pkg/commands/resolver.go +++ b/pkg/commands/resolver.go @@ -199,7 +199,7 @@ func makePublisher(po *options.PublishOptions) (publish.Interface, error) { ) } if strings.HasPrefix(repoName, publish.KindDomain) { - return publish.NewKindPublisher(namer, po.Tags), nil + return publish.NewKindPublisher(repoName, namer, po.Tags), nil } if repoName == "" && po.Push { diff --git a/pkg/publish/kind.go b/pkg/publish/kind.go index f20303cbf7..bcf1a1df14 100644 --- a/pkg/publish/kind.go +++ b/pkg/publish/kind.go @@ -33,13 +33,15 @@ const ( ) type kindPublisher struct { + base string namer Namer tags []string } // NewKindPublisher returns a new publish.Interface that loads images into kind nodes. -func NewKindPublisher(namer Namer, tags []string) Interface { +func NewKindPublisher(base string, namer Namer, tags []string) Interface { return &kindPublisher{ + base: base, namer: namer, tags: tags, } @@ -96,7 +98,7 @@ func (t *kindPublisher) Publish(ctx context.Context, br build.Result, s string) return nil, err } - digestTag, err := name.NewTag(fmt.Sprintf("%s:%s", t.namer(KindDomain, s), h.Hex)) + digestTag, err := name.NewTag(fmt.Sprintf("%s:%s", t.namer(t.base, s), h.Hex)) if err != nil { return nil, err } @@ -109,7 +111,7 @@ func (t *kindPublisher) Publish(ctx context.Context, br build.Result, s string) for _, tagName := range t.tags { log.Printf("Adding tag %v", tagName) - tag, err := name.NewTag(fmt.Sprintf("%s:%s", t.namer(KindDomain, s), tagName)) + tag, err := name.NewTag(fmt.Sprintf("%s:%s", t.namer(t.base, s), tagName)) if err != nil { return nil, err }