Repository navigation
Expand file tree
/
Copy pathMakefile.custom.mk
More file actions
182 lines (153 loc) · 9.4 KB
/
Copy pathMakefile.custom.mk
File metadata and controls
182 lines (153 loc) · 9.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# Custom Makefile targets for muster
# This file is included by the main Makefile via `include Makefile.*.mk`
##@ Development
.PHONY: helm-lint
helm-lint: ## Run Helm linter
@echo "Running Helm linter..."
@helm lint helm/muster/
HELM_UNITTEST_VERSION := 1.0.3
YQ_VERSION := v4.44.6
# The chart checks that need helm only, which the generated chart-tests workflow runs
# through `make helm-test` on a runner with no promtool. The chart-test job in
# .circleci/custom.yml adds helm-promtool-test, which needs promtool and yq.
.PHONY: helm-test
helm-test: helm-lint helm-unittest ## Run the helm-only chart checks: lint and unittest.
.PHONY: helm-test-all
helm-test-all: helm-test helm-promtool-test ## Run every chart check (what CircleCI runs).
.PHONY: helm-alerting-test
helm-alerting-test: ## Run only the PrometheusRule checks: its helm-unittest suite plus the promtool alert-rule tests.
@echo "Running PrometheusRule chart tests..."
@$(MAKE) --no-print-directory helm-plugin-unittest
@helm unittest helm/muster/ -f 'tests/prometheusrule_test.yaml'
@$(MAKE) --no-print-directory helm-promtool-test
.PHONY: helm-unittest
helm-unittest: helm-plugin-unittest ## Run the helm-unittest suites of both charts (helm/muster, helm/muster-crds).
@echo "Running helm unittest..."
@helm unittest helm/muster/ helm/muster-crds/
.PHONY: helm-plugin-unittest
helm-plugin-unittest:
@helm plugin list | grep -q '^unittest' || helm plugin install https://github.com/helm-unittest/helm-unittest --version $(HELM_UNITTEST_VERSION)
# Separate from helm-unittest: the alert expressions need a PromQL engine to
# say anything, and only promtool has one. helm-unittest can assert that the
# rule renders; only this can assert that it fires when a backend breaks and
# stays quiet when one is merely waiting for auth.
.PHONY: helm-promtool-test
helm-promtool-test: ## Run the promtool unit tests for the PrometheusRule (requires promtool and mikefarah/yq).
@echo "Running promtool alert rule tests..."
@bash helm/muster/tests/promtool/run.sh
##@ Testing
# The architect go-build job runs `make test` (test_target: test). Extend that
# target with the checks that used to live in the hand-written ci.yaml so CI and
# local runs share one command. The `go test` recipe itself lives in
# Makefile.gen.go.mk; these prerequisites run before it (the version stamp for
# the CI binaries, CRD freshness, then the integration suite) and only add
# prerequisites -- they do not override the generated recipe.
test: stamp-version verify-crds verify-cli-docs verify-scenario-schema muster-integration-test
# The version stamp-version appends: the tag when CIRCLE_TAG is set,
# otherwise what `git describe` says about HEAD (v5.23.2-1-g4be8379e on a
# branch, with -dirty for uncommitted changes). In CI only the `git describe`
# value is ever appended: a tag build's .ldflags already carries the tag.
STAMP_VERSION ?= $(or $(CIRCLE_TAG),$(shell git describe --tags --always --dirty --match 'v*'))
# The architect orb's go-build job links the binaries with the flags in
# .ldflags, a file its go-test command writes right before it runs
# `make test`: commit SHA and build time on every build, and on a tag build
# also `-X '<module>/pkg/project.version=<tag without v>'` (Version in
# pkg/project adds the `v` back). A branch build gets no version from the
# orb, and without a version ldflag the binary falls back to what Go's
# buildvcs stamped from the checkout: a pseudo-version on a branch, nothing
# from a checkout without tags. `make test` is the one repo-owned step
# between the orb writing .ldflags and linking with it, so this prerequisite
# appends the version there when .ldflags has none, and every CI binary
# carries one whatever the checkout looks like; on a tag build it finds the
# orb's flag and does nothing. Without a .ldflags file (a local `make build`,
# whose generated LDFLAGS already carry the version) it does nothing either.
.PHONY: stamp-version
stamp-version: ## Append the version to the link flags in .ldflags, the file the architect go-build job links with.
@if [ -f .ldflags ] && ! grep -q 'pkg/project.version=' .ldflags; then \
v="$(STAMP_VERSION)"; \
printf " -X '%s/pkg/project.version=%s'" "$(MODULE)" "$$v" >> .ldflags; \
echo "Stamped version $$v into .ldflags"; \
fi
CONTROLLER_GEN_VERSION := v0.21.0
.PHONY: verify-crds
verify-crds: ## Regenerate CRDs and fail if the committed copies are stale.
@echo "Verifying CRDs are up to date..."
go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION)
PATH="$(shell go env GOPATH)/bin:$$PATH" $(MAKE) generate-crds
@git diff --exit-code $(CRD_DIR) $(APP_CRD_DIR) || { \
echo "ERROR: CRDs are out of date. Run 'make generate-crds' and commit."; \
exit 1; }
@echo "CRDs are up to date."
# schema.json is the core tool API the scenarios are validated against
# (TestCommittedScenariosValidateAgainstSchema, run by `go test`). This keeps
# it current: regenerated from a live `muster serve`, it must match the
# committed copy, and every scenario must validate against it.
.PHONY: verify-scenario-schema
verify-scenario-schema: build ## Regenerate schema.json, fail if the committed copy is stale or a scenario does not validate.
@echo "Verifying schema.json is up to date..."
./muster test --generate-schema --base-port 45000
@git diff --exit-code schema.json || { \
echo "ERROR: schema.json is out of date. Run 'muster test --generate-schema' and commit."; \
exit 1; }
./muster test --validate-scenarios
.PHONY: muster-integration-test
muster-integration-test: build ## Run the muster integration suite (./muster test).
@echo "Running muster integration suite..."
./muster test --parallel 50 --base-port 20000 --report test-reports
# The Kubernetes-mode scenarios run on a giantswarm/k8senv control plane:
# kube-apiserver (from setup-envtest, like the envtest-backed Go tests) on
# kine and SQLite. KINE_VERSION is the version k8senv pins.
KINE_VERSION ?= v0.14.12
K8SENV_BIN_DIR ?= $(HOME)/.local/share/k8senv/kine-$(KINE_VERSION)
KINE_ARCH ?= $(shell go env GOARCH)
SETUP_ENVTEST = go run sigs.k8s.io/controller-runtime/tools/setup-envtest@release-0.24 use -p path
.PHONY: kine
kine: $(K8SENV_BIN_DIR)/kine ## Fetch the kine binary the k8senv control plane runs (a checksum-verified release asset).
$(K8SENV_BIN_DIR)/kine:
mkdir -p "$(K8SENV_BIN_DIR)"
curl -fsSL -o "$(K8SENV_BIN_DIR)/kine-$(KINE_ARCH)" "https://github.com/k3s-io/kine/releases/download/$(KINE_VERSION)/kine-$(KINE_ARCH)"
curl -fsSL -o "$(K8SENV_BIN_DIR)/sha256sum-$(KINE_ARCH).txt" "https://github.com/k3s-io/kine/releases/download/$(KINE_VERSION)/sha256sum-$(KINE_ARCH).txt"
cd "$(K8SENV_BIN_DIR)" && sha256sum -c "sha256sum-$(KINE_ARCH).txt"
mv "$(K8SENV_BIN_DIR)/kine-$(KINE_ARCH)" "$@"
chmod 0755 "$@"
# The Postgres-backed tests and scenarios run against the server
# MUSTER_TEST_POSTGRES_DSN names (the test-envtest CI job's second container),
# or one the harness starts from initdb and postgres on PATH; without either
# they are skipped. Each Postgres scenario runs once: the Kubernetes-mode ones
# with the Kubernetes-mode scenarios, the filesystem-mode ones after them.
.PHONY: test-envtest
test-envtest: kine ## Run the Kubernetes- and Postgres-backed tests: the envtest RBAC integration tests, the Kubernetes-mode scenarios on k8senv and the Postgres scenarios (fetches kube-apiserver via setup-envtest, and kine).
@echo "Running envtest-backed tests..."
KUBEBUILDER_ASSETS="$$($(SETUP_ENVTEST))" \
go test -tags envtest ./internal/mcpserver/ ./internal/reconciler/ ./internal/workflow/ -run Envtest -count=1 -v
@echo "Running the harness's k8senv and Postgres tests..."
KUBEBUILDER_ASSETS="$$($(SETUP_ENVTEST))" MUSTER_TEST_KINE="$(K8SENV_BIN_DIR)/kine" \
go test -tags k8senv ./internal/testing/ -run 'K8senv|PostgresServer|PostgresLocalServer' -count=1 -v
@echo "Running the Kubernetes-mode scenarios (mode: kubernetes) on k8senv..."
go build -tags k8senv -o $(APPLICATION)-k8senv .
KUBEBUILDER_ASSETS="$$($(SETUP_ENVTEST))" MUSTER_TEST_KINE="$(K8SENV_BIN_DIR)/kine" \
./$(APPLICATION)-k8senv test --mode kubernetes --parallel 8 --base-port 21000 --readiness-timeout 60s --report test-reports-envtest
@echo "Running the filesystem-mode Postgres scenarios (postgres: true)..."
./$(APPLICATION)-k8senv test --mode filesystem --postgres-only --parallel 8 --base-port 21000 --readiness-timeout 60s --report test-reports-envtest
.PHONY: test-vet
test-vet: ## Run go test and go vet
@echo "Running Go tests (with NO_COLOR=true)..."
@NO_COLOR=true go test -cover ./...
@echo "Running go vet..."
@go vet ./...
##@ Documentation
.PHONY: tools-doc
tools-doc: ## Regenerate docs/reference/meta-tools.md from the registered meta-tools.
TOOLS_DOC_UPDATE=1 go test -count=1 -run TestToolsDocIsCurrent ./internal/aggregator/
DOCS_REQUIREMENTS := requirements-docs.txt
docs-build: ## Build the documentation site into site/; a broken link or a page missing from the nav fails the build.
uvx --with-requirements $(DOCS_REQUIREMENTS) mkdocs build --strict
docs-serve: ## Serve the documentation site on http://127.0.0.1:8000 with live reload.
uvx --with-requirements $(DOCS_REQUIREMENTS) mkdocs serve
generate-cli-docs: ## Render docs/reference/cli from the Cobra command tree.
go run ./hack/gen-cli-docs
verify-cli-docs: generate-cli-docs ## Fail if the committed CLI reference is stale.
@git diff --exit-code docs/reference/cli || { \
echo "ERROR: docs/reference/cli is out of date. Run 'make generate-cli-docs' and commit."; \
exit 1; }
@echo "CLI reference is up to date."