Skip to content

Commit 56d99d7

Browse files
authored
Merge pull request #5741 from kaitoii11/temp-gomod
🌱 Install hack/tools with temporary go module
2 parents f8f6583 + 7de8c01 commit 56d99d7

File tree

9 files changed

+204
-568
lines changed

9 files changed

+204
-568
lines changed

Makefile

Lines changed: 109 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,10 @@ EXP_DIR := exp
5555
BIN_DIR := bin
5656
TEST_DIR := test
5757
TOOLS_DIR := hack/tools
58-
TOOLS_BIN_DIR := $(TOOLS_DIR)/$(BIN_DIR)
58+
TOOLS_BIN_DIR := $(abspath $(TOOLS_DIR)/$(BIN_DIR))
5959
E2E_FRAMEWORK_DIR := $(TEST_DIR)/framework
6060
CAPD_DIR := $(TEST_DIR)/infrastructure/docker
61-
GO_APIDIFF_BIN := $(BIN_DIR)/go-apidiff
62-
GO_APIDIFF := $(TOOLS_DIR)/$(GO_APIDIFF_BIN)
63-
KPROMO_BIN := $(BIN_DIR)/kpromo
64-
KPROMO := $(TOOLS_DIR)/$(KPROMO_BIN)
65-
ENVSUBST_BIN := $(BIN_DIR)/envsubst
66-
ENVSUBST := $(TOOLS_DIR)/$(ENVSUBST_BIN)
61+
GO_INSTALL := ./scripts/go_install.sh
6762

6863
export PATH := $(abspath $(TOOLS_BIN_DIR)):$(PATH)
6964

@@ -78,15 +73,56 @@ endif
7873
# Binaries.
7974
#
8075
# Note: Need to use abspath so we can invoke these from subdirectories
81-
KUSTOMIZE := $(abspath $(TOOLS_BIN_DIR)/kustomize)
82-
SETUP_ENVTEST := $(abspath $(TOOLS_BIN_DIR)/setup-envtest)
83-
CONTROLLER_GEN := $(abspath $(TOOLS_BIN_DIR)/controller-gen)
84-
GOTESTSUM := $(abspath $(TOOLS_BIN_DIR)/gotestsum)
85-
GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/golangci-lint)
86-
CONVERSION_GEN := $(abspath $(TOOLS_BIN_DIR)/conversion-gen)
87-
CONVERSION_VERIFIER := $(abspath $(TOOLS_BIN_DIR)/conversion-verifier)
88-
TILT_PREPARE := $(abspath $(TOOLS_BIN_DIR)/tilt-prepare)
89-
ENVSUBST := $(abspath $(TOOLS_BIN_DIR)/envsubst)
76+
KUSTOMIZE_VER := v4.4.1
77+
KUSTOMIZE_BIN := kustomize
78+
KUSTOMIZE := $(abspath $(TOOLS_BIN_DIR)/$(KUSTOMIZE_BIN)-$(KUSTOMIZE_VER))
79+
KUSTOMIZE_PKG := sigs.k8s.io/kustomize/kustomize/v4
80+
81+
SETUP_ENVTEST_VER := v0.0.0-20211110210527-619e6b92dab9
82+
SETUP_ENVTEST_BIN := setup-envtest
83+
SETUP_ENVTEST := $(abspath $(TOOLS_BIN_DIR)/$(SETUP_ENVTEST_BIN)-$(SETUP_ENVTEST_VER))
84+
SETUP_ENVTEST_PKG := sigs.k8s.io/controller-runtime/tools/setup-envtest
85+
86+
CONTROLLER_GEN_VER := v0.8.0
87+
CONTROLLER_GEN_BIN := controller-gen
88+
CONTROLLER_GEN := $(abspath $(TOOLS_BIN_DIR)/$(CONTROLLER_GEN_BIN)-$(CONTROLLER_GEN_VER))
89+
CONTROLLER_GEN_PKG := sigs.k8s.io/controller-tools/cmd/controller-gen
90+
91+
GOTESTSUM_VER := v1.6.4
92+
GOTESTSUM_BIN := gotestsum
93+
GOTESTSUM := $(abspath $(TOOLS_BIN_DIR)/$(GOTESTSUM_BIN)-$(GOTESTSUM_VER))
94+
GOTESTSUM_PKG := gotest.tools/gotestsum
95+
96+
CONVERSION_GEN_VER := v0.23.1
97+
CONVERSION_GEN_BIN := conversion-gen
98+
# We are intentionally using the binary without version suffix, to avoid the version
99+
# in generated files.
100+
CONVERSION_GEN := $(abspath $(TOOLS_BIN_DIR)/$(CONVERSION_GEN_BIN))
101+
CONVERSION_GEN_PKG := k8s.io/code-generator/cmd/conversion-gen
102+
103+
ENVSUBST_VER := v2.0.0-20210730161058-179042472c46
104+
ENVSUBST_BIN := envsubst
105+
ENVSUBST := $(abspath $(TOOLS_BIN_DIR)/$(ENVSUBST_BIN)-$(ENVSUBST_VER))
106+
ENVSUBST_PKG := github.com/drone/envsubst/v2/cmd/envsubst
107+
108+
GO_APIDIFF_VER := v0.1.0
109+
GO_APIDIFF_BIN := go-apidiff
110+
GO_APIDIFF := $(abspath $(TOOLS_BIN_DIR)/$(GO_APIDIFF_BIN)-$(GO_APIDIFF_VER))
111+
GO_APIDIFF_PKG := github.com/joelanford/go-apidiff
112+
113+
KPROMO_VER := v3.3.0-beta.3
114+
KPROMO_BIN := kpromo
115+
KPROMO := $(abspath $(TOOLS_BIN_DIR)/$(KPROMO_BIN)-$(KPROMO_VER))
116+
KPROMO_PKG := sigs.k8s.io/promo-tools/v3/cmd/kpromo
117+
118+
CONVERSION_VERIFIER_BIN := conversion-verifier
119+
CONVERSION_VERIFIER := $(abspath $(TOOLS_BIN_DIR)/$(CONVERSION_VERIFIER_BIN))
120+
121+
TILT_PREPARE_BIN := tilt-prepare
122+
TILT_PREPARE := $(abspath $(TOOLS_BIN_DIR)/$(TILT_PREPARE_BIN))
123+
124+
GOLANGCI_LINT_BIN := golangci-lint
125+
GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN))
90126

91127
# clusterctl.
92128
CLUSTERCTL_MANIFEST_DIR := cmd/clusterctl/config
@@ -111,6 +147,7 @@ KUBEADM_CONTROL_PLANE_IMAGE_NAME ?= kubeadm-control-plane-controller
111147
KUBEADM_CONTROL_PLANE_CONTROLLER_IMG ?= $(REGISTRY)/$(KUBEADM_CONTROL_PLANE_IMAGE_NAME)
112148

113149
# It is set by Prow GIT_TAG, a git-based tag of the form vYYYYMMDD-hash, e.g., v20210120-v0.3.10-308-gc61521971
150+
114151
TAG ?= dev
115152
ARCH ?= $(shell go env GOARCH)
116153
ALL_ARCH = amd64 arm arm64 ppc64le s390x
@@ -407,7 +444,7 @@ ALL_DOCKER_BUILD = core kubeadm-bootstrap kubeadm-control-plane
407444

408445
.PHONY: docker-build
409446
docker-build: docker-pull-prerequisites ## Run docker-build-* targets for all providers
410-
$(MAKE) ARCH=$(ARCH) $(addprefix docker-build-,$(ALL_DOCKER_BUILD))
447+
$(MAKE) ARCH=$(ARCH) $(addprefix docker-build-,$(ALL_DOCKER_BUILD))
411448

412449
.PHONY: docker-build-core
413450
docker-build-core: ## Build the docker image for core controller manager
@@ -715,49 +752,73 @@ clean-generated-conversions: ## Remove files generated by conversion-gen from th
715752

716753
##@ hack/tools:
717754

718-
controller-gen: $(CONTROLLER_GEN) ## Build a local copy of controller-gen
719-
conversion-gen: $(CONVERSION_GEN) ## Build a local copy of conversion-gen
720-
conversion-verifier: $(CONVERSION_VERIFIER) ## Build a local copy of conversion-verifier
721-
gotestsum: $(GOTESTSUM) ## Build a local copy of gotestsum
722-
go-apidiff: $(GO_APIDIFF) ## Build a local copy of apidiff
723-
golangci-lint: $(GOLANGCI_LINT) ## Build a local copy of golangci-lint
724-
envsubst: $(ENVSUBST) ## Build a local copy of envsubst
725-
kustomize: $(KUSTOMIZE) ## Build a local copy of kustomize
726-
setup-envtest: $(SETUP_ENVTEST) ## Build a local copy of setup-envtest
727-
tilt-prepare: $(TILT_PREPARE) ## Build a local copy of tilt-prepare
728-
kpromo: $(KPROMO) ## Build a local copy of kpromo
755+
.PHONY: $(CONTROLLER_GEN_BIN)
756+
$(CONTROLLER_GEN_BIN): $(CONTROLLER_GEN) ## Build a local copy of controller-gen.
757+
758+
.PHONY: $(CONVERSION_GEN_BIN)
759+
$(CONVERSION_GEN_BIN): $(CONVERSION_GEN) ## Build a local copy of conversion-gen.
760+
761+
.PHONY: $(CONVERSION_VERIFIER_BIN)
762+
$(CONVERSION_VERIFIER_BIN): $(CONVERSION_VERIFIER) ## Build a local copy of conversion-verifier.
763+
764+
.PHONY: $(GOTESTSUM_BIN)
765+
$(GOTESTSUM_BIN): $(GOTESTSUM) ## Build a local copy of gotestsum.
766+
767+
.PHONY: $(GO_APIDIFF_BIN)
768+
$(GO_APIDIFF_BIN): $(GO_APIDIFF) ## Build a local copy of go-apidiff
769+
770+
.PHONY: $(ENVSUBST_BIN)
771+
$(ENVSUBST_BIN): $(ENVSUBST) ## Build a local copy of envsubst.
772+
773+
.PHONY: $(KUSTOMIZE_BIN)
774+
$(KUSTOMIZE_BIN): $(KUSTOMIZE) ## Build a local copy of kustomize.
775+
776+
.PHONY: $(SETUP_ENVTEST_BIN)
777+
$(SETUP_ENVTEST_BIN): $(SETUP_ENVTEST) ## Build a local copy of setup-envtest.
729778

730-
$(SETUP_ENVTEST): $(TOOLS_DIR)/go.mod # Build setup-envtest from tools folder.
731-
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/setup-envtest sigs.k8s.io/controller-runtime/tools/setup-envtest
779+
.PHONY: $(KPROMO_BIN)
780+
$(KPROMO_BIN): $(KPROMO) ## Build a local copy of kpromo
732781

733-
$(CONTROLLER_GEN): $(TOOLS_DIR)/go.mod # Build controller-gen from tools folder.
734-
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/controller-gen sigs.k8s.io/controller-tools/cmd/controller-gen
782+
.PHONY: $(TILT_PREPARE_BIN)
783+
$(TILT_PREPARE_BIN): $(TILT_PREPARE) ## Build a local copy of tilt-prepare.
735784

736-
$(GOTESTSUM): $(TOOLS_DIR)/go.mod # Build gotestsum from tools folder.
737-
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/gotestsum gotest.tools/gotestsum
785+
.PHONY: $(GOLANGCI_LINT_BIN)
786+
$(GOLANGCI_LINT_BIN): $(GOLANGCI_LINT) ## Build a local copy of golangci-lint
738787

739-
$(CONVERSION_GEN): $(TOOLS_DIR)/go.mod # Build conversion-gen from tools folder.
740-
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/conversion-gen k8s.io/code-generator/cmd/conversion-gen
788+
$(CONTROLLER_GEN): # Build controller-gen from tools folder.
789+
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(CONTROLLER_GEN_PKG) $(CONTROLLER_GEN_BIN) $(CONTROLLER_GEN_VER)
790+
791+
## We are forcing a rebuilt of conversion-gen via PHONY so that we're always using an up-to-date version.
792+
## We can't use a versioned name for the binary, because that would be reflected in generated files.
793+
.PHONY: $(CONVERSION_GEN)
794+
$(CONVERSION_GEN): # Build conversion-gen from tools folder.
795+
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(CONVERSION_GEN_PKG) $(CONVERSION_GEN_BIN) $(CONVERSION_GEN_VER)
741796

742797
$(CONVERSION_VERIFIER): $(TOOLS_DIR)/go.mod # Build conversion-verifier from tools folder.
743798
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/conversion-verifier sigs.k8s.io/cluster-api/hack/tools/conversion-verifier
744799

745-
$(TILT_PREPARE): $(TOOLS_DIR)/go.mod # Build tilt-prepare from tools folder.
746-
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/tilt-prepare sigs.k8s.io/cluster-api/hack/tools/tilt-prepare
800+
$(GOTESTSUM): # Build gotestsum from tools folder.
801+
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(GOTESTSUM_PKG) $(GOTESTSUM_BIN) $(GOTESTSUM_VER)
802+
803+
$(GO_APIDIFF): # Build go-apidiff from tools folder.
804+
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(GO_APIDIFF_PKG) $(GO_APIDIFF_BIN) $(GO_APIDIFF_VER)
747805

748-
$(GO_APIDIFF): $(TOOLS_DIR)/go.mod # Build go-apidiff from tools folder.
749-
cd $(TOOLS_DIR) && go build -tags=tools -o $(GO_APIDIFF_BIN) github.com/joelanford/go-apidiff
806+
$(ENVSUBST): # Build gotestsum from tools folder.
807+
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(ENVSUBST_PKG) $(ENVSUBST_BIN) $(ENVSUBST_VER)
750808

751-
$(ENVSUBST): $(TOOLS_DIR)/go.mod # Build envsubst from tools folder.
752-
cd $(TOOLS_DIR) && go build -tags=tools -o $(ENVSUBST_BIN) github.com/drone/envsubst/v2/cmd/envsubst
809+
$(KUSTOMIZE): # Build kustomize from tools folder.
810+
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(KUSTOMIZE_PKG) $(KUSTOMIZE_BIN) $(KUSTOMIZE_VER)
753811

754-
$(KPROMO): $(TOOLS_DIR)/go.mod # Build kpromo from tools folder.
755-
cd $(TOOLS_DIR) && go build -tags=tools -o $(KPROMO_BIN) sigs.k8s.io/promo-tools/v3/cmd/kpromo
812+
$(SETUP_ENVTEST): # Build setup-envtest from tools folder.
813+
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(SETUP_ENVTEST_PKG) $(SETUP_ENVTEST_BIN) $(SETUP_ENVTEST_VER)
814+
815+
$(TILT_PREPARE): $(TOOLS_DIR)/go.mod # Build tilt-prepare from tools folder.
816+
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/tilt-prepare sigs.k8s.io/cluster-api/hack/tools/tilt-prepare
756817

757-
$(KUSTOMIZE): # Download kustomize using hack script into tools folder.
758-
hack/ensure-kustomize.sh
818+
$(KPROMO):
819+
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(KPROMO_PKG) $(KPROMO_BIN) ${KPROMO_VER}
759820

760-
$(GOLANGCI_LINT): .github/workflows/golangci-lint.yml # Download golanci-lint using hack script into tools folder.
821+
$(GOLANGCI_LINT): .github/workflows/golangci-lint.yml # Download golangci-lint using hack script into tools folder.
761822
hack/ensure-golangci-lint.sh \
762-
-b $(TOOLS_DIR)/$(BIN_DIR) \
823+
-b $(TOOLS_BIN_DIR) \
763824
$(shell cat .github/workflows/golangci-lint.yml | grep version | sed 's/.*version: //')

hack/ensure-kustomize.sh

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)