-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
🐛 Fix permanent change to Kubernetes version when running make generate #4612
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,8 +45,11 @@ help: ## Display this help | |
|
||
##@ Build | ||
|
||
K8S_VERSION ?= $(shell go list -m -modfile=./testdata/project-v4/go.mod -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d.%d", $$3, $$4}') | ||
|
||
LD_FLAGS=-ldflags " \ | ||
-X sigs.k8s.io/kubebuilder/v4/cmd.kubeBuilderVersion=$(shell git describe --tags --dirty --broken) \ | ||
-X sigs.k8s.io/kubebuilder/v4/cmd.kubernetesVendorVersion=$(K8S_VERSION) \ | ||
-X sigs.k8s.io/kubebuilder/v4/cmd.goos=$(shell go env GOOS) \ | ||
-X sigs.k8s.io/kubebuilder/v4/cmd.goarch=$(shell go env GOARCH) \ | ||
-X sigs.k8s.io/kubebuilder/v4/cmd.gitCommit=$(shell git rev-parse HEAD) \ | ||
|
@@ -201,13 +204,10 @@ install-helm: ## Install the latest version of Helm locally | |
helm-lint: install-helm ## Lint the Helm chart in testdata | ||
helm lint testdata/project-v4-with-plugins/dist/chart | ||
|
||
K8S_VERSION ?= $(shell go list -m -modfile=./testdata/project-v4/go.mod -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d.%d", $$3, $$4}') | ||
.PHONY: update-k8s-version | ||
update-k8s-version: ## Update Kubernetes API version in version.go and .goreleaser.yml | ||
update-k8s-version: ## Update Kubernetes API version in .goreleaser.yml | ||
@if [ -z "$(K8S_VERSION)" ]; then echo "Error: K8S_VERSION is empty"; exit 1; fi | ||
@echo "Updating Kubernetes version to $(K8S_VERSION)" | ||
@# Update version.go | ||
@sed -i.bak 's/kubernetesVendorVersion = .*/kubernetesVendorVersion = "$(K8S_VERSION)"/' cmd/version.go | ||
@echo "Updating Kubernetes version to $(K8S_VERSION) in .goreleaser.yml" | ||
@# Update .goreleaser.yml | ||
@sed -i.bak 's/KUBERNETES_VERSION=.*/KUBERNETES_VERSION=$(K8S_VERSION)/' build/.goreleaser.yml | ||
@# Clean up backup files | ||
Comment on lines
+210
to
213
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This target was originally created due to: https://github.com/kubernetes-sigs/kubebuilder/pull/4516/files#diff-7cb26babce207ed9c17e9dd3ead0b66d204da3cf4d11649412c197defbb3029cR31 I just reviewed this. If we can ensure that:
Then, we are good to go. If you find a solution that meets all these requirements without needing to modify cmd/version.go, that would be even better. Let me know your thoughts! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @camilamacedo86 I ran $ make install
go build -ldflags " -X sigs.k8s.io/kubebuilder/v4/cmd.kubeBuilderVersion=v4.5.1-39-g32e5d5522 -X sigs.k8s.io/kubebuilder/v4/cmd.kubernetesVendorVersion=1.32.1 -X sigs.k8s.io/kubebuilder/v4/cmd.goos=linux -X sigs.k8s.io/kubebuilder/v4/cmd.goarch=amd64 -X sigs.k8s.io/kubebuilder/v4/cmd.gitCommit=32e5d5522b12d71356a2ffbc230866b4ddd512cc -X sigs.k8s.io/kubebuilder/v4/cmd.buildDate=2025-03-18T04:29:06Z " -o bin/kubebuilder
rm -f /home/vitorfloriano/go/bin/kubebuilder
cp ./bin/kubebuilder /home/vitorfloriano/go/bin/kubebuilder
$ kubebuilder version
Version: main.version{KubeBuilderVersion:"4.5.1", KubernetesVendor:"1.32.1", GitCommit:"0ace7a8753c52b35014e43edc2a0b0454b78e769", BuildDate:"2025-02-21T20:16:18Z", GoOs:"linux", GoArch:"amd64"} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also ran $ goreleaser release --snapshot --skip=publish -f ./build/.goreleaser.yml
• skipping announce, publish, and validate...
• loading environment variables
• getting and validating git state
• git state commit=32e5d5522b12d71356a2ffbc230866b4ddd512cc branch=bug/4611-make-generate-kubernetes-version current_tag=v4.5.1 previous_tag=v4.5.0 dirty=false
...
...
...
...
• writing artifacts metadata
• release succeeded after 21s
• thanks for using GoReleaser!
$ ./dist/kubebuilder_linux_amd64_v1/kubebuilder version
Version: cmd.version{KubeBuilderVersion:"4.5.1-SNAPSHOT-32e5d5522", KubernetesVendor:"1.32.1", GitCommit:"32e5d5522b12d71356a2ffbc230866b4ddd512cc", BuildDate:"2025-03-18T04:40:38Z", GoOs:"linux", GoArch:"amd64"} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great !!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @camilamacedo86 If I'm replicating this correctly, $ mkdir kb-test
$ cd kb-test/
~/kb-test$ git clone https://github.com/vitorfloriano/kubebuilder.git
Cloning into 'kubebuilder'...
~/kb-test$ cd kubebuilder/
~/kb-test/kubebuilder$ git checkout 32e5d5522b12d71356a2ffbc230866b4ddd512cc
Note: switching to '32e5d5522b12d71356a2ffbc230866b4ddd512cc'.
HEAD is now at 32e5d5522 🐛 Fix changes to Kubernetes version when running make generate
~/kb-test/kubebuilder$ go mod tidy
~/kb-test/kubebuilder$ go install .
~/kb-test/kubebuilder$ ~/go/bin/kubebuilder version
Version: cmd.version{KubeBuilderVersion:"(devel)", KubernetesVendor:"unknown", GitCommit:"$Format:%H$", BuildDate:"1970-01-01T00:00:00Z", GoOs:"unknown", GoArch:"unknown"} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also ran ~/kb-test/kubebuilder$ go build .
go: downloading github.com/sirupsen/logrus v1.9.3
go: downloading github.com/spf13/afero v1.12.0
go: downloading github.com/spf13/cobra v1.9.1
go: downloading github.com/spf13/pflag v1.0.6
go: downloading sigs.k8s.io/yaml v1.4.0
go: downloading golang.org/x/text v0.23.0
go: downloading golang.org/x/tools v0.31.0
go: downloading golang.org/x/sys v0.31.0
go: downloading github.com/gobuffalo/flect v1.0.3
go: downloading golang.org/x/sync v0.12.0
go: downloading golang.org/x/mod v0.24.0
~/kb-test/kubebuilder$ ./kubebuilder version
Version: cmd.version{KubeBuilderVersion:"(devel)", KubernetesVendor:"unknown", GitCommit:"$Format:%H$", BuildDate:"1970-01-01T00:00:00Z", GoOs:"unknown", GoArch:"unknown"} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @camilamacedo86 I think I see what you mean now. It seems that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we revert the changes in: update-k8s-version |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @vitorfloriano,
Our goal is to ensure that the binary always uses the Kubernetes version defined in the go.mod file of the projects built with it (e.g., project-v4), so that we don't need to pass any additional values manually.
Given that, the change you made above makes sense for me, But this one will be called when we run
make install
right? So, we need to run make install and check the bin version after the change.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test for this one:
The flags are called here:
kubebuilder/Makefile
Lines 56 to 58 in 4c0b8d6