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

✨ Makefile: Create Version-Agnostic Symlinks for Specified Versioned Binaries #4013

Merged
merged 1 commit into from
Jul 12, 2024

Conversation

schrej
Copy link
Member

@schrej schrej commented Jul 11, 2024

While the new approach (we'll, new since I last used kubebuilder) finally does proper upgrades of tools, which is very nice, it makes it much harder to use the versioned tools in scripts that aren't called by the makefile, e.g. Tilt. (https://tilt.dev/)

This MR introduces symlinks to the latest version of the tools, which are updated whenever a new version is downloaded.

The Makefile also uses those symlinks to access the tools, which makes the go-install-tool function a bit simpler, getting rid of the sed replace.

Details

This change does not remove the explicit versioning, and the versioned binaries will still exists in the bin folder. There will just be an additional symlink to the version that was installed last (the symlink is only created during installation, which could be changed to support downgrades to already installed versions).
image

Use cases:

It is helpful if you write scripts that use the binaries downloaded by the makefile. You can just use e.g. bin/kustomize and there is no need to adapt it to the version currently set in the makefile, and also no need to execute the script with the makefile to pass in the binary to use.
The only relevant one probably is kustomize, but it should be the same behaviour for all of them.

Another use-case can be to point your IDE to your bin/golangci-lint binary to always use the version specified by the project.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jul 11, 2024
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jul 11, 2024
Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

Sorry, I will try to understand better your motivation here.

@camilamacedo86 camilamacedo86 dismissed their stale review July 11, 2024 18:57

ignore for now, I need to give a better look

camilamacedo86

This comment was marked as resolved.

@camilamacedo86 camilamacedo86 changed the title 🌱 makefile: create unversioned symlinks for tools ✨ makefile: create unversioned symlinks for tools Jul 12, 2024
@schrej
Copy link
Member Author

schrej commented Jul 12, 2024

The last two pushes should fix upgrades failing due to the binary file already existing (or rather the symlink to it) and it will also ensure the correct binary is used when downgrading by replacing the symlink every time.

GOBIN=$(LOCALBIN) go install $${package} ;\
mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\
Copy link
Member

@camilamacedo86 camilamacedo86 Jul 12, 2024

Choose a reason for hiding this comment

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

I like the idea of remove sed since it does not work always at the same way in linux and mac/
sed is usually problematic

Copy link
Member Author

Choose a reason for hiding this comment

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

This could also be done without the symlink stuff, in case this doesn't make it in.

Copy link
Member

@camilamacedo86 camilamacedo86 Jul 12, 2024

Choose a reason for hiding this comment

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

If you have an alternative approach that avoids using symlinks and you believe it would be more suitable, please feel free to suggest it. The use of symlinks might not be very clear for beginner users and could cause some confusion. Otherwise, I think I am ok with

set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
rm -f $(1) || true ;\
Copy link
Member

@camilamacedo86 camilamacedo86 Jul 12, 2024

Choose a reason for hiding this comment

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

What are we removing here? The symbolic link or binary?
If is the symbolic link 👍

I do not think that we should remove anything without an explicit request, OK, or demand from a user.
It is not a good practice/ux delete staff without the user knowledge.

Copy link
Member Author

Choose a reason for hiding this comment

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

The symbolic link, otherwise the go install will fail.

Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

/ok-to-test

@k8s-ci-robot k8s-ci-robot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Jul 12, 2024
Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

Hi @schrej,

Thank you for your time and collab on this one 🥇

Just one question here: https://github.com/kubernetes-sigs/kubebuilder/pull/4013/files#r1676137395

Otherwise, after the explanations I think I am OK with the changes.

Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

@schrej

I am OK with the changes proposed.
/lgtm
/approved

If you have a better approach or suggestion feel free to raise a follow up
It seems good to fly 🎉

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 12, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: camilamacedo86, schrej

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 12, 2024
@camilamacedo86 camilamacedo86 changed the title ✨ makefile: create unversioned symlinks for tools ✨ makefile: create unversioned symlinks for configurable binaries tools Jul 12, 2024
@k8s-ci-robot k8s-ci-robot merged commit 8376422 into kubernetes-sigs:master Jul 12, 2024
20 checks passed
@camilamacedo86 camilamacedo86 changed the title ✨ makefile: create unversioned symlinks for configurable binaries tools ✨ Makefile: Create Version-Agnostic Symlinks for Specified Versioned Binaries Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants