-
Notifications
You must be signed in to change notification settings - Fork 664
Expand file tree
/
Copy pathMakefile
More file actions
280 lines (240 loc) · 11.4 KB
/
Makefile
File metadata and controls
280 lines (240 loc) · 11.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
PGMONITOR_DIR ?= hack/tools/pgmonitor
PGMONITOR_VERSION ?= v5.2.1
QUERIES_CONFIG_DIR ?= hack/tools/queries
BUILDAH ?= buildah
GO ?= go
GO_TEST ?= $(GO) test
# Ensure modules imported by `postgres-operator` and `controller-gen` are compatible
# by managing them together in the main module.
CONTROLLER ?= $(GO) tool sigs.k8s.io/controller-tools/cmd/controller-gen
# Run tests using the latest tools.
CHAINSAW ?= $(GO) run github.com/kyverno/chainsaw@latest
CHAINSAW_TEST ?= $(CHAINSAW) test
CRD_CHECKER ?= $(GO) run github.com/openshift/crd-schema-checker/cmd/crd-schema-checker@latest
ENVTEST ?= $(GO) run sigs.k8s.io/controller-runtime/tools/setup-envtest@release-0.22
KUTTL ?= $(GO) run github.com/kudobuilder/kuttl/cmd/kubectl-kuttl@latest
KUTTL_TEST ?= $(KUTTL) test
##@ General
.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)
.PHONY: setup
setup: ## Run Setup needed to build images
setup: get-pgmonitor
.PHONY: get-pgmonitor
get-pgmonitor:
git -C '$(dir $(PGMONITOR_DIR))' clone https://github.com/CrunchyData/pgmonitor.git || git -C '$(PGMONITOR_DIR)' fetch origin
@git -C '$(PGMONITOR_DIR)' checkout '$(PGMONITOR_VERSION)'
@git -C '$(PGMONITOR_DIR)' config pull.ff only
[ -d '${QUERIES_CONFIG_DIR}' ] || mkdir -p '${QUERIES_CONFIG_DIR}'
cp -r '$(PGMONITOR_DIR)/postgres_exporter/common/.' '${QUERIES_CONFIG_DIR}'
cp '$(PGMONITOR_DIR)/postgres_exporter/linux/queries_backrest.yml' '${QUERIES_CONFIG_DIR}'
.PHONY: notes
notes: ## List known issues and future considerations
command -v rg > /dev/null && rg '(BUGS|FIXME|NOTE|TODO)[(][^)]+[)]' || grep -Ern '(BUGS|FIXME|NOTE|TODO)[(][^)]+[)]' *
.PHONY: clean
clean: ## Clean resources
clean: clean-deprecated
rm -f bin/postgres-operator
rm -rf licenses/*/
[ ! -d testing/kuttl/e2e-generated ] || rm -r testing/kuttl/e2e-generated
[ ! -d hack/tools/envtest ] || { chmod -R u+w hack/tools/envtest && rm -r hack/tools/envtest; }
[ ! -d hack/tools/pgmonitor ] || rm -rf hack/tools/pgmonitor
[ ! -d hack/tools/external-snapshotter ] || rm -rf hack/tools/external-snapshotter
[ ! -n "$$(ls hack/tools)" ] || rm -r hack/tools/*
[ ! -d hack/.kube ] || rm -r hack/.kube
.PHONY: clean-deprecated
clean-deprecated: ## Clean deprecated resources
@# packages used to be downloaded into the vendor directory
[ ! -d vendor ] || rm -r vendor
@# executables used to be compiled into the $GOBIN directory
[ ! -n '$(GOBIN)' ] || rm -f $(GOBIN)/postgres-operator $(GOBIN)/apiserver $(GOBIN)/*pgo
@# executables used to be in subdirectories
[ ! -d bin/pgo-rmdata ] || rm -r bin/pgo-rmdata
[ ! -d bin/pgo-backrest ] || rm -r bin/pgo-backrest
[ ! -d bin/pgo-scheduler ] || rm -r bin/pgo-scheduler
[ ! -d bin/postgres-operator ] || rm -r bin/postgres-operator
@# keys used to be generated before install
[ ! -d conf/pgo-backrest-repo ] || rm -r conf/pgo-backrest-repo
[ ! -d conf/postgres-operator ] || rm -r conf/postgres-operator
@# crunchy-postgres-exporter used to live in this repo
[ ! -d bin/crunchy-postgres-exporter ] || rm -r bin/crunchy-postgres-exporter
[ ! -d build/crunchy-postgres-exporter ] || rm -r build/crunchy-postgres-exporter
@# CRDs used to require patching
[ ! -d build/crd ] || rm -r build/crd
@# Old testing directories
[ ! -d testing/kuttl/e2e-generated-other ] || rm -r testing/kuttl/e2e-generated-other
@# Tools used to be downloaded directly
[ ! -f hack/tools/controller-gen ] || rm hack/tools/controller-gen
[ ! -f hack/tools/setup-envtest ] || rm hack/tools/setup-envtest
##@ Deployment
.PHONY: createnamespaces
createnamespaces: ## Create operator and target namespaces
kubectl apply -k ./config/namespace
.PHONY: deletenamespaces
deletenamespaces: ## Delete operator and target namespaces
kubectl delete -k ./config/namespace
.PHONY: install
install: ## Install the postgrescluster CRD
kubectl apply --server-side -k ./config/crd
.PHONY: uninstall
uninstall: ## Delete the postgrescluster CRD
kubectl delete -k ./config/crd
.PHONY: deploy
deploy: ## Deploy the PostgreSQL Operator (enables the postgrescluster controller)
kubectl apply --server-side -k ./config/default
.PHONY: undeploy
undeploy: ## Undeploy the PostgreSQL Operator
kubectl delete -k ./config/default
.PHONY: deploy-dev
deploy-dev: ## Deploy the PostgreSQL Operator locally
deploy-dev: get-pgmonitor
deploy-dev: createnamespaces
kubectl apply --server-side -k ./config/dev
hack/create-kubeconfig.sh postgres-operator pgo
env \
QUERIES_CONFIG_DIR='$(QUERIES_CONFIG_DIR)' \
CRUNCHY_DEBUG="$${CRUNCHY_DEBUG:-true}" \
PGO_FEATURE_GATES="$${PGO_FEATURE_GATES:-AllAlpha=true,AppendCustomQueries=false}" \
KUBECONFIG=hack/.kube/postgres-operator/pgo \
PGO_NAMESPACE='postgres-operator' \
PGO_INSTALLER='deploy-dev' \
PGO_INSTALLER_ORIGIN='postgres-operator-repo' \
BUILD_SOURCE='build-postgres-operator' \
$(shell kubectl kustomize ./config/dev | \
sed -ne '/^kind: Deployment/,/^---/ { \
/RELATED_IMAGE_/ { N; s,.*\(RELATED_[^[:space:]]*\).*value:[[:space:]]*\([^[:space:]]*\),\1="\2",; p; }; \
}') \
$(foreach v,$(filter RELATED_IMAGE_%,$(.VARIABLES)),$(v)="$($(v))") \
$(GO) run ./cmd/postgres-operator
##@ Build
.PHONY: build
build: ## Build a postgres-operator image
build: get-pgmonitor
$(BUILDAH) build --tag localhost/postgres-operator \
--label org.opencontainers.image.authors='Crunchy Data' \
--label org.opencontainers.image.description='Crunchy PostgreSQL Operator' \
--label org.opencontainers.image.revision='$(shell git rev-parse HEAD)' \
--label org.opencontainers.image.source='https://github.com/CrunchyData/postgres-operator' \
--label org.opencontainers.image.title='Crunchy PostgreSQL Operator' \
.
##@ Test
.PHONY: check
check: ## Run basic go tests with coverage output
check: get-pgmonitor
QUERIES_CONFIG_DIR="$(CURDIR)/${QUERIES_CONFIG_DIR}" $(GO_TEST) -cover ./...
# Informational only; no criteria to enforce at this time.
.PHONY: check-crd
check-crd:
$(foreach CRD, $(wildcard config/crd/bases/*.yaml), \
$(CRD_CHECKER) check-manifests --new-crd-filename '$(CRD)' 2>&1 | awk -f hack/check-manifests.awk $(newline))
# Available versions: curl -s 'https://storage.googleapis.com/kubebuilder-tools/' | grep -o '<Key>[^<]*</Key>'
# - KUBEBUILDER_ATTACH_CONTROL_PLANE_OUTPUT=true
.PHONY: check-envtest
check-envtest: ## Run check using envtest and a mock kube api
check-envtest: ENVTEST_USE = $(ENVTEST) --bin-dir=$(CURDIR)/hack/tools/envtest use $(ENVTEST_K8S_VERSION)
check-envtest: SHELL = bash
check-envtest: get-pgmonitor
@$(ENVTEST_USE) --print=overview && echo
source <($(ENVTEST_USE) --print=env) && PGO_NAMESPACE="postgres-operator" QUERIES_CONFIG_DIR="$(CURDIR)/${QUERIES_CONFIG_DIR}" \
$(GO_TEST) -count=1 -cover ./...
# The "PGO_TEST_TIMEOUT_SCALE" environment variable (default: 1) can be set to a
# positive number that extends test timeouts. The following runs tests with
# timeouts that are 20% longer than normal:
# make check-envtest-existing PGO_TEST_TIMEOUT_SCALE=1.2
.PHONY: check-envtest-existing
check-envtest-existing: ## Run check using envtest and an existing kube api
check-envtest-existing: get-pgmonitor
check-envtest-existing: createnamespaces
kubectl apply --server-side -k ./config/dev
USE_EXISTING_CLUSTER=true PGO_NAMESPACE="postgres-operator" QUERIES_CONFIG_DIR="$(CURDIR)/${QUERIES_CONFIG_DIR}" \
$(GO_TEST) -count=1 -cover -p=1 ./...
kubectl delete -k ./config/dev
# Expects operator to be running
#
# Chainsaw runs with a single kubectl context named "chainsaw".
# If you experience `cluster "minikube" does not exist`, try `MINIKUBE_PROFILE=chainsaw`.
#
# https://kyverno.github.io/chainsaw/latest/operations/script#kubeconfig
#
# NOTE: The autogrow volume tests require a storage provider that supports real
# volume expansion (e.g., GKE, EKS, AKS). They will fail on k3d/kind with the
# default local-path provisioner. Use CHAINSAW_EXTRA_ARGS to skip them when needed:
# make check-chainsaw CHAINSAW_EXTRA_ARGS='--exclude-test-regex chainsaw/.*autogrow.*'
#
.PHONY: check-chainsaw
check-chainsaw:
$(CHAINSAW_TEST) --config testing/chainsaw/e2e/config.yaml --values testing/chainsaw/e2e/values.yaml $(CHAINSAW_EXTRA_ARGS) testing/chainsaw/e2e
# Expects operator to be running
#
# KUTTL runs with a single kubectl context named "cluster".
# If you experience `cluster "minikube" does not exist`, try `MINIKUBE_PROFILE=cluster`.
#
.PHONY: check-kuttl
check-kuttl: ## Run kuttl end-to-end tests
check-kuttl: ## example command: make check-kuttl KUTTL_TEST='
${KUTTL_TEST} \
--config testing/kuttl/kuttl-test.yaml
.PHONY: generate-kuttl
generate-kuttl: export KUTTL_PGCLUSTER_API_VERSION ?= v1
generate-kuttl: export KUTTL_PG_UPGRADE_FROM_VERSION ?= 16
generate-kuttl: export KUTTL_PG_UPGRADE_TO_VERSION ?= 17
generate-kuttl: export KUTTL_PG_VERSION ?= 16
generate-kuttl: export KUTTL_POSTGIS_VERSION ?= 3.4
generate-kuttl: export KUTTL_PSQL_IMAGE ?= registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi9-17.7-2550
generate-kuttl: export KUTTL_TEST_DELETE_NAMESPACE ?= kuttl-test-delete-namespace
generate-kuttl: ## Generate kuttl tests
[ ! -d testing/kuttl/e2e-generated ] || rm -r testing/kuttl/e2e-generated
bash -ceu ' \
render() { envsubst '"'"' \
$$KUTTL_PGCLUSTER_API_VERSION \
$$KUTTL_PG_UPGRADE_FROM_VERSION $$KUTTL_PG_UPGRADE_TO_VERSION \
$$KUTTL_PG_VERSION $$KUTTL_POSTGIS_VERSION $$KUTTL_PSQL_IMAGE \
$$KUTTL_TEST_DELETE_NAMESPACE'"'"'; }; \
while [ $$# -gt 0 ]; do \
source="$${1}" target="$${1/e2e/e2e-generated}"; \
mkdir -p "$${target%/*}"; render < "$${source}" > "$${target}"; \
shift; \
done' - testing/kuttl/e2e/*/*.yaml testing/kuttl/e2e/*/*/*.yaml
if [ "$$KUTTL_PG_VERSION" -ge "18" ]; then \
[ ! -d testing/kuttl/e2e-generated/exporter-custom-queries ] || rm -rf testing/kuttl/e2e-generated/exporter-custom-queries; \
[ ! -d testing/kuttl/e2e-generated/exporter-no-tls ] || rm -rf testing/kuttl/e2e-generated/exporter-no-tls; \
[ ! -d testing/kuttl/e2e-generated/exporter-tls ] || rm -rf testing/kuttl/e2e-generated/exporter-tls; \
[ ! -d testing/kuttl/e2e-generated/exporter-password-change ] || rm -rf testing/kuttl/e2e-generated/exporter-password-change; \
fi
##@ Generate
.PHONY: check-generate
check-generate: ## Check everything generated is also committed
check-generate: generate
git diff --exit-code -- config/dev
git diff --exit-code -- internal/collector
git diff --exit-code -- pkg/apis
.PHONY: generate
generate: ## Generate everything
generate: generate-collector
generate: generate-crd
generate: generate-deepcopy
generate: generate-rbac
.PHONY: generate-crd
generate-crd: ## Generate Custom Resource Definitions (CRDs)
$(CONTROLLER) $(\
) crd paths='./pkg/apis/...' $(\
) output:dir='config/dev/crd/bases' # {directory}/{group}_{plural}.yaml
$(GO) generate ./internal/crd
.PHONY: generate-collector
generate-collector: ## Generate OTel Collector files
$(GO) generate ./internal/collector
.PHONY: generate-deepcopy
generate-deepcopy: ## Generate DeepCopy functions
$(CONTROLLER) $(\
) object:headerFile='hack/boilerplate.go.txt' $(\
) paths='./pkg/apis/postgres-operator.crunchydata.com/...'
.PHONY: generate-rbac
generate-rbac: ## Generate RBAC
$(CONTROLLER) $(\
) rbac:roleName='postgres-operator' $(\
) paths='./cmd/...' paths='./internal/...' $(\
) output:dir='config/dev/rbac/cluster' # {directory}/role.yaml
# https://www.gnu.org/software/make/manual/make.html#Multi_002dLine
define newline
endef