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

🐛 Fix permanent change to Kubernetes version when running make generate #4612

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vitorfloriano
Copy link
Contributor

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.

Closes: #4611

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.
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 15, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: vitorfloriano
Once this PR has been reviewed and has the lgtm label, please assign camilamacedo86 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot
Copy link
Contributor

Hi @vitorfloriano. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions 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.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 15, 2025
@camilamacedo86
Copy link
Member

camilamacedo86 commented Mar 15, 2025

Hi @vitorfloriano

That is great idea 🚀

Can you please just run go-releaser locally and verify the version values output in the binary generated.
To do it, you will need to follow the same steps: #4575 (comment)

Could you please add it in the description? In this way, we can easily ensure and keep a track that this fix worked? We have no tests for this one.

Thank you a lot 🥇

@vitorfloriano
Copy link
Contributor Author

vitorfloriano commented Mar 15, 2025

Can you please just run go-releaser locally and verify the version values output in the binary generated. To do it, you will need to follow the same steps: #4575 (comment)

@camilamacedo86 So I followed the steps mentioned in #4575 (comment) to test this and didn't get the expected result. To make sure that the version was being injected in the binary, I exported an arbitrary version, then ran make generate and goreleaser, but the version in the binary was not updated:

  1. Exporting an arbitrary version for test:
vitorfloriano@BOOK-LH3N3SS559:~/kubebuilder$ export KUBERNETES_VERSION="test-1.2.3"
  1. Then running make generate :
Some really long logs
vitorfloriano@BOOK-LH3N3SS559:~/kubebuilder$ make generate
chmod -R +w testdata/
rm -rf testdata/
./test/testdata/generate.sh
Building kubebuilder
~/kubebuilder/testdata/project-v4 ~/kubebuilder
Generating project project-v4 with flags: --plugins=go/v4
go: creating new go.mod: module sigs.k8s.io/kubebuilder/testdata/project-v4
Initializing project ...
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO Get controller runtime:
$ go get sigs.k8s.io/[email protected] 
INFO Update dependencies:
$ go mod tidy           
Next: define a resource with:
$ kubebuilder create api
Creating APIs ...
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO api/v1/captain_types.go                      
INFO api/v1/groupversion_info.go                  
INFO internal/controller/suite_test.go            
INFO internal/controller/captain_controller.go    
INFO internal/controller/captain_controller_test.go 
INFO Update dependencies:
$ go mod tidy           
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO api/v1/captain_types.go                      
INFO api/v1/groupversion_info.go                  
INFO internal/controller/suite_test.go            
INFO internal/controller/captain_controller.go    
INFO internal/controller/captain_controller_test.go 
INFO Update dependencies:
$ go mod tidy           
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO internal/webhook/v1/captain_webhook.go       
INFO internal/webhook/v1/captain_webhook_test.go  
INFO internal/webhook/v1/webhook_suite_test.go    
INFO Update dependencies:
$ go mod tidy           
Next: implement your new Webhook and generate the manifests with:
$ make manifests
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO api/v1/firstmate_types.go                    
INFO api/v1/groupversion_info.go                  
INFO internal/controller/suite_test.go            
INFO internal/controller/firstmate_controller.go  
INFO internal/controller/firstmate_controller_test.go 
INFO Update dependencies:
$ go mod tidy           
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO api/v2/firstmate_types.go                    
INFO api/v2/groupversion_info.go                  
INFO Update dependencies:
$ go mod tidy           
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO internal/webhook/v1/firstmate_webhook.go     
INFO internal/webhook/v1/firstmate_webhook_test.go 
INFO api/v1/firstmate_conversion.go               
INFO Scaffolding for spoke version: v2            
INFO Creating spoke conversion file at: api/v2/firstmate_conversion.go 
INFO Webhook server has been set up for you.
You need to implement the conversion.Hub and conversion.Convertible interfaces for your CRD types. 
INFO Update dependencies:
$ go mod tidy           
Next: implement your new Webhook and generate the manifests with:
$ make manifests
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO api/v1/admiral_types.go                      
INFO api/v1/groupversion_info.go                  
INFO internal/controller/suite_test.go            
INFO internal/controller/admiral_controller.go    
INFO internal/controller/admiral_controller_test.go 
INFO Update dependencies:
$ go mod tidy           
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO internal/webhook/v1/admiral_webhook.go       
INFO internal/webhook/v1/admiral_webhook_test.go  
INFO internal/webhook/v1/webhook_suite_test.go    
INFO Update dependencies:
$ go mod tidy           
INFO Running make:
$ make generate                
make[1]: Entering directory '/home/vitorfloriano/kubebuilder/testdata/project-v4'
mkdir -p /home/vitorfloriano/kubebuilder/testdata/project-v4/bin
Downloading sigs.k8s.io/controller-tools/cmd/[email protected]
/home/vitorfloriano/kubebuilder/testdata/project-v4/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
make[1]: Leaving directory '/home/vitorfloriano/kubebuilder/testdata/project-v4'
Next: implement your new Webhook and generate the manifests with:
$ make manifests
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO internal/controller/suite_test.go            
INFO internal/controller/certificate_controller.go 
INFO internal/controller/certificate_controller_test.go 
INFO Update dependencies:
$ go mod tidy           
go: finding module for package github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1
go: found github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1 in github.com/cert-manager/cert-manager v1.17.1
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO internal/webhook/v1/issuer_webhook.go        
INFO internal/webhook/v1/issuer_webhook_test.go   
INFO internal/webhook/v1/webhook_suite_test.go    
INFO Update dependencies:
$ go mod tidy           
INFO Running make:
$ make generate                
make[1]: Entering directory '/home/vitorfloriano/kubebuilder/testdata/project-v4'
/home/vitorfloriano/kubebuilder/testdata/project-v4/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
make[1]: Leaving directory '/home/vitorfloriano/kubebuilder/testdata/project-v4'
Next: implement your new Webhook and generate the manifests with:
$ make manifests
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO internal/webhook/v1/pod_webhook.go           
INFO internal/webhook/v1/pod_webhook_test.go      
INFO internal/webhook/v1/webhook_suite_test.go    
INFO Update dependencies:
$ go mod tidy           
INFO Running make:
$ make generate                
make[1]: Entering directory '/home/vitorfloriano/kubebuilder/testdata/project-v4'
/home/vitorfloriano/kubebuilder/testdata/project-v4/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
make[1]: Leaving directory '/home/vitorfloriano/kubebuilder/testdata/project-v4'
Next: implement your new Webhook and generate the manifests with:
$ make manifests
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO internal/webhook/v1/deployment_webhook.go    
INFO internal/webhook/v1/deployment_webhook_test.go 
INFO internal/webhook/v1/webhook_suite_test.go    
INFO Update dependencies:
$ go mod tidy           
INFO Running make:
$ make generate                
make[1]: Entering directory '/home/vitorfloriano/kubebuilder/testdata/project-v4'
/home/vitorfloriano/kubebuilder/testdata/project-v4/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
make[1]: Leaving directory '/home/vitorfloriano/kubebuilder/testdata/project-v4'
Next: implement your new Webhook and generate the manifests with:
$ make manifests
make[1]: Entering directory '/home/vitorfloriano/kubebuilder/testdata/project-v4'
/home/vitorfloriano/kubebuilder/testdata/project-v4/bin/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
/home/vitorfloriano/kubebuilder/testdata/project-v4/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
go fmt ./...
go vet ./...
go build -o bin/manager cmd/main.go
make[1]: Leaving directory '/home/vitorfloriano/kubebuilder/testdata/project-v4'
make[1]: Entering directory '/home/vitorfloriano/kubebuilder/testdata/project-v4'
/home/vitorfloriano/kubebuilder/testdata/project-v4/bin/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
/home/vitorfloriano/kubebuilder/testdata/project-v4/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
Downloading sigs.k8s.io/kustomize/kustomize/[email protected]
mkdir -p dist
cd config/manager && /home/vitorfloriano/kubebuilder/testdata/project-v4/bin/kustomize edit set image controller=controller:latest
/home/vitorfloriano/kubebuilder/testdata/project-v4/bin/kustomize build config/default > dist/install.yaml
make[1]: Leaving directory '/home/vitorfloriano/kubebuilder/testdata/project-v4'
~/kubebuilder
~/kubebuilder/testdata/project-v4-multigroup ~/kubebuilder
Generating project project-v4-multigroup with flags: --plugins=go/v4
go: creating new go.mod: module sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup
Initializing project ...
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO Get controller runtime:
$ go get sigs.k8s.io/[email protected] 
INFO Update dependencies:
$ go mod tidy           
Next: define a resource with:
$ kubebuilder create api
Switching to multigroup layout ...
Creating APIs ...
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO api/crew/v1/captain_types.go                 
INFO api/crew/v1/groupversion_info.go             
INFO internal/controller/crew/suite_test.go       
INFO internal/controller/crew/captain_controller.go 
INFO internal/controller/crew/captain_controller_test.go 
INFO Update dependencies:
$ go mod tidy           
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO internal/webhook/crew/v1/captain_webhook.go  
INFO internal/webhook/crew/v1/captain_webhook_test.go 
INFO internal/webhook/crew/v1/webhook_suite_test.go 
INFO Update dependencies:
$ go mod tidy           
Next: implement your new Webhook and generate the manifests with:
$ make manifests
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO api/ship/v1beta1/frigate_types.go            
INFO api/ship/v1beta1/groupversion_info.go        
INFO internal/controller/ship/suite_test.go       
INFO internal/controller/ship/frigate_controller.go 
INFO internal/controller/ship/frigate_controller_test.go 
INFO Update dependencies:
$ go mod tidy           
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO api/ship/v1/destroyer_types.go               
INFO api/ship/v1/groupversion_info.go             
INFO internal/controller/ship/suite_test.go       
INFO internal/controller/ship/destroyer_controller.go 
INFO internal/controller/ship/destroyer_controller_test.go 
INFO Update dependencies:
$ go mod tidy           
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO internal/webhook/ship/v1/destroyer_webhook.go 
INFO internal/webhook/ship/v1/destroyer_webhook_test.go 
INFO internal/webhook/ship/v1/webhook_suite_test.go 
INFO Update dependencies:
$ go mod tidy           
Next: implement your new Webhook and generate the manifests with:
$ make manifests
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO api/ship/v2alpha1/cruiser_types.go           
INFO api/ship/v2alpha1/groupversion_info.go       
INFO internal/controller/ship/suite_test.go       
INFO internal/controller/ship/cruiser_controller.go 
INFO internal/controller/ship/cruiser_controller_test.go 
INFO Update dependencies:
$ go mod tidy           
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO internal/webhook/ship/v2alpha1/cruiser_webhook.go 
INFO internal/webhook/ship/v2alpha1/cruiser_webhook_test.go 
INFO internal/webhook/ship/v2alpha1/webhook_suite_test.go 
INFO Update dependencies:
$ go mod tidy           
Next: implement your new Webhook and generate the manifests with:
$ make manifests
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO api/sea-creatures/v1beta1/kraken_types.go    
INFO api/sea-creatures/v1beta1/groupversion_info.go 
INFO internal/controller/sea-creatures/suite_test.go 
INFO internal/controller/sea-creatures/kraken_controller.go 
INFO internal/controller/sea-creatures/kraken_controller_test.go 
INFO Update dependencies:
$ go mod tidy           
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO api/sea-creatures/v1beta2/leviathan_types.go 
INFO api/sea-creatures/v1beta2/groupversion_info.go 
INFO internal/controller/sea-creatures/suite_test.go 
INFO internal/controller/sea-creatures/leviathan_controller.go 
INFO internal/controller/sea-creatures/leviathan_controller_test.go 
INFO Update dependencies:
$ go mod tidy           
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO api/foo.policy/v1/healthcheckpolicy_types.go 
INFO api/foo.policy/v1/groupversion_info.go       
INFO internal/controller/foo.policy/suite_test.go 
INFO internal/controller/foo.policy/healthcheckpolicy_controller.go 
INFO internal/controller/foo.policy/healthcheckpolicy_controller_test.go 
INFO Update dependencies:
$ go mod tidy           
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO internal/controller/apps/suite_test.go       
INFO internal/controller/apps/deployment_controller.go 
INFO internal/controller/apps/deployment_controller_test.go 
INFO Update dependencies:
$ go mod tidy           
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO api/foo/v1/bar_types.go                      
INFO api/foo/v1/groupversion_info.go              
INFO internal/controller/foo/suite_test.go        
INFO internal/controller/foo/bar_controller.go    
INFO internal/controller/foo/bar_controller_test.go 
INFO Update dependencies:
$ go mod tidy           
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO api/fiz/v1/bar_types.go                      
INFO api/fiz/v1/groupversion_info.go              
INFO internal/controller/fiz/suite_test.go        
INFO internal/controller/fiz/bar_controller.go    
INFO internal/controller/fiz/bar_controller_test.go 
INFO Update dependencies:
$ go mod tidy           
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO internal/controller/cert-manager/suite_test.go 
INFO internal/controller/cert-manager/certificate_controller.go 
INFO internal/controller/cert-manager/certificate_controller_test.go 
INFO Update dependencies:
$ go mod tidy           
go: finding module for package github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1
go: found github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1 in github.com/cert-manager/cert-manager v1.17.1
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO internal/webhook/cert-manager/v1/issuer_webhook.go 
INFO internal/webhook/cert-manager/v1/issuer_webhook_test.go 
INFO internal/webhook/cert-manager/v1/webhook_suite_test.go 
INFO Update dependencies:
$ go mod tidy           
INFO Running make:
$ make generate                
make[1]: Entering directory '/home/vitorfloriano/kubebuilder/testdata/project-v4-multigroup'
mkdir -p /home/vitorfloriano/kubebuilder/testdata/project-v4-multigroup/bin
Downloading sigs.k8s.io/controller-tools/cmd/[email protected]
/home/vitorfloriano/kubebuilder/testdata/project-v4-multigroup/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
make[1]: Leaving directory '/home/vitorfloriano/kubebuilder/testdata/project-v4-multigroup'
Next: implement your new Webhook and generate the manifests with:
$ make manifests
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO internal/webhook/core/v1/pod_webhook.go      
INFO internal/webhook/core/v1/pod_webhook_test.go 
INFO internal/webhook/core/v1/webhook_suite_test.go 
INFO Update dependencies:
$ go mod tidy           
Next: implement your new Webhook and generate the manifests with:
$ make manifests
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO internal/webhook/apps/v1/deployment_webhook.go 
INFO internal/webhook/apps/v1/deployment_webhook_test.go 
INFO internal/webhook/apps/v1/webhook_suite_test.go 
INFO Update dependencies:
$ go mod tidy           
Next: implement your new Webhook and generate the manifests with:
$ make manifests
With Optional Plugins ...
Creating APIs with deploy-image plugin ...
INFO updating scaffold with deploy-image/v1alpha1 plugin... 
INFO Writing scaffold for you to edit...          
INFO Writing scaffold for you to edit...          
INFO api/example.com/v1alpha1/memcached_types.go  
INFO api/example.com/v1alpha1/groupversion_info.go 
INFO internal/controller/example.com/suite_test.go 
INFO internal/controller/example.com/memcached_controller.go 
INFO internal/controller/example.com/memcached_controller_test.go 
INFO Writing kustomize manifests for you to edit... 
INFO api/example.com/v1alpha1/memcached_types.go  
INFO config/samples/example.com_v1alpha1_memcached.yaml 
INFO internal/controller/example.com/memcached_controller.go 
INFO creating import for % sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/example.com/v1alpha1 
INFO internal/controller/example.com/memcached_controller_test.go 
INFO creating import for % sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/example.com/v1alpha1 
INFO Update dependencies:
$ go mod tidy           
INFO Running make:
$ make manifests               
make[1]: Entering directory '/home/vitorfloriano/kubebuilder/testdata/project-v4-multigroup'
/home/vitorfloriano/kubebuilder/testdata/project-v4-multigroup/bin/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
make[1]: Leaving directory '/home/vitorfloriano/kubebuilder/testdata/project-v4-multigroup'
Next: check the implementation of your new API and controller. If you do changes in the API run the manifests with:
$ make manifests
INFO updating scaffold with deploy-image/v1alpha1 plugin... 
INFO Writing scaffold for you to edit...          
INFO Writing scaffold for you to edit...          
INFO api/example.com/v1alpha1/busybox_types.go    
INFO api/example.com/v1alpha1/groupversion_info.go 
INFO internal/controller/example.com/suite_test.go 
INFO internal/controller/example.com/busybox_controller.go 
INFO internal/controller/example.com/busybox_controller_test.go 
INFO Writing kustomize manifests for you to edit... 
INFO api/example.com/v1alpha1/busybox_types.go    
INFO config/samples/example.com_v1alpha1_busybox.yaml 
INFO internal/controller/example.com/busybox_controller.go 
INFO creating import for % sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/example.com/v1alpha1 
INFO internal/controller/example.com/busybox_controller_test.go 
INFO creating import for % sigs.k8s.io/kubebuilder/testdata/project-v4-multigroup/api/example.com/v1alpha1 
INFO Update dependencies:
$ go mod tidy           
INFO Running make:
$ make manifests               
make[1]: Entering directory '/home/vitorfloriano/kubebuilder/testdata/project-v4-multigroup'
/home/vitorfloriano/kubebuilder/testdata/project-v4-multigroup/bin/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
make[1]: Leaving directory '/home/vitorfloriano/kubebuilder/testdata/project-v4-multigroup'
Next: check the implementation of your new API and controller. If you do changes in the API run the manifests with:
$ make manifests
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO internal/webhook/example.com/v1alpha1/memcached_webhook.go 
INFO internal/webhook/example.com/v1alpha1/memcached_webhook_test.go 
INFO internal/webhook/example.com/v1alpha1/webhook_suite_test.go 
INFO Update dependencies:
$ go mod tidy           
Next: implement your new Webhook and generate the manifests with:
$ make manifests
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO api/example.com/v1/wordpress_types.go        
INFO api/example.com/v1/groupversion_info.go      
INFO internal/controller/example.com/suite_test.go 
INFO internal/controller/example.com/wordpress_controller.go 
INFO internal/controller/example.com/wordpress_controller_test.go 
INFO Update dependencies:
$ go mod tidy           
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO api/example.com/v2/wordpress_types.go        
INFO api/example.com/v2/groupversion_info.go      
INFO Update dependencies:
$ go mod tidy           
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO internal/webhook/example.com/v1/wordpress_webhook.go 
INFO internal/webhook/example.com/v1/wordpress_webhook_test.go 
INFO api/example.com/v1/wordpress_conversion.go   
INFO Scaffolding for spoke version: v2            
INFO Creating spoke conversion file at: api/example.com/v2/wordpress_conversion.go 
INFO Webhook server has been set up for you.
You need to implement the conversion.Hub and conversion.Convertible interfaces for your CRD types. 
INFO Update dependencies:
$ go mod tidy           
Next: implement your new Webhook and generate the manifests with:
$ make manifests
Editing project with Grafana plugin ...
INFO Generating Grafana manifests to visualize controller status... 
make[1]: Entering directory '/home/vitorfloriano/kubebuilder/testdata/project-v4-multigroup'
/home/vitorfloriano/kubebuilder/testdata/project-v4-multigroup/bin/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
/home/vitorfloriano/kubebuilder/testdata/project-v4-multigroup/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
go fmt ./...
go vet ./...
go build -o bin/manager cmd/main.go
make[1]: Leaving directory '/home/vitorfloriano/kubebuilder/testdata/project-v4-multigroup'
make[1]: Entering directory '/home/vitorfloriano/kubebuilder/testdata/project-v4-multigroup'
/home/vitorfloriano/kubebuilder/testdata/project-v4-multigroup/bin/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
/home/vitorfloriano/kubebuilder/testdata/project-v4-multigroup/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
Downloading sigs.k8s.io/kustomize/kustomize/[email protected]
mkdir -p dist
cd config/manager && /home/vitorfloriano/kubebuilder/testdata/project-v4-multigroup/bin/kustomize edit set image controller=controller:latest
/home/vitorfloriano/kubebuilder/testdata/project-v4-multigroup/bin/kustomize build config/default > dist/install.yaml
make[1]: Leaving directory '/home/vitorfloriano/kubebuilder/testdata/project-v4-multigroup'
~/kubebuilder
~/kubebuilder/testdata/project-v4-with-plugins ~/kubebuilder
Generating project project-v4-with-plugins with flags: --plugins=go/v4
go: creating new go.mod: module sigs.k8s.io/kubebuilder/testdata/project-v4-with-plugins
Initializing project ...
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO Get controller runtime:
$ go get sigs.k8s.io/[email protected] 
INFO Update dependencies:
$ go mod tidy           
Next: define a resource with:
$ kubebuilder create api
With Optional Plugins ...
Creating APIs with deploy-image plugin ...
INFO updating scaffold with deploy-image/v1alpha1 plugin... 
INFO Writing scaffold for you to edit...          
INFO Writing scaffold for you to edit...          
INFO api/v1alpha1/memcached_types.go              
INFO api/v1alpha1/groupversion_info.go            
INFO internal/controller/suite_test.go            
INFO internal/controller/memcached_controller.go  
INFO internal/controller/memcached_controller_test.go 
INFO Writing kustomize manifests for you to edit... 
INFO api/v1alpha1/memcached_types.go              
INFO config/samples/example.com_v1alpha1_memcached.yaml 
INFO internal/controller/memcached_controller.go  
INFO creating import for % sigs.k8s.io/kubebuilder/testdata/project-v4-with-plugins/api/v1alpha1 
INFO internal/controller/memcached_controller_test.go 
INFO creating import for % sigs.k8s.io/kubebuilder/testdata/project-v4-with-plugins/api/v1alpha1 
INFO Update dependencies:
$ go mod tidy           
INFO Running make:
$ make manifests               
make[1]: Entering directory '/home/vitorfloriano/kubebuilder/testdata/project-v4-with-plugins'
mkdir -p /home/vitorfloriano/kubebuilder/testdata/project-v4-with-plugins/bin
Downloading sigs.k8s.io/controller-tools/cmd/[email protected]
/home/vitorfloriano/kubebuilder/testdata/project-v4-with-plugins/bin/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
make[1]: Leaving directory '/home/vitorfloriano/kubebuilder/testdata/project-v4-with-plugins'
Next: check the implementation of your new API and controller. If you do changes in the API run the manifests with:
$ make manifests
INFO updating scaffold with deploy-image/v1alpha1 plugin... 
INFO Writing scaffold for you to edit...          
INFO Writing scaffold for you to edit...          
INFO api/v1alpha1/busybox_types.go                
INFO api/v1alpha1/groupversion_info.go            
INFO internal/controller/suite_test.go            
INFO internal/controller/busybox_controller.go    
INFO internal/controller/busybox_controller_test.go 
INFO Writing kustomize manifests for you to edit... 
INFO api/v1alpha1/busybox_types.go                
INFO config/samples/example.com_v1alpha1_busybox.yaml 
INFO internal/controller/busybox_controller.go    
INFO creating import for % sigs.k8s.io/kubebuilder/testdata/project-v4-with-plugins/api/v1alpha1 
INFO internal/controller/busybox_controller_test.go 
INFO creating import for % sigs.k8s.io/kubebuilder/testdata/project-v4-with-plugins/api/v1alpha1 
INFO Update dependencies:
$ go mod tidy           
INFO Running make:
$ make manifests               
make[1]: Entering directory '/home/vitorfloriano/kubebuilder/testdata/project-v4-with-plugins'
/home/vitorfloriano/kubebuilder/testdata/project-v4-with-plugins/bin/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
make[1]: Leaving directory '/home/vitorfloriano/kubebuilder/testdata/project-v4-with-plugins'
Next: check the implementation of your new API and controller. If you do changes in the API run the manifests with:
$ make manifests
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO internal/webhook/v1alpha1/memcached_webhook.go 
INFO internal/webhook/v1alpha1/memcached_webhook_test.go 
INFO internal/webhook/v1alpha1/webhook_suite_test.go 
INFO Update dependencies:
$ go mod tidy           
Next: implement your new Webhook and generate the manifests with:
$ make manifests
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO api/v1/wordpress_types.go                    
INFO api/v1/groupversion_info.go                  
INFO internal/controller/suite_test.go            
INFO internal/controller/wordpress_controller.go  
INFO internal/controller/wordpress_controller_test.go 
INFO Update dependencies:
$ go mod tidy           
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO api/v2/wordpress_types.go                    
INFO api/v2/groupversion_info.go                  
INFO Update dependencies:
$ go mod tidy           
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit...          
INFO internal/webhook/v1/wordpress_webhook.go     
INFO internal/webhook/v1/wordpress_webhook_test.go 
INFO api/v1/wordpress_conversion.go               
INFO Scaffolding for spoke version: v2            
INFO Creating spoke conversion file at: api/v2/wordpress_conversion.go 
INFO Webhook server has been set up for you.
You need to implement the conversion.Hub and conversion.Convertible interfaces for your CRD types. 
INFO Update dependencies:
$ go mod tidy           
Next: implement your new Webhook and generate the manifests with:
$ make manifests
Editing project with Grafana plugin ...
INFO Generating Grafana manifests to visualize controller status... 
make[1]: Entering directory '/home/vitorfloriano/kubebuilder/testdata/project-v4-with-plugins'
/home/vitorfloriano/kubebuilder/testdata/project-v4-with-plugins/bin/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
/home/vitorfloriano/kubebuilder/testdata/project-v4-with-plugins/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
go fmt ./...
go vet ./...
go build -o bin/manager cmd/main.go
make[1]: Leaving directory '/home/vitorfloriano/kubebuilder/testdata/project-v4-with-plugins'
make[1]: Entering directory '/home/vitorfloriano/kubebuilder/testdata/project-v4-with-plugins'
/home/vitorfloriano/kubebuilder/testdata/project-v4-with-plugins/bin/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
/home/vitorfloriano/kubebuilder/testdata/project-v4-with-plugins/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
Downloading sigs.k8s.io/kustomize/kustomize/[email protected]
mkdir -p dist
cd config/manager && /home/vitorfloriano/kubebuilder/testdata/project-v4-with-plugins/bin/kustomize edit set image controller=controller:latest
/home/vitorfloriano/kubebuilder/testdata/project-v4-with-plugins/bin/kustomize build config/default > dist/install.yaml
make[1]: Leaving directory '/home/vitorfloriano/kubebuilder/testdata/project-v4-with-plugins'
Editing project with Helm plugin ...
INFO Generating Helm Chart to distribute project  
INFO Successfully copied config/rbac/busybox_admin_role.yaml to dist/chart/templates/rbac/busybox_admin_role.yaml 
INFO Successfully copied config/rbac/busybox_editor_role.yaml to dist/chart/templates/rbac/busybox_editor_role.yaml 
INFO Successfully copied config/rbac/busybox_viewer_role.yaml to dist/chart/templates/rbac/busybox_viewer_role.yaml 
INFO Successfully copied config/rbac/leader_election_role.yaml to dist/chart/templates/rbac/leader_election_role.yaml 
INFO Successfully copied config/rbac/leader_election_role_binding.yaml to dist/chart/templates/rbac/leader_election_role_binding.yaml 
INFO Successfully copied config/rbac/memcached_admin_role.yaml to dist/chart/templates/rbac/memcached_admin_role.yaml 
INFO Successfully copied config/rbac/memcached_editor_role.yaml to dist/chart/templates/rbac/memcached_editor_role.yaml 
INFO Successfully copied config/rbac/memcached_viewer_role.yaml to dist/chart/templates/rbac/memcached_viewer_role.yaml 
INFO Successfully copied config/rbac/metrics_auth_role.yaml to dist/chart/templates/rbac/metrics_auth_role.yaml 
INFO Successfully copied config/rbac/metrics_auth_role_binding.yaml to dist/chart/templates/rbac/metrics_auth_role_binding.yaml 
INFO Successfully copied config/rbac/metrics_reader_role.yaml to dist/chart/templates/rbac/metrics_reader_role.yaml 
INFO Successfully copied config/rbac/role.yaml to dist/chart/templates/rbac/role.yaml 
INFO Successfully copied config/rbac/role_binding.yaml to dist/chart/templates/rbac/role_binding.yaml 
INFO Successfully copied config/rbac/service_account.yaml to dist/chart/templates/rbac/service_account.yaml 
INFO Successfully copied config/rbac/wordpress_admin_role.yaml to dist/chart/templates/rbac/wordpress_admin_role.yaml 
INFO Successfully copied config/rbac/wordpress_editor_role.yaml to dist/chart/templates/rbac/wordpress_editor_role.yaml 
INFO Successfully copied config/rbac/wordpress_viewer_role.yaml to dist/chart/templates/rbac/wordpress_viewer_role.yaml 
INFO Successfully copied config/crd/bases/example.com.testproject.org_busyboxes.yaml to dist/chart/templates/crd/example.com.testproject.org_busyboxes.yaml 
INFO Successfully copied config/crd/bases/example.com.testproject.org_memcacheds.yaml to dist/chart/templates/crd/example.com.testproject.org_memcacheds.yaml 
INFO Successfully copied config/crd/bases/example.com.testproject.org_wordpresses.yaml to dist/chart/templates/crd/example.com.testproject.org_wordpresses.yaml 
INFO Successfully copied config/network-policy/allow-metrics-traffic.yaml to dist/chart/templates/network-policy/allow-metrics-traffic.yaml 
INFO Successfully copied config/network-policy/allow-webhook-traffic.yaml to dist/chart/templates/network-policy/allow-webhook-traffic.yaml 
~/kubebuilder
./hack/docs/generate.sh
Building kubebuilder
INFO Generating documents...                      
INFO Generating cronjob tutorial                  
INFO Generating the sample context of Cronjob...  
INFO destroying directory for cronjob sample project 
INFO refreshing tools and creating directory...   
  cleaning up tools
  preparing testing directory: docs/book/src/cronjob-tutorial/testdata/project/
INFO Initializing the cronjob project             
  running: /tmp/kubebuilder/bin/kubebuilder init --domain tutorial.kubebuilder.io --repo tutorial.kubebuilder.io/project --license apache2 --owner The Kubernetes authors
INFO Adding a new config type                     
  running: /tmp/kubebuilder/bin/kubebuilder create api --group batch --version v1 --kind CronJob --resource --controller
INFO Implementing admission webhook               
  running: /tmp/kubebuilder/bin/kubebuilder create webhook --group batch --version v1 --kind CronJob --defaulting --programmatic-validation
INFO Update tutorial with cronjob code            
  running: go mod tidy
  running: go get github.com/robfig/cron
  running: make generate manifests
  running: make generate manifests
  running: make all
  running: make build-installer
  running: /tmp/kubebuilder/bin/kubebuilder edit --plugins=helm/v1-alpha
INFO Generating getting-started tutorial          
INFO Generating the sample context of getting-started... 
INFO Destroying directory for getting-started sample project 
INFO Refreshing tools and creating directory...   
  cleaning up tools
  preparing testing directory: docs/book/src/getting-started/testdata/project
INFO Initializing the getting started project     
  running: /tmp/kubebuilder/bin/kubebuilder init --domain example.com --repo example.com/memcached --license apache2 --owner The Kubernetes authors
INFO Adding a new config type                     
  running: /tmp/kubebuilder/bin/kubebuilder create api --group cache --version v1alpha1 --kind Memcached --resource --controller
  running: go mod tidy
  running: make all
  running: make build-installer
  running: /tmp/kubebuilder/bin/kubebuilder edit --plugins=helm/v1-alpha
INFO Generating multiversion tutorial             
INFO Generating the sample context of Cronjob...  
INFO destroying directory for cronjob sample project 
INFO refreshing tools and creating directory...   
  cleaning up tools
  preparing testing directory: docs/book/src/multiversion-tutorial/testdata/project
INFO Initializing the cronjob project             
  running: /tmp/kubebuilder/bin/kubebuilder init --domain tutorial.kubebuilder.io --repo tutorial.kubebuilder.io/project --license apache2 --owner The Kubernetes authors
INFO Adding a new config type                     
  running: /tmp/kubebuilder/bin/kubebuilder create api --group batch --version v1 --kind CronJob --resource --controller
INFO Implementing admission webhook               
  running: /tmp/kubebuilder/bin/kubebuilder create webhook --group batch --version v1 --kind CronJob --defaulting --programmatic-validation
INFO Update tutorial with cronjob code            
  running: go mod tidy
  running: go get github.com/robfig/cron
  running: make generate manifests
  running: make generate manifests
  running: make all
  running: make build-installer
  running: /tmp/kubebuilder/bin/kubebuilder edit --plugins=helm/v1-alpha
INFO Generating the sample context of MultiVersion Cronjob... 
INFO refreshing tools and creating directory for multiversion ... 
  cleaning up tools
  preparing testing directory: docs/book/src/multiversion-tutorial/testdata/project
INFO Initializing the multiversion cronjob project 
INFO Creating v2 API                              
  running: /tmp/kubebuilder/bin/kubebuilder create api --group batch --version v2 --kind CronJob --resource=true --controller=false
INFO Creating conversion webhook for v1           
  running: /tmp/kubebuilder/bin/kubebuilder create webhook --group batch --version v1 --kind CronJob --conversion --spoke v2 --force
INFO Workaround to fix the issue with the conversion webhook 
  running: cp ./../../../cronjob-tutorial/testdata/project/internal/webhook/v1/cronjob_webhook.go ./internal/webhook/v1/cronjob_webhook.go
INFO Creating defaulting and validation webhook for v2 
  running: /tmp/kubebuilder/bin/kubebuilder create webhook --group batch --version v2 --kind CronJob --defaulting --programmatic-validation
INFO Update tutorial with multiversion code       
  running: make all
  running: make build-installer
  running: /tmp/kubebuilder/bin/kubebuilder edit --plugins=helm/v1-alpha
Updating Kubernetes version to 1.32.1 in .goreleaser.yml
go mod tidy
make remove-spaces
make[1]: Entering directory '/home/vitorfloriano/kubebuilder'
Removing trailing spaces
make[1]: Leaving directory '/home/vitorfloriano/kubebuilder'
  1. Running goreleaser as instructed:
goreleaser output
vitorfloriano@BOOK-LH3N3SS559:~/kubebuilder$ goreleaser release --snapshot --skip=publish -f ./build/.goreleaser.yml
  • skipping announce, publish, and validate...
  • loading environment variables
  • getting and validating git state
    • ignoring errors because this is a snapshot     error=git doesn't contain any tags - either add a tag or use --snapshot
    • git state                                      commit=32e5d5522b12d71356a2ffbc230866b4ddd512cc branch=bug/4611-make-generate-kubernetes-version current_tag=v0.0.0 previous_tag=<unknown> dirty=false
    • pipe skipped or partially skipped              reason=disabled during snapshot mode
  • parsing tag
  • setting defaults
  • snapshotting
    • building snapshot...                           version=0.0.0-SNAPSHOT-32e5d5522
  • running before hooks
    • running                                        hook=go mod download
  • ensuring distribution directory
  • setting up metadata
  • writing release metadata
  • loading go mod information
  • build prerequisites
  • building binaries
    • building                                       binary=dist/kubebuilder_linux_arm64_v8.0/kubebuilder
    • building                                       binary=dist/kubebuilder_linux_s390x/kubebuilder
    • building                                       binary=dist/kubebuilder_darwin_amd64_v1/kubebuilder
    • building                                       binary=dist/kubebuilder_linux_ppc64le_power8/kubebuilder
    • building                                       binary=dist/kubebuilder_darwin_arm64_v8.0/kubebuilder
    • building                                       binary=dist/kubebuilder_linux_amd64_v1/kubebuilder
  • archives
    • archiving                                      binary=kubebuilder name=kubebuilder_linux_arm64
    • archiving                                      binary=kubebuilder name=kubebuilder_linux_amd64
    • archiving                                      binary=kubebuilder name=kubebuilder_linux_s390x
    • archiving                                      binary=kubebuilder name=kubebuilder_linux_ppc64le
    • archiving                                      binary=kubebuilder name=kubebuilder_darwin_arm64
    • archiving                                      binary=kubebuilder name=kubebuilder_darwin_amd64
  • cataloging artifacts
    • cataloging                                     cmd=syft artifact=dist/kubebuilder_linux_arm64_v8.0/kubebuilder sbom=[kubebuilder_0.0.0-SNAPSHOT-32e5d5522_linux_arm64.cyclonedx.sbom.json]
    • cataloging                                     cmd=syft artifact=dist/kubebuilder_linux_amd64_v1/kubebuilder sbom=[kubebuilder_0.0.0-SNAPSHOT-32e5d5522_linux_amd64.cyclonedx.sbom.json]
    • cataloging                                     cmd=syft artifact=dist/kubebuilder_linux_s390x/kubebuilder sbom=[kubebuilder_0.0.0-SNAPSHOT-32e5d5522_linux_s390x.cyclonedx.sbom.json]
    • cataloging                                     cmd=syft artifact=dist/kubebuilder_linux_ppc64le_power8/kubebuilder sbom=[kubebuilder_0.0.0-SNAPSHOT-32e5d5522_linux_ppc64le.cyclonedx.sbom.json]
    • cataloging                                     cmd=syft artifact=dist/kubebuilder_darwin_arm64_v8.0/kubebuilder sbom=[kubebuilder_0.0.0-SNAPSHOT-32e5d5522_darwin_arm64.cyclonedx.sbom.json]
    • cataloging                                     cmd=syft artifact=dist/kubebuilder_darwin_amd64_v1/kubebuilder sbom=[kubebuilder_0.0.0-SNAPSHOT-32e5d5522_darwin_amd64.cyclonedx.sbom.json]
    • took: 17s
  • calculating checksums
  • writing artifacts metadata
  • release succeeded after 20s
  • thanks for using GoReleaser!
  1. Then checking the version in the binary:
vitorfloriano@BOOK-LH3N3SS559:~/kubebuilder$ ./dist/kubebuilder_linux_amd64_v1/kubebuilder version
Version: cmd.version{KubeBuilderVersion:"0.0.0-SNAPSHOT-32e5d5522", KubernetesVendor:"1.32.1", GitCommit:"32e5d5522b12d71356a2ffbc230866b4ddd512cc", BuildDate:"2025-03-15T17:23:29Z", GoOs:"linux", GoArch:"amd64"}

So, as you can see, the KubernetesVendor version is still set to "1.32.1", despite having exported a different value before the build.

I guess this is due to how the instructions in the Makefile are hardcoding the version in the goreleaser config file:

kubebuilder/Makefile

Lines 211 to 212 in 4c0b8d6

@# Update .goreleaser.yml
@sed -i.bak 's/KUBERNETES_VERSION=.*/KUBERNETES_VERSION=$(K8S_VERSION)/' build/.goreleaser.yml

env:
- KUBERNETES_VERSION=1.32.1

This could create a diff in the goreleaser config file every time there's an upgrade.

Perhaps we could simplify our approach here and rely entirely on environment variables at build time, instead of changing values in a file. 🤔

Am I missing something? Let me know your thoughts on this.

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

Comment on lines +210 to 213
@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
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.

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!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@camilamacedo86 I ran make install after the changes in this PR and the version was still there:

$ 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"}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also ran make generate then goreleaser again, to double-check and the version was there too:

$ 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"}

Copy link
Member

Choose a reason for hiding this comment

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

Great !!!
So, it seems that it is missing to be checked only for item (b) above. How does that work when we try to install the module using the latest commit? How that will be if we do not set the fixed version in the cmd/version.go?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@camilamacedo86 If I'm replicating this correctly, go install does not inject the version into the binary:

$ 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"}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also ran go build to test the binary and got the same result:

~/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"}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@camilamacedo86 I think I see what you mean now. It seems that go install and go build do not handle ldflags correctly, or don't even access them, like it happens when running make install, hence why we need to update the .cmd/version.go file. Shoot!

Copy link
Member

Choose a reason for hiding this comment

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

Can we revert the changes in: update-k8s-version
I think the build flag change is OK .. we can move forward with

@camilamacedo86
Copy link
Member

Hi @vitorfloriano,

Sorry, I did not properly check and give a right guidance at first, see my comments:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

make generate modifies Kubernetes version permanently
3 participants