Skip to content

build: set kube version via debug.BuildInfo - #13180

Closed
branchv wants to merge 2 commits into
helm:mainfrom
branchv:buildinfo
Closed

branchv wants to merge 2 commits into
helm:mainfrom
branchv:buildinfo

Conversation

@branchv

@branchv branchv commented Jul 16, 2024

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

This is inspired by #13174, where Homebrew built helm outside of the Makefile and accidentally did not set the correct ldflags for the k8sVersion variables (which were defaulted to 1.20 instead of 1.30)

Instead, this uses runtime/debug's ReadBuildInfo to automatically extract the correct k8s.io/client-go version, regardless if the Makefile was used (for example, using go install helm.sh/helm/v3/cmd/helm@latest). It also adds a similar fallback for the git metadata ldflags using 1.18's BuildSetting (but respects the variables if they are already set):

$ go build ./cmd/helm && ./helm version
version.BuildInfo{Version:"v3.15", GitCommit:"7af094d606aff055c1eb938775b6fd260e637158", GitTreeState:"clean", GoVersion:"go1.22.5"}

Special notes for your reviewer:

This does introduce a lot of test golden changes since tests now also run with the correct k8s.io/client-go version

If applicable:

  • this PR contains documentation
  • this PR contains unit tests
  • this PR has been tested for backwards compatibility

@pull-request-size pull-request-size Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 16, 2024
@robertsirc

Copy link
Copy Markdown
Member

This PR is a bit in depth could you attend the developer call on Thursdays at 9:30-10:00 Pacific (meeting details)??

@gjenkins8 gjenkins8 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the PR. I do think this is a worthy change. TIL about https://pkg.go.dev/runtime/debug#ReadBuildInfo . Removing these ldflags and Makefile logic from Helm's certainly seems an improvement.

And in particular, Helm is often used as an SDK. And SDK users (presumably) find out the hard way they need to set these ldflags in their build system.

The only concerns I can think of are a) accuracy. I assume debug.ReadBuildInfo() can be accurate here. But probably just need to do some diligence to confirm, and b) performance. As long as reading this info does have some significant latency (I can't imagine it does), I can't imagine Helm wouldn't want to read this info at runtime.

@gjenkins8 gjenkins8 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Git commit changes I think need more thought. If we move them to a seperate PR, can approve the Kubernetes client-go version changes

Comment thread pkg/chartutil/capabilities.go Resolved
if !ok {
return nil, false
}
for _, m := range info.Deps {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could perhaps write this now with slices.IndexFunc ?

return vs
}

func k8sClientVersion() (*semver.Version, bool) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: kubernetesClientGoModVersion might be a more accurate name for this function?

This comment is partly inspired by the below v.Major()+1, where client-go uses zero-based major version for some reason I forget. So thought the name should be very clear to what is being determined.

Comment thread internal/version/version.go Resolved
@github-actions

Copy link
Copy Markdown

This pull request has been marked as stale because it has been open for 90 days with no activity. This pull request will be automatically closed in 30 days if no further activity occurs.

@gjenkins8

Copy link
Copy Markdown
Member

Note: I copied and reworked this PR into: #31296 (which has some differences in implementation, which I think are worthwhile). Also to move this forward and simplify Helm's build.

@branchv

branchv commented Sep 26, 2025

Copy link
Copy Markdown
Contributor Author

Thanks for pushing this forward @gjenkins8

@branchv branchv closed this Sep 26, 2025
@branchv
branchv deleted the buildinfo branch September 26, 2025 19:58
@TerryHowe

Copy link
Copy Markdown
Contributor

Whoops closed

@branchv

branchv commented Sep 27, 2025

Copy link
Copy Markdown
Contributor Author

Yes this was superseded by #31296

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

4 participants