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

internal/version: Adopt Go 1.18+ implementation #10646

Merged

Conversation

timflannagan
Copy link
Member

@timflannagan timflannagan commented Feb 17, 2025

Description

This PR overhauls the pkg/version library:

  • Removes several files that are cruft (e.g. enterprise, federation, etc.)
  • Moves the package from pkg/ -> internal/
  • Refactors the version package to be based on the Go 1.18+ version approach via runtime.ReadBuildInfo()
  • Add the --version CLI flag to the controller binary to decorate the version.Version build flag with VCS metadata

See the Go 1.18 release notes for more information.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

- Required to populate VCS metadata in runtime.ReadBuildInfo calls correctly

Signed-off-by: timflannagan <[email protected]>
@@ -29,6 +28,7 @@ require (
github.com/solo-io/go-list-licenses v0.1.4
github.com/solo-io/go-utils v0.27.3
github.com/spf13/afero v1.11.0
github.com/spf13/cobra v1.8.1
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm typically hesitant introducing new direct dependencies, but in this case cobra is pretty standard and I wasn't able to get to refactoring the CLI packages when we were pushing through the deflate/cleanup repository stream of work at the time.

Copy link
Contributor

Choose a reason for hiding this comment

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

not opposed, but cobra here for a single binary startup (i.e. not a CLI) does seem a bit excessive.

also, we have the Settings replacement plumbed via env vars, if we are going cobra maybe we should reevaluate Viper for the env var config?

no real blocker here, just thinking out loud

Copy link
Member Author

Choose a reason for hiding this comment

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

Talked with Yuval about this offline: I was planning on refactoring the SDS/envoyinit cmd packages to use cobra to be consistent with the kgateway package as a follow-up when I have some downtime. In this case, we'd pipe configuration to our internal packages via cobra flags and expose knobs in the helm chart for higher-level config.

Copy link
Member Author

Choose a reason for hiding this comment

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

@lgadban Glossed over your "not a CLI" comment. IMHO, all these binaries should be CLI-based with the sole responsibility that they 1.) provide flags/configuration to libraries, 2.) call that libaries' constructor and delegate to that library to do the heavy lifting, and 3.) handle any I/O that doesn't make sense in the context of the library being utilized.

@timflannagan timflannagan mentioned this pull request Feb 18, 2025
4 tasks
@yuval-k
Copy link
Contributor

yuval-k commented Feb 18, 2025

just tried it:

❯ ./_output/internal/kgateway/kgateway-linux-amd64 --version
controller version 1.0.1-dev, commit 8f82c9e3e37452bd4aacf70398251d76f330e374, built at 2025-02-17T23:20:27Z

looks good!

@timflannagan
Copy link
Member Author

@yuval-k Perfect. Last I checked the controller will only log the version.Version variable, but we can adjust that the entire version.String() (which includes the VCS metadata) is logged too.

@timflannagan timflannagan changed the title pkg/version: Adopt Go 1.18+ implementation internal/version: Adopt Go 1.18+ implementation Feb 18, 2025
@lgadban
Copy link
Contributor

lgadban commented Feb 18, 2025

Refactors the version package to be based on the Go 1.18+ version approach via runtime.ReadBuildInfo()

@timflannagan can you add a ref link to the PR description for above?

@timflannagan
Copy link
Member Author

@lgadban Done, added a link to https://tip.golang.org/doc/go1.18#debug_buildinfo.

Copy link
Contributor

@lgadban lgadban left a comment

Choose a reason for hiding this comment

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

very nice, just a quick discussion point

@@ -29,6 +28,7 @@ require (
github.com/solo-io/go-list-licenses v0.1.4
github.com/solo-io/go-utils v0.27.3
github.com/spf13/afero v1.11.0
github.com/spf13/cobra v1.8.1
Copy link
Contributor

Choose a reason for hiding this comment

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

not opposed, but cobra here for a single binary startup (i.e. not a CLI) does seem a bit excessive.

also, we have the Settings replacement plumbed via env vars, if we are going cobra maybe we should reevaluate Viper for the env var config?

no real blocker here, just thinking out loud

@timflannagan timflannagan added this pull request to the merge queue Feb 18, 2025
Merged via the queue into kgateway-dev:main with commit a4121ed Feb 18, 2025
9 checks passed
@timflannagan timflannagan deleted the chore/overhaul-version-package branch February 18, 2025 22:45
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.

3 participants