Skip to content

Commit 4c77ebe

Browse files
🐛 fix controller-runtime setupenv incompability with old versions
1 parent 011383c commit 4c77ebe

File tree

11 files changed

+45
-14
lines changed

11 files changed

+45
-14
lines changed

docs/book/src/component-config-tutorial/testdata/project/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
166166
## Tool Versions
167167
KUSTOMIZE_VERSION ?= v5.3.0
168168
CONTROLLER_TOOLS_VERSION ?= v0.14.0
169-
ENVTEST_VERSION ?= latest
169+
ENVTEST_VERSION ?= release-0.17
170170
GOLANGCI_LINT_VERSION ?= v1.54.2
171171

172172
.PHONY: kustomize

docs/book/src/cronjob-tutorial/testdata/project/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
166166
## Tool Versions
167167
KUSTOMIZE_VERSION ?= v5.3.0
168168
CONTROLLER_TOOLS_VERSION ?= v0.14.0
169-
ENVTEST_VERSION ?= latest
169+
ENVTEST_VERSION ?= release-0.17
170170
GOLANGCI_LINT_VERSION ?= v1.54.2
171171

172172
.PHONY: kustomize

docs/book/src/getting-started/testdata/project/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
166166
## Tool Versions
167167
KUSTOMIZE_VERSION ?= v5.3.0
168168
CONTROLLER_TOOLS_VERSION ?= v0.14.0
169-
ENVTEST_VERSION ?= latest
169+
ENVTEST_VERSION ?= release-0.17
170170
GOLANGCI_LINT_VERSION ?= v1.54.2
171171

172172
.PHONY: kustomize

pkg/plugins/golang/v4/scaffolds/init.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ limitations under the License.
1717
package scaffolds
1818

1919
import (
20+
"fmt"
21+
"strings"
22+
2023
log "github.com/sirupsen/logrus"
2124
"github.com/spf13/afero"
2225
"sigs.k8s.io/kubebuilder/v3/pkg/config"
@@ -71,6 +74,20 @@ func (s *initScaffolder) InjectFS(fs machinery.Filesystem) {
7174
s.fs = fs
7275
}
7376

77+
// getControllerRuntimeReleaseBranch converts the ControllerRuntime semantic versioning string to a
78+
// release branch string. Example input: "v0.17.0" -> Output: "release-0.17"
79+
func getControllerRuntimeReleaseBranch() string {
80+
v := strings.TrimPrefix(ControllerRuntimeVersion, "v")
81+
tmp := strings.Split(v, ".")
82+
83+
if len(tmp) < 2 {
84+
fmt.Println("Invalid version format. Expected at least major and minor version numbers.")
85+
return ""
86+
}
87+
releaseBranch := fmt.Sprintf("release-%s.%s", tmp[0], tmp[1])
88+
return releaseBranch
89+
}
90+
7491
// Scaffold implements cmdutil.Scaffolder
7592
func (s *initScaffolder) Scaffold() error {
7693
log.Println("Writing scaffold for you to edit...")
@@ -136,6 +153,7 @@ func (s *initScaffolder) Scaffold() error {
136153
ControllerToolsVersion: ControllerToolsVersion,
137154
KustomizeVersion: kustomizeVersion,
138155
ControllerRuntimeVersion: ControllerRuntimeVersion,
156+
EnvtestVersion: getControllerRuntimeReleaseBranch(),
139157
},
140158
&templates.Dockerfile{},
141159
&templates.DockerIgnore{},

pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,15 @@ func (f *Makefile) SetTemplateDefaults() error {
5656
f.Image = "controller:latest"
5757
}
5858

59-
// TODO: Looking for ways to tag the controller-runtime
60-
// release using tag versions. Note that we cannot
61-
// relay upon the branch since we cannot ensure that
62-
// it will be generated for all releases. We must be
63-
// able to use the tag.
59+
// TODO: Current workaround for setup-envtest compatibility
60+
// Due to past instances where controller-runtime maintainers released
61+
// versions without corresponding branches, directly relying on branches
62+
// poses a risk of breaking the Kubebuilder chain. Such practices may
63+
// change over time, potentially leading to compatibility issues. This
64+
// approach, although not ideal, remains the best solution for ensuring
65+
// compatibility with controller-runtime releases as of now. For more
66+
// details on the quest for a more robust solution, refer to the issue
67+
// raised in the controller-runtime repository: https://github.com/kubernetes-sigs/controller-runtime/issues/2744
6468
if f.EnvtestVersion == "" {
6569
f.EnvtestVersion = "latest"
6670
}

test/common.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,16 @@ function fetch_tools {
114114
if ! is_installed setup-envtest; then
115115
header_text "Installing setup-envtest to $(go env GOPATH)/bin"
116116

117-
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
117+
# TODO: Current workaround for setup-envtest compatibility
118+
# Due to past instances where controller-runtime maintainers released
119+
# versions without corresponding branches, directly relying on branches
120+
# poses a risk of breaking the Kubebuilder chain. Such practices may
121+
# change over time, potentially leading to compatibility issues. This
122+
# approach, although not ideal, remains the best solution for ensuring
123+
# compatibility with controller-runtime releases as of now. For more
124+
# details on the quest for a more robust solution, refer to the issue
125+
# raised in the controller-runtime repository: https://github.com/kubernetes-sigs/controller-runtime/issues/2744
126+
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@release-0.17
118127
fi
119128

120129
if [ -z "$SKIP_FETCH_TOOLS" ]; then

testdata/project-v4-multigroup-with-deploy-image/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
166166
## Tool Versions
167167
KUSTOMIZE_VERSION ?= v5.3.0
168168
CONTROLLER_TOOLS_VERSION ?= v0.14.0
169-
ENVTEST_VERSION ?= latest
169+
ENVTEST_VERSION ?= release-0.17
170170
GOLANGCI_LINT_VERSION ?= v1.54.2
171171

172172
.PHONY: kustomize

testdata/project-v4-multigroup/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
166166
## Tool Versions
167167
KUSTOMIZE_VERSION ?= v5.3.0
168168
CONTROLLER_TOOLS_VERSION ?= v0.14.0
169-
ENVTEST_VERSION ?= latest
169+
ENVTEST_VERSION ?= release-0.17
170170
GOLANGCI_LINT_VERSION ?= v1.54.2
171171

172172
.PHONY: kustomize

testdata/project-v4-with-deploy-image/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
166166
## Tool Versions
167167
KUSTOMIZE_VERSION ?= v5.3.0
168168
CONTROLLER_TOOLS_VERSION ?= v0.14.0
169-
ENVTEST_VERSION ?= latest
169+
ENVTEST_VERSION ?= release-0.17
170170
GOLANGCI_LINT_VERSION ?= v1.54.2
171171

172172
.PHONY: kustomize

testdata/project-v4-with-grafana/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
166166
## Tool Versions
167167
KUSTOMIZE_VERSION ?= v5.3.0
168168
CONTROLLER_TOOLS_VERSION ?= v0.14.0
169-
ENVTEST_VERSION ?= latest
169+
ENVTEST_VERSION ?= release-0.17
170170
GOLANGCI_LINT_VERSION ?= v1.54.2
171171

172172
.PHONY: kustomize

0 commit comments

Comments
 (0)