diff --git a/docs/book/src/component-config-tutorial/testdata/project/Makefile b/docs/book/src/component-config-tutorial/testdata/project/Makefile index c38d0294813..36c5471b0b8 100644 --- a/docs/book/src/component-config-tutorial/testdata/project/Makefile +++ b/docs/book/src/component-config-tutorial/testdata/project/Makefile @@ -166,7 +166,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION) ## Tool Versions KUSTOMIZE_VERSION ?= v5.3.0 CONTROLLER_TOOLS_VERSION ?= v0.14.0 -ENVTEST_VERSION ?= latest +ENVTEST_VERSION ?= release-0.14 GOLANGCI_LINT_VERSION ?= v1.54.2 .PHONY: kustomize diff --git a/docs/book/src/cronjob-tutorial/testdata/project/Makefile b/docs/book/src/cronjob-tutorial/testdata/project/Makefile index c38d0294813..36c5471b0b8 100644 --- a/docs/book/src/cronjob-tutorial/testdata/project/Makefile +++ b/docs/book/src/cronjob-tutorial/testdata/project/Makefile @@ -166,7 +166,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION) ## Tool Versions KUSTOMIZE_VERSION ?= v5.3.0 CONTROLLER_TOOLS_VERSION ?= v0.14.0 -ENVTEST_VERSION ?= latest +ENVTEST_VERSION ?= release-0.14 GOLANGCI_LINT_VERSION ?= v1.54.2 .PHONY: kustomize diff --git a/docs/book/src/getting-started/testdata/project/Makefile b/docs/book/src/getting-started/testdata/project/Makefile index c38d0294813..36c5471b0b8 100644 --- a/docs/book/src/getting-started/testdata/project/Makefile +++ b/docs/book/src/getting-started/testdata/project/Makefile @@ -166,7 +166,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION) ## Tool Versions KUSTOMIZE_VERSION ?= v5.3.0 CONTROLLER_TOOLS_VERSION ?= v0.14.0 -ENVTEST_VERSION ?= latest +ENVTEST_VERSION ?= release-0.14 GOLANGCI_LINT_VERSION ?= v1.54.2 .PHONY: kustomize diff --git a/pkg/plugins/golang/v4/scaffolds/init.go b/pkg/plugins/golang/v4/scaffolds/init.go index a9f673be494..42d7c9f8371 100644 --- a/pkg/plugins/golang/v4/scaffolds/init.go +++ b/pkg/plugins/golang/v4/scaffolds/init.go @@ -17,6 +17,7 @@ limitations under the License. package scaffolds import ( + "fmt" log "github.com/sirupsen/logrus" "github.com/spf13/afero" "sigs.k8s.io/kubebuilder/v3/pkg/config" @@ -29,6 +30,7 @@ import ( "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v4/scaffolds/internal/templates/hack" "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v4/scaffolds/internal/templates/test/e2e" "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v4/scaffolds/internal/templates/test/utils" + "strings" ) const ( @@ -71,6 +73,20 @@ func (s *initScaffolder) InjectFS(fs machinery.Filesystem) { s.fs = fs } +// getControllerRuntimeReleaseBranch converts the ControllerRuntime semantic versioning string to a release branch string. +// Example input: "v0.17.0" -> Output: "release-0.17" +func getControllerRuntimeReleaseBranch() string { + v := strings.TrimPrefix(ControllerToolsVersion, "v") + tmp := strings.Split(v, ".") + + if len(tmp) < 2 { + fmt.Println("Invalid version format. Expected at least major and minor version numbers.") + return "" + } + releaseBranch := fmt.Sprintf("release-%s.%s", tmp[0], tmp[1]) + return releaseBranch +} + // Scaffold implements cmdutil.Scaffolder func (s *initScaffolder) Scaffold() error { log.Println("Writing scaffold for you to edit...") @@ -136,6 +152,7 @@ func (s *initScaffolder) Scaffold() error { ControllerToolsVersion: ControllerToolsVersion, KustomizeVersion: kustomizeVersion, ControllerRuntimeVersion: ControllerRuntimeVersion, + EnvtestVersion: getControllerRuntimeReleaseBranch(), }, &templates.Dockerfile{}, &templates.DockerIgnore{}, diff --git a/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go b/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go index 870aae7f59a..af077909321 100644 --- a/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go +++ b/pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go @@ -56,11 +56,15 @@ func (f *Makefile) SetTemplateDefaults() error { f.Image = "controller:latest" } - // TODO: Looking for ways to tag the controller-runtime - // release using tag versions. Note that we cannot - // relay upon the branch since we cannot ensure that - // it will be generated for all releases. We must be - // able to use the tag. + // TODO: Current workaround for setup-envtest compatibility + // Due to past instances where controller-runtime maintainers released + // versions without corresponding branches, directly relying on branches + // poses a risk of breaking the Kubebuilder chain. Such practices may + // change over time, potentially leading to compatibility issues. This + // approach, although not ideal, remains the best solution for ensuring + // compatibility with controller-runtime releases as of now. For more + // details on the quest for a more robust solution, refer to the issue + // raised in the controller-runtime repository: https://github.com/kubernetes-sigs/controller-runtime/issues/2744 if f.EnvtestVersion == "" { f.EnvtestVersion = "latest" } diff --git a/test/common.sh b/test/common.sh index e9430481f12..582203cd913 100644 --- a/test/common.sh +++ b/test/common.sh @@ -114,7 +114,16 @@ function fetch_tools { if ! is_installed setup-envtest; then header_text "Installing setup-envtest to $(go env GOPATH)/bin" - go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest + # TODO: Current workaround for setup-envtest compatibility + # Due to past instances where controller-runtime maintainers released + # versions without corresponding branches, directly relying on branches + # poses a risk of breaking the Kubebuilder chain. Such practices may + # change over time, potentially leading to compatibility issues. This + # approach, although not ideal, remains the best solution for ensuring + # compatibility with controller-runtime releases as of now. For more + # details on the quest for a more robust solution, refer to the issue + # raised in the controller-runtime repository: https://github.com/kubernetes-sigs/controller-runtime/issues/2744 + go install sigs.k8s.io/controller-runtime/tools/setup-envtest@release-0.17 fi if [ -z "$SKIP_FETCH_TOOLS" ]; then diff --git a/testdata/project-v4-multigroup-with-deploy-image/Makefile b/testdata/project-v4-multigroup-with-deploy-image/Makefile index c38d0294813..36c5471b0b8 100644 --- a/testdata/project-v4-multigroup-with-deploy-image/Makefile +++ b/testdata/project-v4-multigroup-with-deploy-image/Makefile @@ -166,7 +166,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION) ## Tool Versions KUSTOMIZE_VERSION ?= v5.3.0 CONTROLLER_TOOLS_VERSION ?= v0.14.0 -ENVTEST_VERSION ?= latest +ENVTEST_VERSION ?= release-0.14 GOLANGCI_LINT_VERSION ?= v1.54.2 .PHONY: kustomize diff --git a/testdata/project-v4-multigroup/Makefile b/testdata/project-v4-multigroup/Makefile index c38d0294813..36c5471b0b8 100644 --- a/testdata/project-v4-multigroup/Makefile +++ b/testdata/project-v4-multigroup/Makefile @@ -166,7 +166,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION) ## Tool Versions KUSTOMIZE_VERSION ?= v5.3.0 CONTROLLER_TOOLS_VERSION ?= v0.14.0 -ENVTEST_VERSION ?= latest +ENVTEST_VERSION ?= release-0.14 GOLANGCI_LINT_VERSION ?= v1.54.2 .PHONY: kustomize diff --git a/testdata/project-v4-with-deploy-image/Makefile b/testdata/project-v4-with-deploy-image/Makefile index c38d0294813..36c5471b0b8 100644 --- a/testdata/project-v4-with-deploy-image/Makefile +++ b/testdata/project-v4-with-deploy-image/Makefile @@ -166,7 +166,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION) ## Tool Versions KUSTOMIZE_VERSION ?= v5.3.0 CONTROLLER_TOOLS_VERSION ?= v0.14.0 -ENVTEST_VERSION ?= latest +ENVTEST_VERSION ?= release-0.14 GOLANGCI_LINT_VERSION ?= v1.54.2 .PHONY: kustomize diff --git a/testdata/project-v4-with-grafana/Makefile b/testdata/project-v4-with-grafana/Makefile index c38d0294813..36c5471b0b8 100644 --- a/testdata/project-v4-with-grafana/Makefile +++ b/testdata/project-v4-with-grafana/Makefile @@ -166,7 +166,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION) ## Tool Versions KUSTOMIZE_VERSION ?= v5.3.0 CONTROLLER_TOOLS_VERSION ?= v0.14.0 -ENVTEST_VERSION ?= latest +ENVTEST_VERSION ?= release-0.14 GOLANGCI_LINT_VERSION ?= v1.54.2 .PHONY: kustomize diff --git a/testdata/project-v4/Makefile b/testdata/project-v4/Makefile index c38d0294813..36c5471b0b8 100644 --- a/testdata/project-v4/Makefile +++ b/testdata/project-v4/Makefile @@ -166,7 +166,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION) ## Tool Versions KUSTOMIZE_VERSION ?= v5.3.0 CONTROLLER_TOOLS_VERSION ?= v0.14.0 -ENVTEST_VERSION ?= latest +ENVTEST_VERSION ?= release-0.14 GOLANGCI_LINT_VERSION ?= v1.54.2 .PHONY: kustomize