|
1 | | -# Image URL to use all building/pushing image targets |
2 | 1 | IMG ?= controller:latest |
3 | | -# YEAR defines the year value used for substituting the YEAR placeholder in the boilerplate header. |
| 2 | + |
4 | 3 | YEAR ?= $(shell date +%Y) |
5 | 4 |
|
6 | | -# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) |
7 | 5 | ifeq (,$(shell go env GOBIN)) |
8 | 6 | GOBIN=$(shell go env GOPATH)/bin |
9 | 7 | else |
10 | 8 | GOBIN=$(shell go env GOBIN) |
11 | 9 | endif |
12 | 10 |
|
13 | | -# CONTAINER_TOOL defines the container tool to be used for building images. |
14 | | -# Be aware that the target commands are only tested with Docker which is |
15 | | -# scaffolded by default. However, you might want to replace it to use other |
16 | | -# tools. (i.e. podman) |
17 | 11 | CONTAINER_TOOL ?= docker |
18 | 12 |
|
19 | | -# Setting SHELL to bash allows bash commands to be executed by recipes. |
20 | | -# Options are set to exit when a recipe line exits non-zero or a piped command fails. |
21 | 13 | SHELL = /usr/bin/env bash -o pipefail |
22 | 14 | .SHELLFLAGS = -ec |
23 | 15 |
|
@@ -48,7 +40,7 @@ vet: ## Run go vet against code. |
48 | 40 |
|
49 | 41 | .PHONY: test |
50 | 42 | test: manifests generate fmt vet setup-envtest ## Run tests. |
51 | | - KUBEBUILDER_ASSETS="$(shell "$(ENVTEST)" use $(ENVTEST_K8S_VERSION) --bin-dir "$(LOCALBIN)" -p path)" go test ./... -coverprofile cover.out |
| 43 | + KUBEBUILDER_ASSETS="$(shell "$(ENVTEST)" use $(ENVTEST_K8S_VERSION) --bin-dir "$(LOCALBIN)" -p path)" go test ./... -v -race -coverprofile cover.out |
52 | 44 |
|
53 | 45 | .PHONY: lint |
54 | 46 | lint: golangci-lint ## Run golangci-lint linter |
@@ -153,6 +145,38 @@ deploy-rbpi: ## Build arm64 image, import on rbpi, deploy (set KUBECONFIG). |
153 | 145 | $(MAKE) rbpi-verify |
154 | 146 | @echo "Revert image pin: git checkout -- config/manager/kustomization.yaml" |
155 | 147 |
|
| 148 | +##@ scale test |
| 149 | + |
| 150 | +LOAD_NS ?= default |
| 151 | +LOAD_REDIS_DEPLOY ?= redis |
| 152 | +LOAD_STREAM ?= events |
| 153 | +LOAD_GROUP ?= workers |
| 154 | +LOAD_COUNT ?= 80 |
| 155 | +LOAD_DEPLOY ?= worker-deployment |
| 156 | +LOAD_SCALER ?= redisstreamscaler-sample |
| 157 | + |
| 158 | +LOAD_REDIS_EXEC = $(KUBECTL) exec -n $(LOAD_NS) deploy/$(LOAD_REDIS_DEPLOY) -- redis-cli |
| 159 | + |
| 160 | +.PHONY: scale-load |
| 161 | +scale-load: ## XADD messages on LOAD_STREAM (Redis deploy + RedisStreamScaler required). |
| 162 | + $(LOAD_REDIS_EXEC) XGROUP CREATE $(LOAD_STREAM) $(LOAD_GROUP) $$ MKSTREAM 2>/dev/null || true |
| 163 | + @for i in $$(seq 1 $(LOAD_COUNT)); do \ |
| 164 | + $(LOAD_REDIS_EXEC) XADD $(LOAD_STREAM) '*' payload $$i >/dev/null; \ |
| 165 | + done |
| 166 | + @echo "Added $(LOAD_COUNT) messages to $(LOAD_STREAM). Run: make scale-observe" |
| 167 | + |
| 168 | +.PHONY: scale-observe |
| 169 | +scale-observe: ## Watch deployment replicas and RedisStreamScaler status (Ctrl+C to stop). |
| 170 | + watch -n 2 -- \ |
| 171 | + "$(KUBECTL) get deploy $(LOAD_DEPLOY) -n $(LOAD_NS); \ |
| 172 | + echo; \ |
| 173 | + $(KUBECTL) get redisstreamscaler $(LOAD_SCALER) -n $(LOAD_NS) -o custom-columns=NAME:.metadata.name,BACKLOG:.status.currentBacklog,REPLICAS:.status.currentReplicas,READY:.status.conditions[?(@.type==\"Available\")].status" |
| 174 | + |
| 175 | +.PHONY: scale-load-clear |
| 176 | +scale-load-clear: ## XTRIM stream empty; scale-down may wait for cooldownPeriod. |
| 177 | + $(LOAD_REDIS_EXEC) XTRIM $(LOAD_STREAM) MAXLEN 0 |
| 178 | + @echo "Cleared $(LOAD_STREAM). Scale-down may wait for cooldownPeriod on the CR." |
| 179 | + |
156 | 180 | ##@ Dependencies |
157 | 181 |
|
158 | 182 | ## Location to install dependencies to |
@@ -207,13 +231,11 @@ $(ENVTEST): $(LOCALBIN) |
207 | 231 |
|
208 | 232 | .PHONY: golangci-lint |
209 | 233 | golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. |
210 | | -$(GOLANGCI_LINT): $(LOCALBIN) |
| 234 | +$(GOLANGCI_LINT): $(LOCALBIN) .custom-gcl.yml |
211 | 235 | $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) |
212 | | - @test -f .custom-gcl.yml && { \ |
213 | | - echo "Building custom golangci-lint with plugins..." && \ |
214 | | - $(GOLANGCI_LINT) custom --destination $(LOCALBIN) --name golangci-lint-custom && \ |
215 | | - mv -f $(LOCALBIN)/golangci-lint-custom $(GOLANGCI_LINT); \ |
216 | | - } || true |
| 236 | + @echo "Building custom golangci-lint with plugins..." |
| 237 | + $(GOLANGCI_LINT) custom --destination $(LOCALBIN) --name golangci-lint-custom |
| 238 | + mv -f $(LOCALBIN)/golangci-lint-custom $(GOLANGCI_LINT) |
217 | 239 |
|
218 | 240 | # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist |
219 | 241 | # $1 - target path with name of binary |
|
0 commit comments