Skip to content

Commit 32e5d55

Browse files
committed
🐛 Fix changes to Kubernetes version when running make generate
This commit changes how the Makefile handles updating Kubernetes version in cmd/version.go when running make generate. Rely on ldflags to set kubernetesVendorVersion, similarly to the other variables in cmd/version.go. Use a single variable to define K8S_VERSION for both ldflags and the goreleaser configuration. This makes our version handling more consistent and avoids unnecessary diffs in version control when only generating docs or other build artifacts.
1 parent 4c0b8d6 commit 32e5d55

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Makefile

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ help: ## Display this help
4545

4646
##@ Build
4747

48+
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}')
49+
4850
LD_FLAGS=-ldflags " \
4951
-X sigs.k8s.io/kubebuilder/v4/cmd.kubeBuilderVersion=$(shell git describe --tags --dirty --broken) \
52+
-X sigs.k8s.io/kubebuilder/v4/cmd.kubernetesVendorVersion=$(K8S_VERSION) \
5053
-X sigs.k8s.io/kubebuilder/v4/cmd.goos=$(shell go env GOOS) \
5154
-X sigs.k8s.io/kubebuilder/v4/cmd.goarch=$(shell go env GOARCH) \
5255
-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
201204
helm-lint: install-helm ## Lint the Helm chart in testdata
202205
helm lint testdata/project-v4-with-plugins/dist/chart
203206

204-
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}')
205207
.PHONY: update-k8s-version
206-
update-k8s-version: ## Update Kubernetes API version in version.go and .goreleaser.yml
208+
update-k8s-version: ## Update Kubernetes API version in .goreleaser.yml
207209
@if [ -z "$(K8S_VERSION)" ]; then echo "Error: K8S_VERSION is empty"; exit 1; fi
208-
@echo "Updating Kubernetes version to $(K8S_VERSION)"
209-
@# Update version.go
210-
@sed -i.bak 's/kubernetesVendorVersion = .*/kubernetesVendorVersion = "$(K8S_VERSION)"/' cmd/version.go
210+
@echo "Updating Kubernetes version to $(K8S_VERSION) in .goreleaser.yml"
211211
@# Update .goreleaser.yml
212212
@sed -i.bak 's/KUBERNETES_VERSION=.*/KUBERNETES_VERSION=$(K8S_VERSION)/' build/.goreleaser.yml
213213
@# Clean up backup files

0 commit comments

Comments
 (0)