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 kubernetesVendorVersion for binary builds with LD_FLAGS #4612

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Copy link
Member

@camilamacedo86 camilamacedo86 Mar 17, 2025

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.

Copy link
Member

@camilamacedo86 camilamacedo86 Mar 17, 2025

Choose a reason for hiding this comment

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

Test for this one:

$ make install 
go build -ldflags " -X sigs.k8s.io/kubebuilder/v4/cmd.kubeBuilderVersion=v4.5.0-99-g4c0b8d641 -X sigs.k8s.io/kubebuilder/v4/cmd.goos=darwin -X sigs.k8s.io/kubebuilder/v4/cmd.goarch=arm64 -X sigs.k8s.io/kubebuilder/v4/cmd.gitCommit=4c0b8d64107a1c2beae6ae6c83ca63d5393cde22 -X sigs.k8s.io/kubebuilder/v4/cmd.buildDate=2025-03-17T11:25:36Z " -o bin/kubebuilder
rm -f /Users/camilam/go/bin/kubebuilder
cp ./bin/kubebuilder /Users/camilam/go/bin/kubebuilder

----- Now to check that all still fine ---

$ kubebuilder version
Version: main.version{KubeBuilderVersion:"4.5.1", KubernetesVendor:"1.32.1", GitCommit:"0ace7a8753c52b35014e43edc2a0b0454b78e769", BuildDate:"2025-02-21T20:16:18Z", GoOs:"darwin", GoArch:"arm64"}

The flags are called here:

kubebuilder/Makefile

Lines 56 to 58 in 4c0b8d6

build: ## Build the project locally
go build $(LD_FLAGS) -o bin/kubebuilder

-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) \
Expand Down Expand Up @@ -201,7 +204,6 @@ 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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @camilamacedo86 I reverted the changes to the update-k8s-version target, as requested. The only changes left were moving the K8S_VERSION variable and adding a flag for kubernetesVendorVersion. I also changed the commit title and message accordingly. Let me know what you think.

update-k8s-version: ## Update Kubernetes API version in version.go and .goreleaser.yml
@if [ -z "$(K8S_VERSION)" ]; then echo "Error: K8S_VERSION is empty"; exit 1; fi
Expand Down
Loading