Repository navigation
fix: set k8s.io/client-go version ldflags to fix User-Agent header - #444
Conversation
|
Hi @msasadzaidi. Thanks for your PR. I'm waiting for a cert-manager member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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. |
The User-Agent header in HTTP requests to the Kubernetes API server reports 'cmctl/v0.0.0 (linux/amd64) kubernetes/$Format' instead of the actual release version. The build pipeline sets ldflags for cert-manager/pkg/util (controlling the clientVersion output) but not for k8s.io/client-go/pkg/version, which is what the Kubernetes REST client uses to construct the User-Agent header. Add -X ldflags for k8s.io/client-go/pkg/version.gitVersion and gitCommit so the User-Agent correctly reflects the release version. Fixes cert-manager#128 Co-authored-by: Copilot <[email protected]> Signed-off-by: Asad Zaidi <[email protected]>
5d9c9d8 to
742f960
Compare
There was a problem hiding this comment.
Pull request overview
Updates the cmctl build ldflags so Kubernetes client-go version metadata is embedded into the binary, fixing API request User-Agent headers that currently report v0.0.0 / $Format instead of the actual cmctl release version and git commit (per #128).
Changes:
- Extend
go_cmctl_ldflagsto also setk8s.io/client-go/pkg/version.gitVersion. - Extend
go_cmctl_ldflagsto also setk8s.io/client-go/pkg/version.gitCommit.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
/ok-to-test |
|
For reference, these flags are "documented" in the client-go source code: https://github.com/kubernetes/client-go/blob/b5cc94ef3b2fa553a6b69d6c7c6fc8e5c90c02ce/pkg/version/version.go#L28-L42 |
erikgb
left a comment
There was a problem hiding this comment.
Thanks a lot @msasadzaidi! And thank you for attending our ContribFest at KubeCon EU 2026. This was a really nice fix! We hope to see more future contributions to cert-manager projects from you! 🚀
/lgtm
/approve
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: erikgb The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
Excellent PR. I was able to test this by running mitmproxy, but the easiest way to see that this PR works is to run the command that was shown in the PR description: $ make _bin/bin/cmctl
$ _bin/bin/cmctl version -o yaml -v 7 2>&1 | grep User-Agent
User-Agent: cmctl/v2.4.1 (darwin/arm64) kubernetes/742f960
User-Agent: cmctl/v2.4.1 (darwin/arm64) kubernetes/742f960
User-Agent: cmctl/v2.4.1 (darwin/arm64) kubernetes/742f960Very impressed, well done!! |
Fix User-Agent header reporting
v0.0.0instead of actual versionFixes #128
Problem
The
cmctlbinary reportsv0.0.0in the HTTPUser-Agentheader for allrequests made to the Kubernetes API server, regardless of the release version:
The
clientVersionoutput correctly shows the version (e.g.v2.4.1), but theUser-Agent header — which is what API servers and audit logs see — is wrong.
Root Cause
The build pipeline sets ldflags for
github.com/cert-manager/cert-manager/pkg/util(which controls the
clientVersionoutput), but does not set ldflags fork8s.io/client-go/pkg/version,which is what the Kubernetes REST client uses to construct the
User-Agentheader.The default values in
k8s.io/client-go/pkg/version/base.goare:These
$Formatplaceholders are git-archive substitution tokensthat are never expanded during a normal
go buildorgoreleaserbuild. Thefile itself documents: "This is the fallback data used when version information
from git is not provided via go ldflags."
The current ldflags in
make/00_mod.mkonly set two variables:
Steps to Reproduce
1. Build locally with
go install(no ldflags)2. Download the official release binary from the pipeline
The
clientVersion.gitVersioncorrectly reportsv2.4.1, but the User-Agentheader still shows
v0.0.0— confirming the release pipeline has the same gap.3. Rebuild with the missing ldflags
4. Verified the target variables exist and are overridable
The variables
gitVersionandgitCommitare declared as package-levelvar(not
const) ink8s.io/client-go/pkg/version/base.go,making them valid targets for
-ldflags -X.Fix
Add the
k8s.io/client-go/pkg/versionldflags togo_cmctl_ldflagsinmake/00_mod.mk:This is the same pattern used by Kubernetes itself and other tools built on
client-go (e.g., kubectl, helm).