Skip to content

Commit 9847243

Browse files
committed
Use go-install for versioned dependencies
Signed-off-by: Vince Prignano <[email protected]>
1 parent 05127e5 commit 9847243

File tree

8 files changed

+78
-773
lines changed

8 files changed

+78
-773
lines changed

FAQ.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
**A**: Each controller should only reconcile one object type. Other
66
affected objects should be mapped to a single type of root object, using
7-
the `EnqueueRequestForOwner` or `EnqueueRequestsFromMapFunc` event
7+
the `handler.EnqueueRequestForOwner` or `handler.EnqueueRequestsFromMapFunc` event
88
handlers, and potentially indices. Then, your Reconcile method should
99
attempt to reconcile *all* state for that given root objects.
1010

1111
### Q: How do I have different logic in my reconciler for different types of events (e.g. create, update, delete)?
1212

13-
**A**: You should not. Reconcile functions should be idempotent, and
13+
**A**: You should not. Reconcile functions should be idempotent, and
1414
should always reconcile state by reading all the state it needs, then
1515
writing updates. This allows your reconciler to correctly respond to
1616
generic events, adjust to skipped or coalesced events, and easily deal

Makefile

+29-9
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ export GO111MODULE=on
3636

3737
# Tools.
3838
TOOLS_DIR := hack/tools
39-
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
39+
TOOLS_BIN_DIR := $(abspath $(TOOLS_DIR)/bin)
4040
GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/golangci-lint)
4141
GO_APIDIFF := $(TOOLS_BIN_DIR)/go-apidiff
4242
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/controller-gen
4343
ENVTEST_DIR := $(abspath tools/setup-envtest)
4444
SCRATCH_ENV_DIR := $(abspath examples/scratch-env)
45+
GO_INSTALL := ./hack/go-install.sh
4546

4647
# The help will print out all targets with their descriptions organized bellow their categories. The categories are represented by `##@` and the target descriptions by `##`.
4748
# The awk commands is responsible to read the entire set of makefiles included in this invocation, looking for lines of the file as xyz: ## something, and then pretty-format the target and help. Then, if there's a line with ##@ something, that gets pretty-printed as a category.
@@ -67,16 +68,29 @@ test-tools: ## tests the tools codebase (setup-envtest)
6768
## Binaries
6869
## --------------------------------------
6970

70-
$(GO_APIDIFF): $(TOOLS_DIR)/go.mod # Build go-apidiff from tools folder.
71-
cd $(TOOLS_DIR) && go build -tags=tools -o bin/go-apidiff github.com/joelanford/go-apidiff
71+
GO_APIDIFF_VER := v0.8.2
72+
GO_APIDIFF_BIN := go-apidiff
73+
GO_APIDIFF := $(abspath $(TOOLS_BIN_DIR)/$(GO_APIDIFF_BIN)-$(GO_APIDIFF_VER))
74+
GO_APIDIFF_PKG := github.com/joelanford/go-apidiff
7275

73-
$(CONTROLLER_GEN): $(TOOLS_DIR)/go.mod # Build controller-gen from tools folder.
74-
cd $(TOOLS_DIR) && go build -tags=tools -o bin/controller-gen sigs.k8s.io/controller-tools/cmd/controller-gen
76+
$(GO_APIDIFF): # Build go-apidiff from tools folder.
77+
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(GO_APIDIFF_PKG) $(GO_APIDIFF_BIN) $(GO_APIDIFF_VER)
7578

76-
$(GOLANGCI_LINT): .github/workflows/golangci-lint.yml # Download golanci-lint using hack script into tools folder.
77-
hack/ensure-golangci-lint.sh \
78-
-b $(TOOLS_BIN_DIR) \
79-
$(shell cat .github/workflows/golangci-lint.yml | grep "version: v" | sed 's/.*version: //')
79+
CONTROLLER_GEN_VER := v0.14.0
80+
CONTROLLER_GEN_BIN := controller-gen
81+
CONTROLLER_GEN := $(abspath $(TOOLS_BIN_DIR)/$(CONTROLLER_GEN_BIN)-$(CONTROLLER_GEN_VER))
82+
CONTROLLER_GEN_PKG := sigs.k8s.io/controller-tools/cmd/controller-gen
83+
84+
$(CONTROLLER_GEN): # Build controller-gen from tools folder.
85+
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(CONTROLLER_GEN_PKG) $(CONTROLLER_GEN_BIN) $(CONTROLLER_GEN_VER)
86+
87+
GOLANGCI_LINT_BIN := golangci-lint
88+
GOLANGCI_LINT_VER := $(shell cat .github/workflows/golangci-lint.yml | grep [[:space:]]version: | sed 's/.*version: //')
89+
GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER))
90+
GOLANGCI_LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
91+
92+
$(GOLANGCI_LINT): # Build golangci-lint from tools folder.
93+
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(GOLANGCI_LINT_PKG) $(GOLANGCI_LINT_BIN) $(GOLANGCI_LINT_VER)
8094

8195
## --------------------------------------
8296
## Linting
@@ -126,6 +140,12 @@ verify-modules: modules ## Verify go modules are up to date
126140
echo "go module files are out of date, please run 'make modules'"; exit 1; \
127141
fi
128142

143+
APIDIFF_OLD_COMMIT ?= $(shell git rev-parse origin/main)
144+
145+
.PHONY: apidiff
146+
verify-apidiff: $(GO_APIDIFF) ## Check for API differences
147+
$(GO_APIDIFF) $(APIDIFF_OLD_COMMIT) --print-compatible
148+
129149
.PHONY: verify-generate
130150
verify-generate: generate ## Verify generated files are up to date
131151
@if !(git diff --quiet HEAD); then \

hack/apidiff.sh

+2-9
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@ source $(dirname ${BASH_SOURCE})/common.sh
2323
REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
2424
cd "${REPO_ROOT}"
2525

26-
APIDIFF="hack/tools/bin/go-apidiff"
27-
28-
header_text "fetching and building go-apidiff"
29-
make "${APIDIFF}"
30-
31-
git status
32-
3326
header_text "verifying api diff"
34-
header_text "invoking: '${APIDIFF} ${PULL_BASE_SHA} --print-compatible'"
35-
"${APIDIFF}" "${PULL_BASE_SHA}" --print-compatible
27+
echo "*** Running go-apidiff ***"
28+
APIDIFF_OLD_COMMIT="${PULL_BASE_SHA}" make verify-apidiff

0 commit comments

Comments
 (0)