Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: deduplicate tags #884

Merged
merged 1 commit into from
Nov 9, 2022
Merged

Conversation

bluebrown
Copy link
Contributor

Signed-off-by: Nico Braun rainbowstack@gmail.com

resolve: #883

@google-cla
Copy link

google-cla bot commented Nov 8, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@bluebrown
Copy link
Contributor Author

I decided to move the logic to this place so that, it applies to all publishers.

I wanted to add some tests as well, but I didn't find a good way. This is because the publisher interface doesn't expose a way to get the tags. So it's hard to write a test to compare input and output tags.

@imjasonh
Copy link
Member

imjasonh commented Nov 8, 2022

(This isn't commentary on the PR exactly, just research notes I thought it would be useful to share)

The only place we care about the order of the tags is here:

ko/pkg/commands/resolver.go

Lines 241 to 246 in 140ac87

if len(publishers) == 0 {
// If one or more tags are specified, use the first tag in the list
var tag string
if len(po.Tags) >= 1 {
tag = po.Tags[0]
}

This is pretty esoteric. This happens if you're not publishing, but specify multiple tags. This might happen if you do:

ko build --tarball=foo.tar --push=false --tags=foo --tags=bar

In that case the tarball should have the foo tag applied consistently, and not bar.

While looking into this, I also found and fixed #885 which was just kinda weird.

imjasonh
imjasonh previously approved these changes Nov 8, 2022
Copy link
Member

@imjasonh imjasonh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change LGTM, just needs a CLA before we can merge it.

@bluebrown
Copy link
Contributor Author

I have accepted the CLA, and did the rescan :)


// create a set from the input slice
// preserving the order of unique elements
func unique[T comparable](tt []T) []T {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ehh, I don't know if we need to bother with generics here, since we know we'll only call it with strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I had it only for strings before, but then I thought it may be useful for other stuff too. You mentioned platform, for example. Maybe that's also a string, not sure. I can change it, if you want, though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'd prefer to have it work on strings until/unless we find a generic use for it in the future. YAGNI and all.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok done. I did a force push. Not sure how this is done here, but I know some project not doing squash merge and thefore prefer a single commit.

Signed-off-by: Nico Braun <rainbowstack@gmail.com>
@imjasonh imjasonh merged commit 5f75bcf into ko-build:main Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deduplicate tags
2 participants