Skip to content

Conversation

afritzler
Copy link
Contributor

Suggested Changes

  • Introduced LOCALBIN to define local binary installation directory (./bin).
  • Added a reusable go-install-tool Make function to install Go tools with version pinning.
  • Refactored golangci-lint and go-apidiff targets to use go-install-tool.
  • Defined tool binary paths (GO_APIDIFF, GOLANGCI_LINT) and their corresponding version variables.

- Introduced `LOCALBIN` to define local binary installation directory (`./bin`).
- Added a reusable `go-install-tool` Make function to install Go tools with version pinning.
- Refactored `golangci-lint` and `go-apidiff` targets to use `go-install-tool`.
- Defined tool binary paths (`GO_APIDIFF`, `GOLANGCI_LINT`) and their corresponding version variables.
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 5, 2025
@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 5, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @afritzler. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@camilamacedo86 camilamacedo86 requested a review from Copilot August 6, 2025 07:43
@camilamacedo86
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 6, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a standardized tool installation system for Go-based development tools using Make functions. The main goal is to enable versioned tool installation with proper dependency management in the local ./bin directory.

  • Adds a reusable go-install-tool Make function for versioned Go tool installation
  • Refactors existing tool installation targets (golangci-lint, go-apidiff) to use the new system
  • Introduces proper version pinning and local binary management

# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f "$(1)-$(3)" ] || { \
Copy link

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

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

The condition checks for a versioned binary file "$(1)-$(3)" but this file may not exist on first installation. The logic should check if the symlink $(1) points to the correct versioned binary instead of relying on the existence of the versioned file.

Suggested change
@[ -f "$(1)-$(3)" ] || { \
@[ -f "$(1)-$(3)" ] && [ "$$(readlink -- "$(1)" 2>/dev/null)" = "$(1)-$(3)" ] || { \

Copilot uses AI. Check for mistakes.

Copy link
Member

Choose a reason for hiding this comment

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

We might do the AI suggestion for the Makefile end users scaffolded too.
So, I will let it be a follow-up.
Where can we change all at once
Could you work on the follow-up?
We will need to change:

# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary
# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f "$(1)-$(3)" ] || { \
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
rm -f $(1) || true ;\
GOBIN=$(LOCALBIN) go install $${package} ;\
mv $(1) $(1)-$(3) ;\
} ;\
ln -sf $(1)-$(3) $(1)
endef

And run make install AND make generate

GOBIN=$(LOCALBIN) go install $${package} ;\
mv $(1) $(1)-$(3) ;\
} ;\
ln -sf $(1)-$(3) $(1)
Copy link

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

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

The symlink creation uses a relative path which may not work correctly. The target should use an absolute path or basename to ensure the symlink points to the correct file: ln -sf $(notdir $(1)-$(3)) $(1)

Suggested change
ln -sf $(1)-$(3) $(1)
ln -sf $$(realpath $(1)-$(3)) $(1)

Copilot uses AI. Check for mistakes.

Copy link
Member

Choose a reason for hiding this comment

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

Same for

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

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

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

The || true is redundant since rm -f never fails. Consider removing it for cleaner code: rm -f $(1) ;\

Suggested change
rm -f $(1) || true ;\
rm -f $(1) ;\

Copilot uses AI. Check for mistakes.

Copy link
Member

Choose a reason for hiding this comment

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

Same for ^

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 @afritzler

Thank you for your contribution 🥇
Because this change is in the Kubebebuilder makefile, it does not impact the end users.
Therefore, the right emoji is 🌱

Why does that matter?

We use it to do the release notes. So, I will update the PR title. I hope that you do not mind.

@camilamacedo86 camilamacedo86 changed the title ✨ Add versioned tool installation via go-install-tool helper 🌱 Add versioned tool installation via go-install-tool helper in Kubebuilder Makefile such as we provide for end users Aug 6, 2025
@camilamacedo86
Copy link
Member

/approved
/lgtm

@afritzler could we please do the changes in a follow up: #4986 (comment)

Let's apply the AI suggestions for both here and end-users scaffolds.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 6, 2025
@afritzler
Copy link
Contributor Author

@camilamacedo86 thanks for your feedback! I will incorporate the suggested improvements.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

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

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 Aug 6, 2025
@k8s-ci-robot k8s-ci-robot merged commit 83e9ed7 into kubernetes-sigs:master Aug 6, 2025
16 checks passed
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/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants