Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
179 lines (144 loc) · 6.3 KB
/
Copy pathMakefile
File metadata and controls
179 lines (144 loc) · 6.3 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
KUBERNETES_VERSION = 1.35.4
# Tool versions
MYSQLSH_VERSION = 8.4.8-1
OS_VERSION := $(shell . /etc/os-release; echo $$VERSION_ID)
# Test tools
BIN_DIR := $(shell pwd)/bin
NILERR := $(BIN_DIR)/nilerr
STATICCHECK := $(BIN_DIR)/staticcheck
SUDO = sudo
# for envtest
export ENVTEST_KUBERNETES_VERSION=$(shell echo $(KUBERNETES_VERSION) | cut -d "." -f 1-2).0
export ENVTEST_ASSETS_DIR=$(BIN_DIR)
KUSTOMIZE := kustomize
HELM := helm
GORELEASER := goreleaser
YQ := yq
CONTROLLER_GEN := controller-gen
CRD_TO_MARKDOWN := crd-to-markdown
MDBOOK := mdbook
PKG_LIST := zstd python3 libpython3.8
ifneq ($(CI),true)
# Don't install the mysql packages in GitHub Actions.
# refs: https://github.com/actions/virtual-environments/pull/4674
PKG_LIST := $(PKG_LIST) mysql-client mysql-server-core-8.0
endif
# Set the shell used to bash for better error handling.
SHELL = /bin/bash
.SHELLFLAGS = -e -o pipefail -c
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS = "crd:crdVersions=v1,maxDescLen=50"
# for Go
GOOS = $(shell go env GOOS)
GOARCH = $(shell go env GOARCH)
SUFFIX =
.PHONY: all
all: build
##@ General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading 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.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Development
.PHONY: manifests
manifests: aqua-install ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
rm -rf charts/moco/templates/generated/
mkdir -p charts/moco/templates/generated/crds/
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
$(KUSTOMIZE) build config/crd -o config/crd/tests # Outputs static CRDs for use with Envtest.
$(KUSTOMIZE) build config/kustomize-to-helm/overlays/templates | $(YQ) e ". | del(select(.kind==\"ValidatingAdmissionPolicy\" or .kind==\"ValidatingAdmissionPolicyBinding\").metadata.namespace)" - > charts/moco/templates/generated/generated.yaml # Manually remove namespaces because the API version supported by kustomize is out of date.
echo '{{- if .Values.crds.enabled }}' > charts/moco/templates/generated/crds/moco_crds.yaml
$(KUSTOMIZE) build config/kustomize-to-helm/overlays/crds | $(YQ) e "." - >> charts/moco/templates/generated/crds/moco_crds.yaml
echo '{{- end }}' >> charts/moco/templates/generated/crds/moco_crds.yaml
.PHONY: generate
generate: aqua-install ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
.PHONY: apidoc
apidoc: aqua-install $(wildcard api/*/*_types.go)
$(CRD_TO_MARKDOWN) --links docs/links.csv -f api/v1beta2/mysqlcluster_types.go -f api/v1beta2/job_types.go -n MySQLCluster > docs/crd_mysqlcluster_v1beta2.md
$(CRD_TO_MARKDOWN) --links docs/links.csv -f api/v1beta2/backuppolicy_types.go -f api/v1beta2/job_types.go -n BackupPolicy > docs/crd_backuppolicy_v1beta2.md
.PHONY: book
book: aqua-install
rm -rf docs/book
cd docs; $(MDBOOK) build
.PHONY: check-generate
check-generate:
$(MAKE) manifests generate apidoc
go mod tidy
git diff --exit-code --name-only
.PHONY: clustering-envtest
clustering-envtest: aqua-install
export MOCO_CHECK_INTERVAL=100ms; \
export MOCO_CLONE_WAIT_DURATION=100ms; \
go test -v -count 1 -race ./clustering -ginkgo.randomize-all -ginkgo.v -ginkgo.fail-fast $(if $(FOCUS),-ginkgo.focus="$(FOCUS)")
.PHONY: controller-envtest
controller-envtest: aqua-install
export DEBUG_CONTROLLER=1; \
go test -v -count 1 -race ./controllers -ginkgo.randomize-all -ginkgo.v -ginkgo.fail-fast $(if $(FOCUS),-ginkgo.focus="$(FOCUS)")
.PHONY: api-envtest
api-envtest: aqua-install
go test -v -count 1 -race ./api/... -ginkgo.randomize-all -ginkgo.v $(if $(FOCUS),-ginkgo.focus="$(FOCUS)")
.PHONY: backup-envtest
backup-envtest: aqua-install
go test -v -count 1 -race ./backup -ginkgo.randomize-all -ginkgo.v -ginkgo.fail-fast $(if $(FOCUS),-ginkgo.focus="$(FOCUS)")
.PHONY: envtest
envtest: aqua-install clustering-envtest controller-envtest api-envtest backup-envtest
.PHONY: test-dbop
test-dbop:
-docker network create test-moco
TEST_MYSQL=1 MYSQL_VERSION=$(MYSQL_VERSION) go test -v -count 1 -race ./pkg/dbop -ginkgo.v -ginkgo.randomize-all
.PHONY: test-bkop
test-bkop:
@if which mysqlsh; then : ; else echo 'Run "make setup" to prepare test tools.'; exit 1; fi
-docker network create test-moco
TEST_MYSQL=1 MYSQL_VERSION=$(MYSQL_VERSION) go test -v -count 1 -race ./pkg/bkop -ginkgo.v -ginkgo.randomize-all
.PHONY: test
test: aqua-install
go test -v -count 1 -race ./pkg/...
go install ./...
go vet ./...
test -z $$(gofmt -s -l . | tee /dev/stderr)
.PHONY: lint
lint: aqua-install
@golangci-lint run --timeout 5m
##@ Build
.PHONY: build
build:
mkdir -p bin
GOBIN=$(shell pwd)/bin go install ./cmd/...
.PHONY: release-build
release-build: aqua-install
$(GORELEASER) build --snapshot --clean
.PHONY: release-manifests-build
release-manifests-build: aqua-install
rm -rf build
mkdir -p build
$(KUSTOMIZE) build . > build/moco.yaml
.PHONY: aqua-install
aqua-install: ## Install tools managed by aqua
aqua install
.PHONY: setup
setup:
$(SUDO) apt-get update
$(SUDO) apt-get install -y --no-install-recommends $(PKG_LIST)
curl -o /tmp/mysqlsh.deb -fsL https://dev.mysql.com/get/Downloads/MySQL-Shell/mysql-shell_$(MYSQLSH_VERSION)ubuntu$(OS_VERSION)_amd64.deb
$(SUDO) dpkg -i /tmp/mysqlsh.deb
rm -f /tmp/mysqlsh.deb
.PHONY: lint-ci
lint-ci:
zizmor --offline .github
ghalint run
ghalint act
actionlint
.PHONY: pinact
pinact:
pinact run -update -min-age 7 -verify