Skip to content

Commit fbe3e38

Browse files
wikkykclaude
andauthored
Move tool management from Makefile to go.mod tool (#671)
Move controller-gen, kustomize, setup-envtest, envsubst, and ginkgo from ad-hoc go install / curl-based installation in the Makefile to Go 1.24+ tool directives in go.mod. Pin their versions with replace directives matching the versions previously declared in the Makefile where necessary. This eliminates all tool download targets, LOCALBIN-based tool binary variables, and version variables from the Makefile. All tools are now invoked via `go tool <name>` which uses the module graph directly. LOCALBIN is retained only for envtest binary assets (--bin-dir). Co-authored-by: Claude <noreply@anthropic.com>
1 parent 7321e66 commit fbe3e38

File tree

3 files changed

+104
-112
lines changed

3 files changed

+104
-112
lines changed

Makefile

Lines changed: 23 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@ IMG ?= controller:latest
44
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
55
ENVTEST_K8S_VERSION = 1.30.0
66

7-
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
8-
ifeq (,$(shell go env GOBIN))
9-
GOBIN=$(shell go env GOPATH)/bin
10-
else
11-
GOBIN=$(shell go env GOBIN)
12-
endif
13-
147
# Setting SHELL to bash allows bash commands to be executed by recipes.
158
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
169
SHELL = /usr/bin/env bash -o pipefail
@@ -39,12 +32,12 @@ help: ## Display this help.
3932
##@ Development
4033

4134
.PHONY: manifests
42-
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
43-
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
35+
manifests: ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
36+
go tool controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
4437

4538
.PHONY: generate
46-
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
47-
$(CONTROLLER_GEN) object paths="./..."
39+
generate: ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
40+
go tool controller-gen object paths="./..."
4841

4942
.PHONY: fmt
5043
fmt: ## Run go fmt against code.
@@ -61,9 +54,12 @@ lint: ## Run lint.
6154
# Package names to test
6255
WHAT ?= ./...
6356

57+
## Location for envtest binary assets
58+
LOCALBIN ?= $(shell pwd)/bin
59+
6460
.PHONY: test
65-
test: manifests generate fmt vet envtest ## Run tests. Specify packages to test using WHAT.
66-
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $(WHAT) -coverprofile cover.out
61+
test: manifests generate fmt vet ## Run tests. Specify packages to test using WHAT.
62+
KUBEBUILDER_ASSETS="$(shell go tool setup-envtest use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $(WHAT) -coverprofile cover.out
6763

6864
.PHONY: mockgen
6965
mockgen: ## Generate mocks.
@@ -147,59 +143,21 @@ ifndef ignore-not-found
147143
endif
148144

149145
.PHONY: install
150-
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
151-
$(KUSTOMIZE) build config/crd | kubectl apply -f -
146+
install: manifests ## Install CRDs into the K8s cluster specified in ~/.kube/config.
147+
go tool kustomize build config/crd | kubectl apply -f -
152148

153149
.PHONY: uninstall
154-
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
155-
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
150+
uninstall: manifests ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
151+
go tool kustomize build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
156152

157153
.PHONY: deploy
158-
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
159-
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
160-
$(KUSTOMIZE) build config/default | kubectl apply -f -
154+
deploy: manifests ## Deploy controller to the K8s cluster specified in ~/.kube/config.
155+
cd config/manager && go tool kustomize edit set image controller=${IMG}
156+
go tool kustomize build config/default | kubectl apply -f -
161157

162158
.PHONY: undeploy
163159
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
164-
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
165-
166-
##@ Build Dependencies
167-
168-
## Location to install dependencies to
169-
LOCALBIN ?= $(shell pwd)/bin
170-
$(LOCALBIN):
171-
mkdir -p $(LOCALBIN)
172-
173-
## Tool Binaries
174-
KUSTOMIZE ?= $(LOCALBIN)/kustomize
175-
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
176-
ENVTEST ?= $(LOCALBIN)/setup-envtest
177-
178-
## Tool Versions
179-
KUSTOMIZE_VERSION ?= v5.0.0
180-
CONTROLLER_TOOLS_VERSION ?= v0.16.5
181-
ENVTEST_VERSION ?= 42a14a36c13b95dd6bc8b4ba69c181b16d50e3c0 # last version to support go1.24
182-
183-
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
184-
.PHONY: kustomize
185-
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
186-
$(KUSTOMIZE): $(LOCALBIN)
187-
@if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZE_VERSION); then \
188-
echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \
189-
rm -rf $(LOCALBIN)/kustomize; \
190-
fi
191-
test -s $(LOCALBIN)/kustomize || { curl -Ss $(KUSTOMIZE_INSTALL_SCRIPT) --output install_kustomize.sh && bash install_kustomize.sh $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); rm install_kustomize.sh; }
192-
193-
.PHONY: controller-gen
194-
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
195-
$(CONTROLLER_GEN): $(LOCALBIN)
196-
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
197-
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
198-
199-
.PHONY: envtest
200-
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
201-
$(ENVTEST): $(LOCALBIN)
202-
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@$(ENVTEST_VERSION)
160+
go tool kustomize build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
203161

204162
##@ Test
205163

@@ -251,13 +209,13 @@ RELEASE_VERSION ?= v0.0.1
251209

252210
.PHONY: release-manifests
253211
RELEASE_MANIFEST_SOURCE_BASE ?= config/default
254-
release-manifests: $(KUSTOMIZE) ## Create kustomized release manifest in $RELEASE_DIR (defaults to out).
212+
release-manifests: ## Create kustomized release manifest in $RELEASE_DIR (defaults to out).
255213
@mkdir -p $(RELEASE_DIR)
256214
cp metadata.yaml $(RELEASE_DIR)/metadata.yaml
257215
## change the image tag to the release version
258-
cd $(RELEASE_MANIFEST_SOURCE_BASE) && $(KUSTOMIZE) edit set image $(REPOSITORY):$(RELEASE_VERSION)
216+
cd $(RELEASE_MANIFEST_SOURCE_BASE) && go tool kustomize edit set image $(REPOSITORY):$(RELEASE_VERSION)
259217
## generate the release manifest
260-
$(KUSTOMIZE) build $(RELEASE_MANIFEST_SOURCE_BASE) > $(RELEASE_DIR)/infrastructure-components.yaml
218+
go tool kustomize build $(RELEASE_MANIFEST_SOURCE_BASE) > $(RELEASE_DIR)/infrastructure-components.yaml
261219

262220
.PHONY: release-templates
263221
release-templates: ## Generate release templates
@@ -289,30 +247,14 @@ ARTIFACTS ?= $(ROOT_DIR)/_artifacts
289247
SKIP_CLEANUP ?= false
290248
SKIP_CREATE_MGMT_CLUSTER ?= false
291249

292-
# Install tools
293-
294-
GINKGO_BIN := ginkgo
295-
GINKGO := $(LOCALBIN)/$(GINKGO_BIN)
296-
297-
ENVSUBST_VER := v1.4.2
298-
ENVSUBST_BIN := envsubst
299-
ENVSUBST := $(LOCALBIN)/$(ENVSUBST_BIN)
300-
301-
$(ENVSUBST): ## Build envsubst.
302-
test -s $(LOCALBIN)/$(ENVSUBST_BIN) || \
303-
GOBIN=$(LOCALBIN) go install github.com/a8m/envsubst/cmd/envsubst@$(ENVSUBST_VER)
304-
305-
$(GINKGO): ## Build ginkgo.
306-
GOBIN=$(LOCALBIN) go install github.com/onsi/ginkgo/v2/ginkgo
307-
308250
.PHONY: e2e-image
309251
e2e-image:
310252
docker build --tag="$(REPOSITORY):e2e" .
311253

312254
.PHONY: test-e2e
313-
test-e2e: $(ENVSUBST) $(KUBECTL) $(GINKGO) kustomize e2e-image ## Run the end-to-end tests
314-
$(ENVSUBST) < $(E2E_CONF_FILE) > $(E2E_CONF_FILE_ENVSUBST) && \
315-
time $(GINKGO) -v --trace -poll-progress-after=$(GINKGO_POLL_PROGRESS_AFTER) -poll-progress-interval=$(GINKGO_POLL_PROGRESS_INTERVAL) \
255+
test-e2e: e2e-image ## Run the end-to-end tests
256+
go tool envsubst < $(E2E_CONF_FILE) > $(E2E_CONF_FILE_ENVSUBST) && \
257+
time go tool ginkgo -v --trace -poll-progress-after=$(GINKGO_POLL_PROGRESS_AFTER) -poll-progress-interval=$(GINKGO_POLL_PROGRESS_INTERVAL) \
316258
--tags=e2e --focus="$(GINKGO_FOCUS)" -skip="$(GINKGO_SKIP)" --nodes=$(GINKGO_NODES) --no-color=$(GINKGO_NOCOLOR) \
317259
--timeout=$(GINKGO_TIMEOUT) --output-dir="$(ARTIFACTS)" --junit-report="junit.e2e_suite.1.xml" --fail-fast $(GINKGO_ARGS) ./test/e2e -- \
318260
-e2e.artifacts-folder="$(ARTIFACTS)" \

go.mod

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ go 1.25.0
44

55
replace (
66
github.com/golangci/golangci-lint/v2 => github.com/golangci/golangci-lint/v2 v2.9.0
7-
github.com/google/yamlfmt => github.com/google/yamlfmt v0.21.0
8-
github.com/vektra/mockery/v2 => github.com/vektra/mockery/v2 v2.53.6
7+
k8s.io/apimachinery => k8s.io/apimachinery v0.32.3 // temp override until everything is migrated to k8s 33
8+
k8s.io/kube-openapi/pkg/schemaconv => k8s.io/kube-openapi/pkg/schemaconv v0.0.0-20250701173324-9bd5c66d9911 // temp override until everything is migrated to k8s 33 (34?)
99
sigs.k8s.io/cluster-api => sigs.k8s.io/cluster-api v1.10.4
10+
sigs.k8s.io/controller-runtime/tools/setup-envtest => sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20250911081535-42a14a36c13b // last version to support go1.24, don't update until we're on k8s 34
11+
sigs.k8s.io/controller-tools => sigs.k8s.io/controller-tools v0.16.5
1012
)
1113

1214
require (
@@ -24,21 +26,26 @@ require (
2426
go4.org/netipx v0.0.0-20231129151722-fdeea329fbba
2527
golang.org/x/tools v0.42.0
2628
k8s.io/api v0.32.3
27-
k8s.io/apimachinery v0.32.3
29+
k8s.io/apimachinery v0.34.1
2830
k8s.io/client-go v0.32.3
2931
k8s.io/klog/v2 v2.130.1
30-
k8s.io/utils v0.0.0-20241210054802-24370beab758
32+
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397
3133
sigs.k8s.io/cluster-api v1.10.4
3234
sigs.k8s.io/cluster-api-ipam-provider-in-cluster v1.0.3
3335
sigs.k8s.io/cluster-api/test v1.10.4
3436
sigs.k8s.io/controller-runtime v0.20.4
3537
)
3638

3739
tool (
40+
github.com/a8m/envsubst/cmd/envsubst
3841
github.com/golangci/golangci-lint/v2/cmd/golangci-lint
3942
github.com/google/yamlfmt/cmd/yamlfmt
43+
github.com/onsi/ginkgo/v2/ginkgo
4044
github.com/vektra/mockery/v2
4145
golang.org/x/tools/cmd/goimports
46+
sigs.k8s.io/controller-runtime/tools/setup-envtest
47+
sigs.k8s.io/controller-tools/cmd/controller-gen
48+
sigs.k8s.io/kustomize/kustomize/v5
4249
)
4350

4451
require (
@@ -69,6 +76,7 @@ require (
6976
github.com/NYTimes/gziphandler v1.1.1 // indirect
7077
github.com/OpenPeeDeeP/depguard/v2 v2.2.1 // indirect
7178
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
79+
github.com/a8m/envsubst v1.4.3 // indirect
7280
github.com/adrg/xdg v0.5.3 // indirect
7381
github.com/ajeddeloh/go-json v0.0.0-20200220154158-5ae607161559 // indirect
7482
github.com/alecthomas/chroma/v2 v2.23.1 // indirect
@@ -131,10 +139,11 @@ require (
131139
github.com/felixge/httpsnoop v1.0.4 // indirect
132140
github.com/firefart/nonamedreturns v1.0.6 // indirect
133141
github.com/fsnotify/fsnotify v1.9.0 // indirect
134-
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
142+
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
135143
github.com/fzipp/gocyclo v0.6.0 // indirect
136144
github.com/ghostiam/protogetter v0.3.20 // indirect
137145
github.com/go-critic/go-critic v0.14.3 // indirect
146+
github.com/go-errors/errors v1.4.2 // indirect
138147
github.com/go-logr/stdr v1.2.2 // indirect
139148
github.com/go-logr/zapr v1.3.0 // indirect
140149
github.com/go-openapi/jsonpointer v0.21.0 // indirect
@@ -169,7 +178,7 @@ require (
169178
github.com/golangci/unconvert v0.0.0-20250410112200-a129a6e6413e // indirect
170179
github.com/google/btree v1.1.3 // indirect
171180
github.com/google/cel-go v0.22.0 // indirect
172-
github.com/google/gnostic-models v0.6.8 // indirect
181+
github.com/google/gnostic-models v0.7.0 // indirect
173182
github.com/google/go-github/v53 v53.2.0 // indirect
174183
github.com/google/go-querystring v1.1.0 // indirect
175184
github.com/google/gofuzz v1.2.0 // indirect
@@ -229,7 +238,8 @@ require (
229238
github.com/mitchellh/reflectwalk v1.0.2 // indirect
230239
github.com/moby/docker-image-spec v1.3.1 // indirect
231240
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
232-
github.com/modern-go/reflect2 v1.0.2 // indirect
241+
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
242+
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
233243
github.com/moricho/tparallel v0.3.2 // indirect
234244
github.com/muesli/termenv v0.16.0 // indirect
235245
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
@@ -265,6 +275,7 @@ require (
265275
github.com/sashamelentyev/interfacebloat v1.1.0 // indirect
266276
github.com/sashamelentyev/usestdlibvars v1.29.0 // indirect
267277
github.com/securego/gosec/v2 v2.22.11 // indirect
278+
github.com/sergi/go-diff v1.4.0 // indirect
268279
github.com/shopspring/decimal v1.4.0 // indirect
269280
github.com/sirupsen/logrus v1.9.4 // indirect
270281
github.com/sivchari/containedctx v1.0.3 // indirect
@@ -293,6 +304,7 @@ require (
293304
github.com/vincent-petithory/dataurl v1.0.0 // indirect
294305
github.com/x448/float16 v0.8.4 // indirect
295306
github.com/xen0n/gosmopolitan v1.3.0 // indirect
307+
github.com/xlab/treeprint v1.2.0 // indirect
296308
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
297309
github.com/yagipy/maintidx v1.0.0 // indirect
298310
github.com/yeya24/promlinter v0.3.0 // indirect
@@ -327,26 +339,34 @@ require (
327339
golang.org/x/telemetry v0.0.0-20260209163413-e7419c687ee4 // indirect
328340
golang.org/x/term v0.40.0 // indirect
329341
golang.org/x/text v0.34.0 // indirect
330-
golang.org/x/time v0.8.0 // indirect
342+
golang.org/x/time v0.9.0 // indirect
331343
gomodules.xyz/jsonpatch/v2 v2.5.0 // indirect
332344
google.golang.org/genproto/googleapis/api v0.0.0-20250707201910-8d1bb00bc6a7 // indirect
333345
google.golang.org/genproto/googleapis/rpc v0.0.0-20250818200422-3122310a409c // indirect
334346
google.golang.org/grpc v1.75.0 // indirect
335347
google.golang.org/protobuf v1.36.8 // indirect
336-
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
348+
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
337349
gopkg.in/inf.v0 v0.9.1 // indirect
350+
gopkg.in/yaml.v2 v2.4.0 // indirect
338351
gopkg.in/yaml.v3 v3.0.1 // indirect
339352
honnef.co/go/tools v0.6.1 // indirect
340353
k8s.io/apiextensions-apiserver v0.32.3 // indirect
341354
k8s.io/apiserver v0.32.3 // indirect
342355
k8s.io/cluster-bootstrap v0.32.3 // indirect
343356
k8s.io/component-base v0.32.3 // indirect
344-
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
357+
k8s.io/kube-openapi v0.0.0-20250701173324-9bd5c66d9911 // indirect
345358
mvdan.cc/gofumpt v0.9.2 // indirect
346359
mvdan.cc/unparam v0.0.0-20251027182757-5beb8c8f8f15 // indirect
347360
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.0 // indirect
348-
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
361+
sigs.k8s.io/controller-runtime/tools/setup-envtest v0.0.0-20260305141020-105baa6284da // indirect
362+
sigs.k8s.io/controller-tools v0.16.5 // indirect
363+
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
349364
sigs.k8s.io/kind v0.27.0 // indirect
350-
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
365+
sigs.k8s.io/kustomize/api v0.21.1 // indirect
366+
sigs.k8s.io/kustomize/cmd/config v0.21.1 // indirect
367+
sigs.k8s.io/kustomize/kustomize/v5 v5.8.1 // indirect
368+
sigs.k8s.io/kustomize/kyaml v0.21.1 // indirect
369+
sigs.k8s.io/randfill v1.0.0 // indirect
370+
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect
351371
sigs.k8s.io/yaml v1.6.0 // indirect
352372
)

0 commit comments

Comments
 (0)