Skip to content

Commit

Permalink
nit: replace one-item slice with const (ko-build#885)
Browse files Browse the repository at this point in the history
  • Loading branch information
imjasonh authored Nov 9, 2022
1 parent d6db71d commit 32f68f3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions pkg/publish/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ func identity(base, in string) string { return path.Join(base, in) }

// As some registries do not support pushing an image by digest, the default tag for pushing
// is the 'latest' tag.
var defaultTags = []string{"latest"}
const latestTag = "latest"

func (do *defaultOpener) Open() (Interface, error) {
if do.tagOnly {
if len(do.tags) != 1 {
return nil, errors.New("must specify exactly one tag to resolve images into tag-only references")
}
if do.tags[0] == defaultTags[0] {
if do.tags[0] == latestTag {
return nil, errors.New("latest tag cannot be used in tag-only references")
}
}
Expand All @@ -107,7 +107,7 @@ func NewDefault(base string, options ...Option) (Interface, error) {
userAgent: "ko",
keychain: authn.DefaultKeychain,
namer: identity,
tags: defaultTags,
tags: []string{latestTag},
}

for _, option := range options {
Expand Down Expand Up @@ -244,7 +244,7 @@ func (d *defalt) Publish(ctx context.Context, br build.Result, s string) (name.R
return nil, err
}
ref := fmt.Sprintf("%s@%s", d.namer(d.base, s), h)
if len(d.tags) == 1 && d.tags[0] != defaultTags[0] {
if len(d.tags) == 1 && d.tags[0] != latestTag {
// If a single tag is explicitly set (not latest), then this
// is probably a release, so include the tag in the reference.
ref = fmt.Sprintf("%s:%s@%s", d.namer(d.base, s), d.tags[0], h)
Expand Down
2 changes: 1 addition & 1 deletion pkg/publish/tarball.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (t *tar) Publish(_ context.Context, br build.Result, s string) (name.Refere
}

ref := fmt.Sprintf("%s@%s", t.namer(t.base, s), h)
if len(t.tags) == 1 && t.tags[0] != defaultTags[0] {
if len(t.tags) == 1 && t.tags[0] != latestTag {
// If a single tag is explicitly set (not latest), then this
// is probably a release, so include the tag in the reference.
ref = fmt.Sprintf("%s:%s@%s", t.namer(t.base, s), t.tags[0], h)
Expand Down

0 comments on commit 32f68f3

Please sign in to comment.