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

📖 Add Go section to install clusterctl #11464

Conversation

sivchari
Copy link
Member

What this PR does / why we need it:

I added the Go section to install clusterctl via go install.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

/area documentation

@k8s-ci-robot k8s-ci-robot added area/documentation Issues or PRs related to documentation cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Nov 22, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign vincepri for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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 size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 22, 2024
@sivchari
Copy link
Member Author

Ah, sorry. Presumably, we can't embed the some versions via ldflags option if we use go install.
So, this PR might not be necessary. Or, do we need to deal with the way to use go install ?

@chrischdi
Copy link
Member

Ah, sorry. Presumably, we can't embed the some versions via ldflags option if we use go install. So, this PR might not be necessary. Or, do we need to deal with the way to use go install ?

An alternative would be to make clusterctl not fail when the ld flags have not been set. Afaik they are only used for the version subcommand (which should be okay) and as post run to check for new versions.

@sivchari
Copy link
Member Author

I think it's prefer the way you propose. So I'd open the issue to discuss about it.

Test to ensure the version you installed is up-to-date:
```bash
clusterctl version
Copy link
Member

Choose a reason for hiding this comment

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

Did this work for you?

It didn't for me:

$ go install sigs.k8s.io/cluster-api/cmd/clusterctl@latest
go: downloading sigs.k8s.io/cluster-api v1.9.3

$ ~/code/bin/clusterctl version
clusterctl version: &version.Info{Major:"", Minor:"", GitVersion:"", GitCommit:"", GitTreeState:"", BuildDate:"", GoVersion:"go1.22.1", Compiler:"gc", Platform:"darwin/arm64"}

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry for the late reply.

It didn't for me, too.

Expected

clusterctl version: &version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.3", GitCommit:"cd279dd0c24c5472db45255e3805ae16c61e1432", GitTreeState:"clean", BuildDate:"2024-12-23T13:13:07Z", GoVersion:"go1.22.10", Compiler:"gc", Platform:"darwin/arm64"}

Actual

clusterctl version: &version.Info{Major:"", Minor:"", GitVersion:"", GitCommit:"", GitTreeState:"", BuildDate:"", GoVersion:"devel go1.24-ccf4ebbb61 Wed Dec 4 04:10:56 2024 +0000", Compiler:"gc", Platform:"darwin/arm64"}

But it work when I pass the ldflags like this

go install  -ldflags "-X 'sigs.k8s.io/cluster-api/version.gitMajor=1' -X 'sigs.k8s.io/cluster-api/version.gitMinor=9'" sigs.k8s.io/cluster-api/cmd/clusterctl@latest
clusterctl version: &version.Info{Major:"1", Minor:"9", GitVersion:"", GitCommit:"", GitTreeState:"", BuildDate:"", GoVersion:"devel go1.24-ccf4ebbb61 Wed Dec 4 04:10:56 2024 +0000", Compiler:"gc", Platform:"darwin/arm64"}

Of course, I still didn't get the GitCommit etc.

Should I rewrite this section or remove it ?

Copy link
Member

@sbueringer sbueringer Jan 7, 2025

Choose a reason for hiding this comment

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

I'm wondering if there is a way to make the "simple" go install work (including the correct version). Do we know if that works with some other projects and if yes, what they do differently?

Copy link
Member

Choose a reason for hiding this comment

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

AFAIK both kubectl and kubeadm do not support installing with go install

TBH, I would prefer to not support go install vs supporting it with cryptic -ldflags or knowing it leads to wrong version

Copy link
Member

Choose a reason for hiding this comment

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

Note: with go install the debug.ReadBuildInfo() get's populated which contains a .Main.Version.

In case of go build this normally contains (devel), so its useless.

But when using go install [email protected] it contains vx.x.x.
In case of using go isntall module@CommitHash it contains e.g. v0.0.0-20250108155011-73ddd0ddd442.

Copy link
Member

Choose a reason for hiding this comment

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

But: I'd prefer to not add this to the documentation as it leads to binaries built differently and we don't have the bandwidth to support this.

@sivchari is there a strong use case over not using the pre-compiled released binaries?

We make sure that the pre-built and released binaries are built with the right go version and these binaries get tested in CI too (for linux amd64).

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @chrischdi
Thank you for good feedback. Honestly, I don't have strong use case. I usually use go install to get the binary. Thus I noticed it, but as @fabriziopandini and you said, I thought that it's better not to have various way to install clusterctl, too.
So I close this PR since I change my mind not to add this document.
Thanks all.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for clarification :-)

@sivchari sivchari closed this Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/documentation Issues or PRs related to documentation 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants