-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile
More file actions
395 lines (332 loc) · 15.1 KB
/
Makefile
File metadata and controls
395 lines (332 loc) · 15.1 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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
# CHANNELS define the bundle channels used in the bundle.
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
# To re-generate a bundle for other specific channels without changing the standard setup, you can:
# - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=candidate,fast,stable)
# - use environment variables to overwrite this value (e.g export CHANNELS="candidate,fast,stable")
ifneq ($(origin CHANNELS), undefined)
BUNDLE_CHANNELS := --channels=$(CHANNELS)
endif
# DEFAULT_CHANNEL defines the default channel used in the bundle.
# Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable")
# To re-generate a bundle for any other default channel without changing the default setup, you can:
# - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable)
# - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable")
ifneq ($(origin DEFAULT_CHANNEL), undefined)
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
# IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images.
# This variable is used to construct full image tags for bundle and catalog images.
#
# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
# weka.io/weka-operator-bundle:$VERSION and weka.io/weka-operator-catalog:$VERSION.
#IMAGE_TAG_BASE ?= weka.io/weka-operator
# Determine repository name based on branch
# Use production repository for any release/* branch, otherwise use -dev repository
CURRENT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
ifneq ($(findstring release/,$(CURRENT_BRANCH)),)
REPO ?= quay.io/weka.io/weka-operator
else
REPO ?= quay.io/weka.io/weka-operator-dev
endif
VERSION ?= dev-$(shell git rev-parse --short HEAD)
DEPLOY_CONTROLLER ?= true
WH_ENABLE_INSECURE ?= false
WH_ENDPOINT ?= https://api.home.weka.io
WH_CACERT_SECRET ?=
OTEL_EXPORTER_OTLP_ENDPOINT ?=
ENABLE_CLUSTER_API ?= false
SKIP_CRD_INSTALL ?= false
RECONCILE_TIMEOUT ?= 10m
KUBE_EXEC_TIMEOUT ?= 2m
METRICS_CLUSTERS_ENABLED ?= true
METRICS_CONTAINERS_ENABLED ?= true
CLEANUP_REMOVED_NODES ?= true
CLEANUP_BACKENDS_ON_NODE_SELECTOR_MISMATCH ?= false
CLEANUP_CLIENTS_ON_NODE_SELECTOR_MISMATCH ?= false
CLEANUP_CONTAINERS_ON_TOLERATIONS_MISMATCH ?= false
SIGN_DRIVES_IMAGE ?= quay.io/weka.io/weka-sign-tool:b1fa0a139479f2489d176a6f1235c36beb179410_x86_64
# Optional environment variable to specify custom values.yaml for Helm
VALUES_YAML ?= charts/weka-operator/values.yaml
# Set the Operator SDK version to use. By default, what is installed on the system is used.
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
OPERATOR_SDK_VERSION ?= v1.32.0
# Image URL to use all building/pushing image targets
#IMG ?= $(REPO):$(VERSION)
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.26.0
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
.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
CRD_TYPES = pkg/weka-k8s-api/api/v1alpha1/driveclaims_types.go \
pkg/weka-k8s-api/api/v1alpha1/container_types.go \
pkg/weka-k8s-api/api/v1alpha1/wekacluster_types.go \
pkg/weka-k8s-api/api/v1alpha1/wekamanualoperation_types.go \
pkg/weka-k8s-api/api/v1alpha1/wekapolicy_types.go
.PHONY: crd
crd: ## Generate CustomResourceDefinition objects.
mkdir -p charts/weka-operator/crds/
rm -f charts/weka-operator/crds/*
$(CONTROLLER_GEN) crd paths="./pkg/weka-k8s-api/..." output:crd:artifacts:config=charts/weka-operator/crds
RBAC = charts/weka-operator/templates/role.yaml
$(RBAC): internal/controllers/*.go internal/controllers/*/*.go internal/admission/*.go
.PHONY: rbac
rbac: $(RBAC) ## Generate RBAC objects.
mkdir -p charts/weka-operator/templates
$(CONTROLLER_GEN) rbac:roleName=weka-operator-manager-role paths="./internal/controllers/..." paths="./internal/admission/..." output:rbac:artifacts:config=charts/weka-operator/templates
.PHONY: manifests
manifests: crd rbac api-docs## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
api-docs: ## Generate API reference documentation from source files
@echo "Generating API documentation..."
@mkdir -p doc/api_dump
@go run scripts/gen-api-docs.go
.PHONY: generate
generate: ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="" paths="./pkg/weka-k8s-api/..."
.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
.PHONY: lint
lint: lint-go lint-deadcode ## Run all linters (golangci-lint and deadcode).
.PHONY: lint-go
lint-go: ## Run golangci-lint against code.
golangci-lint run ./...
.PHONY: lint-deadcode
lint-deadcode: ## Run deadcode analysis (includes test coverage).
deadcode -test ./...
.PHONY: lint-govulncheck
lint-govulncheck: ## Run govulncheck against known vulnerability database.
govulncheck ./...
.PHONY: lint-fix
lint-fix: ## Run golangci-lint and auto-fix issues where possible.
golangci-lint run --fix ./...
.PHONY: test
test: ## Run tests.
go test -v ./internal/... -coverprofile cover.out
.PHONY: test-e2e
test-e2e: ## Run e2e tests.
# WEKA_IMAGE and CLUSTER_NAME must be set in the environment.
go test -v ./test -run TestHappyPath -weka-image "${WEKA_IMAGE}" -cluster-name ${CLUSTER_NAME} -debug -timeout 30m -cleanup=false
CLUSTER_SAMPLE=config/samples/weka_v1alpha1_cluster.yaml
.PHONY: cluster-sample
cluster-sample: ## Deploy sample cluster CRD
kubectl apply -f $(CLUSTER_SAMPLE)
##@ Build
.PHONY: build
build: ## Build the operator binary.
go build ./...
.PHONY: verify
verify: ## Verify go.mod is tidy and generated files are current.
go mod tidy
git diff --exit-code go.mod go.sum
$(MAKE) generate
$(MAKE) manifests
git diff --exit-code
.PHONY: clean
clean: ## Clean build artifacts.
find . -name 'mock_*.go' -delete
find . -name 'prog.bin' -delete
rm -rf dist
rm -rf cover.out cover.html
.PHONY: dev
dev:
$(MAKE) build VERSION=${VERSION} REPO=${REPO}
$(MAKE) docker-push VERSION=${VERSION} REPO=${REPO}
- $(MAKE) undeploy
- $(MAKE) uninstall
$(MAKE) deploy VERSION=${VERSION} REPO=${REPO}
.PHONY: devupdate
devupdate:
$(MAKE) build VERSION=${VERSION} REPO=${REPO}
$(MAKE) docker-push VERSION=${VERSION} REPO=${REPO}
$(MAKE) deploy VERSION=${VERSION} REPO=${REPO}
.PHONY: run
run: generate manifests install fmt vet deploy runcontroller ## Run a controller from your host.
;
.PHONY: runocp
runocp: generate manifests install fmt vet deployocp runcontroller ## Run a controller from your host.
;
.PHONY: runcontroller
runcontroller: ## Run a controller from your host.
WEKA_OPERATOR_MAINTENANCE_SA_NAME=weka-operator-maintenance \
WEKA_OPERATOR_WEKA_HOME_ENDPOINT=${WH_ENDPOINT} \
WEKA_OPERATOR_WEKA_HOME_INSECURE="${WH_ENABLE_INSECURE}" \
WEKA_OPERATOR_WEKA_HOME_CACERT_SECRET="${WH_CACERT_SECRET}" \
WEKA_OCP_PULL_SECRET=ocp-buildkit-secret \
WEKA_OCP_TOOLKIT_IMAGE_BASE_URL=quay.io/openshift-release-dev/ocp-v4.0-art-dev \
WEKA_COS_SERVICE_ACCOUNT_SECRET=weka-builder \
WEKA_COS_ALLOW_HUGEPAGE_CONFIG=true \
OTEL_DEPLOYMENT_IDENTIFIER="dev"-${USER} \
WEKA_COS_GLOBAL_HUGEPAGE_SIZE=2M \
WEKA_COS_GLOBAL_HUGEPAGE_COUNT=2000 \
OPERATOR_DEV_MODE=true \
OTEL_EXPORTER_OTLP_ENDPOINT="$(OTEL_EXPORTER_OTLP_ENDPOINT)" \
VERSION=${VERSION} \
LOG_LEVEL=0 \
LOG_TIME_ONLY=true \
ENABLE_CLUSTER_API=$(ENABLE_CLUSTER_API) \
RECONCILE_TIMEOUT=$(RECONCILE_TIMEOUT) \
KUBE_EXEC_TIMEOUT=$(KUBE_EXEC_TIMEOUT) \
METRICS_CLUSTERS_ENABLED=$(METRICS_CLUSTERS_ENABLED) \
METRICS_CONTAINERS_ENABLED=$(METRICS_CONTAINERS_ENABLED) \
CLEANUP_REMOVED_NODES=$(CLEANUP_REMOVED_NODES) \
CLEANUP_BACKENDS_ON_NODE_SELECTOR_MISMATCH=$(CLEANUP_BACKENDS_ON_NODE_SELECTOR_MISMATCH) \
CLEANUP_CLIENTS_ON_NODE_SELECTOR_MISMATCH=$(CLEANUP_CLIENTS_ON_NODE_SELECTOR_MISMATCH) \
CLEANUP_CONTAINERS_ON_TOLERATIONS_MISMATCH=$(CLEANUP_CONTAINERS_ON_TOLERATIONS_MISMATCH) \
OPERATOR_METRICS_BIND_ADDRESS=":8080" \
HEALTH_PROBE_BIND_ADDRESS=":8081" \
SIGN_DRIVES_IMAGE=${SIGN_DRIVES_IMAGE} \
go run ./cmd/manager/main.go
.PHONY: debugcontroller
debugcontroller: ## Run a controller from your host.
WEKA_OPERATOR_MAINTENANCE_SA_NAME=weka-operator-maintenance \
WEKA_OPERATOR_WEKA_HOME_ENDPOINT=${WH_ENDPOINT}
WEKA_OPERATOR_WEKA_HOME_INSECURE="${WH_ENABLE_INSECURE}" \
WEKA_OPERATOR_WEKA_HOME_CACERT_SECRET="${WH_CACERT_SECRET}" \
WEKA_OCP_PULL_SECRET=ocp-buildkit-secret \
WEKA_OCP_TOOLKIT_IMAGE_BASE_URL=quay.io/openshift-release-dev/ocp-v4.0-art-dev \
WEKA_COS_SERVICE_ACCOUNT_SECRET=weka-builder \
WEKA_COS_ALLOW_HUGEPAGE_CONFIG=true \
WEKA_COS_GLOBAL_HUGEPAGE_SIZE=2M \
WEKA_COS_GLOBAL_HUGEPAGE_COUNT=2000 \
ENABLE_CLUSTER_API=$(ENABLE_CLUSTER_API) \
SIGN_DRIVES_IMAGE=${SIGN_DRIVES_IMAGE} \
OPERATOR_DEV_MODE=true \
OTEL_EXPORTER_OTLP_ENDPOINT="$(OTEL_EXPORTER_OTLP_ENDPOINT)" \
dlv debug \
--headless \
--listen=:2345 \
--api-version=2 \
--accept-multiclient \
./cmd/manager/main.go
#.PHONY: docker-build
#docker-build: ## Build docker image with the manager.
# docker buildx build --push --platform linux/x86_64 -t ${IMG} .
.PHONY: docker-push
docker-push: ## Push docker image with the manager.
docker push ${REPO}:${VERSION}
##@ Deployment
ifndef ignore-not-found
ignore-not-found = false
endif
.PHONY: install
install: manifests ## Install CRDs into the K8s cluster specified in ~/.kube/config.
if [ "$(SKIP_CRD_INSTALL)" = "false" ]; then kubectl apply --server-side -f charts/weka-operator/crds; fi
.PHONY: uninstall
uninstall: manifests ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
kubectl delete --ignore-not-found=$(ignore-not-found) -f charts/weka-operator/crds
NAMESPACE="weka-operator-system"
VALUES="prefix=weka-operator,image.repository=$(REPO),image.tag=$(VERSION)"
.PHONY: deploy
deploy: generate install ## Deploy controller to the K8s cluster specified in ~/.kube/config.
$(HELM) upgrade --install weka-operator charts/weka-operator \
--namespace $(NAMESPACE) \
--values $(VALUES_YAML) \
--create-namespace \
--set $(VALUES) \
--set deployController=${DEPLOY_CONTROLLER} \
--set otelExporterOtlpEndpoint="$(OTEL_EXPORTER_OTLP_ENDPOINT)" \
--set wekahome.endpoint="${WH_ENDPOINT}" \
--set wekahome.allowInsecureTLS=${WH_ENABLE_INSECURE} \
--set wekahome.cacertSecret="${WH_CACERT_SECRET}" \
--set ocpCompatibility.hugepageConfiguration.enabled=true \
--set ocpCompatibility.driverToolkitSecretName=ocp-buildkit-secret \
--set ocpCompatibility.driverToolkitImageBaseUrl=quay.io/weka.io/gke-toolkit \
--set gkeCompatibility.hugepageConfiguration.enabled=true \
--set gkeCompatibility.disableDriverSigning=true \
--set deploymentIdentifier="dev-${USER}" \
--set cleanupRemovedNodes=$(CLEANUP_REMOVED_NODES) \
--set gkeCompatibility.gkeServiceAccountSecret=weka-builder \
--set skipUnhealthyToleration=true \
--set csi.installationEnabled=true
.PHONY: deployocp
deployocp: generate install ## Deploy controller to the K8s cluster specified in ~/.kube/config.
$(HELM) upgrade --install weka-operator charts/weka-operator \
--namespace $(NAMESPACE) \
--values $(VALUES_YAML) \
--create-namespace \
--set $(VALUES) \
--set deployController=${DEPLOY_CONTROLLER} \
--set otelExporterOtlpEndpoint="$(OTEL_EXPORTER_OTLP_ENDPOINT)" \
--set wekahome.endpoint="${WH_ENDPOINT}" \
--set wekahome.allowInsecureTLS=${WH_ENABLE_INSECURE} \
--set wekahome.cacertSecret="${WH_CACERT_SECRET}" \
--set ocpCompatibility.hugepageConfiguration.enabled=true \
--set ocpCompatibility.hugepageConfiguration.hugepagesCount=8000 \
--set ocpCompatibility.driverToolkitSecretName=ocp-buildkit-secret \
--set ocpCompatibility.driverToolkitImageBaseUrl=quay.io/weka.io/gke-toolkit \
--set gkeCompatibility.hugepageConfiguration.enabled=true \
--set gkeCompatibility.disableDriverSigning=true \
--set deploymentIdentifier="dev-${USER}" \
--set gkeCompatibility.gkeServiceAccountSecret=weka-builder \
--set nodeAgent.persistencePaths='/root/k8s-weka'
--set csi.installationEnabled=true
.PHONY: undeploy
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
$(HELM) uninstall weka-operator --namespace $(NAMESPACE)
##@ Helm Chart
HELM=helm
CHART= charts/weka-operator
CHART_ARCHIVE=charts/weka-operator-$(VERSION).tgz
.PHONY: chart
chart: $(CHART_ARCHIVE) ## Build Helm chart.
$(HELM) lint $(CHART)
$(HELM) package $(CHART) --destination charts --version $(VERSION)
$(CHART_ARCHIVE): crd
##@ Build Dependencies
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
CONTROLLER_GEN ?= go run sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
ENVTEST ?= $(LOCALBIN)/setup-envtest
## Tool Versions
CONTROLLER_TOOLS_VERSION ?= v0.16.5
.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
.PHONY: operator-sdk
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk
operator-sdk: ## Download operator-sdk locally if necessary.
ifeq (,$(wildcard $(OPERATOR_SDK)))
ifeq (, $(shell which operator-sdk 2>/dev/null))
@{ \
set -e ;\
mkdir -p $(dir $(OPERATOR_SDK)) ;\
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$${OS}_$${ARCH} ;\
chmod +x $(OPERATOR_SDK) ;\
}
else
OPERATOR_SDK = $(shell which operator-sdk)
endif
endif