This repository is currently being migrated. It's locked while the migration is in progress.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
289 lines (234 loc) · 12.4 KB
/
Makefile
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
# VERSION defines the project version for the bundle.
VERSION ?= 2.7.0
# MIN_KUBE_VERSION is the build flag of minimum Kubernetes version.
MIN_KUBE_VERSION ?= 1.22.0
# Generate kuttl e2e tests for the following storageos/kind-node versions
# TEST_KIND_NODES is not intended to be updated manually.
# Please run 'LATEST_KIND_NODE=<latest-kind-node> make update-kind-nodes'.
TEST_KIND_NODES ?= 1.22.3,1.23.0,1.24.2,1.25.0,1.26.0
# 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")
BUNDLE_CHANNELS := --channels=stable
# 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")
ifneq ($(origin DEFAULT_CHANNEL), undefined)
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_PACKAGE_NAME ?= --package=storageosoperator
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) $(BUNDLE_PACKAGE_NAME)
# Image URL to use all building/pushing image targets
OPERATOR_IMAGE ?= storageos/operator:test
# Image URL for manifest image.
MANIFESTS_IMAGE ?= storageos/operator-manifests:test
LD_FLAGS = -X main.SupportedMinKubeVersion=$(MIN_KUBE_VERSION)
# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
# Refer: https://github.com/operator-framework/operator-sdk/issues/4203.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
API_MANAGER_VERSION ?= develop
API_MANAGER_IMAGE ?= storageos/api-manager:$(API_MANAGER_VERSION)
API_MANAGER_MANIFESTS_IMAGE ?= storageos/api-manager-manifests
PORTAL_MANAGER_VERSION ?= develop
PORTAL_MANAGER_IMAGE ?= storageos/portal-manager:$(PORTAL_MANAGER_VERSION)
PORTAL_MANAGER_MANIFESTS_IMAGE ?= storageos/portal-manager-manifests
EXTERNAL_PROVISIONER_IMAGE ?= storageos/csi-provisioner:v3.4.0-patched
EXTERNAL_ATTACHER_IMAGE ?= registry.k8s.io/sig-storage/csi-attacher:v3.5.0
EXTERNAL_RESIZER_IMAGE ?= registry.k8s.io/sig-storage/csi-resizer:v1.6.0
EXTERNAL_SNAPSHOTTER_VERSION ?= v6.2.1
EXTERNAL_SNAPSHOTTER_IMAGE ?= registry.k8s.io/sig-storage/csi-snapshotter:$(EXTERNAL_SNAPSHOTTER_VERSION)
SNAPSHOT_CONTROLLER_IMAGE ?= registry.k8s.io/sig-storage/snapshot-controller:$(EXTERNAL_SNAPSHOTTER_VERSION)
INIT_IMAGE ?= storageos/init:v2.1.3
NODE_IMAGE ?= storageos/node:v2.9.0
NODE_MANAGER_VERSION ?= develop
NODE_MANAGER_IMAGE ?= storageos/node-manager:$(NODE_MANAGER_VERSION)
NODE_MANAGER_MANIFESTS_IMAGE ?= storageos/node-manager-manifests
NODE_GUARD_IMAGE ?= storageos/node-guard:develop
NODE_DRIVER_REG_IMAGE ?= registry.k8s.io/sig-storage/csi-node-driver-registrar:v2.6.0
LIVENESS_PROBE_IMAGE ?= registry.k8s.io/sig-storage/livenessprobe:v2.8.0
METRICS_EXPORTER_VERSION ?= v0.1.7
METRICS_EXPORTER_IMAGE ?= storageos/metrics-exporter:$(METRICS_EXPORTER_VERSION)
METRICS_EXPORTER_MANIFESTS_URL ?= https://github.com/ondat/metrics-exporter/releases/download/$(METRICS_EXPORTER_VERSION)/bundle.yaml
CLI_VERSION ?= v2.9.0
CLI_IMAGE ?= storageos/cli:$(CLI_VERSION)
# The related image environment variables. These are used in the opreator's
# configuration by converting into a ConfigMap and loading as a container's
# environment variables. See make target cofig-update.
define REL_IMAGE_CONF
RELATED_IMAGE_API_MANAGER=${API_MANAGER_IMAGE}
RELATED_IMAGE_PORTAL_MANAGER=${PORTAL_MANAGER_IMAGE}
RELATED_IMAGE_CSIV1_EXTERNAL_PROVISIONER=${EXTERNAL_PROVISIONER_IMAGE}
RELATED_IMAGE_CSIV1_EXTERNAL_ATTACHER_V3=${EXTERNAL_ATTACHER_IMAGE}
RELATED_IMAGE_CSIV1_EXTERNAL_RESIZER=${EXTERNAL_RESIZER_IMAGE}
RELATED_IMAGE_CSIV1_EXTERNAL_SNAPSHOTTER=${EXTERNAL_SNAPSHOTTER_IMAGE}
RELATED_IMAGE_SNAPSHOT_CONTROLLER=${SNAPSHOT_CONTROLLER_IMAGE}
RELATED_IMAGE_STORAGEOS_INIT=${INIT_IMAGE}
RELATED_IMAGE_STORAGEOS_NODE=${NODE_IMAGE}
RELATED_IMAGE_NODE_MANAGER=${NODE_MANAGER_IMAGE}
RELATED_IMAGE_NODE_GUARD=${NODE_GUARD_IMAGE}
RELATED_IMAGE_CSIV1_NODE_DRIVER_REGISTRAR=${NODE_DRIVER_REG_IMAGE}
RELATED_IMAGE_CSIV1_LIVENESS_PROBE=${LIVENESS_PROBE_IMAGE}
RELATED_IMAGE_METRICS_EXPORTER=${METRICS_EXPORTER_IMAGE}
RELATED_IMAGE_CLI=${CLI_IMAGE}
endef
export REL_IMAGE_CONF
# KUBEBUILDER_ASSETS path is set as environment variable when running envtest.
ENVTEST_BIN_VERSION = 1.21.4
KUBEBUILDER_ASSETS = $(shell $(SETUP_ENVTEST) use -i -p path $(ENVTEST_BIN_VERSION))
_env:
env
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
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%-17s\033[0m %s\n", $$1, $$2 } /^##@/{ printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Development
manifests: controller-gen config-update ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
make _manifests
_manifests:
$(CONTROLLER_GEN) crd paths=./api/... rbac:roleName=storageos-operator webhook paths="./..." output:crd:artifacts:config=config/crd/bases output:rbac:artifacts:config=config/rbac/bases
generate: controller-gen mockgen ## Generate code containing DeepCopy, DeepCopyInto, DeepCopyObject method implementations and mocks.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
go generate -v ./...
api-manager:
NAME=api-manager VERSION=$(API_MANAGER_VERSION) MANIFESTS_IMAGE_OR_URL=$(API_MANAGER_MANIFESTS_IMAGE) hack/pull-manifests.sh
NAME=api-manager VERSION=$(API_MANAGER_VERSION) FROM=clusterrole-storageos-api-manager.yaml TO=api_manager_role.yaml hack/update-rbac.sh
make config-update
portal-manager:
NAME=portal-manager VERSION=$(PORTAL_MANAGER_VERSION) MANIFESTS_IMAGE_OR_URL=$(PORTAL_MANAGER_MANIFESTS_IMAGE) hack/pull-manifests.sh
NAME=portal-manager VERSION=$(PORTAL_MANAGER_VERSION) FROM=clusterrole-storageos-portal-manager.yaml TO=portal_manager_role.yaml hack/update-rbac.sh
make config-update
node-manager:
NAME=node-manager VERSION=$(NODE_MANAGER_VERSION) MANIFESTS_IMAGE_OR_URL=$(NODE_MANAGER_MANIFESTS_IMAGE) hack/pull-manifests.sh
NAME=node-manager VERSION=$(NODE_MANAGER_VERSION) FROM=clusterrole-storageos-node-manager.yaml TO=node_manager_role.yaml hack/update-rbac.sh
make config-update
metrics-exporter:
NAME=metrics-exporter VERSION=$(METRICS_EXPORTER_VERSION) MANIFESTS_IMAGE_OR_URL=$(METRICS_EXPORTER_MANIFESTS_URL) hack/pull-manifests.sh
make config-update
lint: ## Run golangci-lint
golangci-lint run --config .github/linters-cfg/.golangci.yml
test: manifests generate setup-envtest ## Run unit tests
KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) \
go test ./... -coverprofile cover.out
.PHONY: e2e
e2e: ## Run end to end tests
kubectl-kuttl test --config e2e/kuttl/operator-deployment-1.22.yaml
update-kind-nodes:
ifndef LATEST_KIND_NODE
$(error LATEST_KIND_NODE is undefined)
endif
LATEST_KIND_NODE=$(LATEST_KIND_NODE) ./hack/update-kind-nodes.sh
generate-tests: ## Generate kuttl e2e tests
TEST_KIND_NODES=$(TEST_KIND_NODES) REPO=operator ./hack/generate-tests.sh
##@ Build
tidy: ## Prune, add and vendor go dependencies.
go mod tidy -v
go mod vendor -v
build: ## Build binary
CGO_ENABLED=0 go build -ldflags "$(LD_FLAGS)" -o bin/manager main.go
run: generate manifests ## Run a controller from your host.
RELATED_IMAGE_API_MANAGER=${API_MANAGER_IMAGE} \
RELATED_IMAGE_PORTAL_MANAGER=${PORTAL_MANAGER_IMAGE} \
RELATED_IMAGE_CSIV1_EXTERNAL_PROVISIONER=${EXTERNAL_PROVISIONER_IMAGE} \
RELATED_IMAGE_CSIV1_EXTERNAL_ATTACHER_V3=${EXTERNAL_ATTACHER_IMAGE} \
RELATED_IMAGE_CSIV1_EXTERNAL_RESIZER=${EXTERNAL_RESIZER_IMAGE} \
RELATED_IMAGE_CSIV1_EXTERNAL_SNAPSHOTTER=${EXTERNAL_SNAPSHOTTER_IMAGE} \
RELATED_IMAGE_STORAGEOS_INIT=${INIT_IMAGE} \
RELATED_IMAGE_STORAGEOS_NODE=${NODE_IMAGE} \
RELATED_IMAGE_NODE_MANAGER=${NODE_MANAGER_IMAGE} \
RELATED_IMAGE_NODE_GUARD=${NODE_GUARD_IMAGE} \
RELATED_IMAGE_CSIV1_NODE_DRIVER_REGISTRAR=${NODE_DRIVER_REG_IMAGE} \
RELATED_IMAGE_CSIV1_LIVENESS_PROBE=${LIVENESS_PROBE_IMAGE} \
POD_NAMESPACE=default \
go run ./main.go
config-update:
@echo "$$REL_IMAGE_CONF" > config/manager/related_images_config.yaml
operator-image: ## Build operator image
docker build -t ${OPERATOR_IMAGE} --build-arg VERSION=$(VERSION) .
operator-image-push:
docker push ${OPERATOR_IMAGE}
manifests-image: manifests ## Build manifests image
docker build -t $(MANIFESTS_IMAGE) --build-arg OPERATOR_IMAGE=$(OPERATOR_IMAGE) -f manifests.Dockerfile .
manifests-image-push:
docker push ${MANIFESTS_IMAGE}
##@ Deployment
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl apply -f -
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | kubectl delete -f -
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && $(KUSTOMIZE) edit set image controller=${OPERATOR_IMAGE}
$(KUSTOMIZE) build config/default | kubectl apply -f -
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/default | kubectl delete -f -
install-manifest: manifests kustomize ## Generate the operator install manifest.
cd config/manager && $(KUSTOMIZE) edit set image controller=${OPERATOR_IMAGE}
$(KUSTOMIZE) build config/default > storageos-operator.yaml
.PHONY: bundle
bundle: operator-sdk manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
$(OPERATOR_SDK) generate kustomize manifests --package=storageosoperator --apis-dir=api/v1 -q
cd config/manager && $(KUSTOMIZE) edit set image controller=$(OPERATOR_IMAGE)
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle --version $(VERSION) $(BUNDLE_METADATA_OPTS)
# Rename manifest files containing colons.
for file in bundle/manifests/* ; do if [[ $$file == *:* ]]; then mv "$$file" "$${file//:/_}"; fi; done
$(OPERATOR_SDK) bundle validate ./bundle
##@ Deps
SETUP_ENVTEST = $(shell pwd)/bin/setup-envtest
setup-envtest:
$(call go-get-tool,$(SETUP_ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
$(SETUP_ENVTEST) use $(ENVTEST_BIN_VERSION)
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize: ## Download kustomize locally if necessary.
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
MOCKGEN = $(shell pwd)/bin/mockgen
mockgen:
$(call go-get-tool,$(MOCKGEN),github.com/golang/mock/[email protected])
OPERATOR_SDK_DOWNLOAD_URL = "https://github.com/operator-framework/operator-sdk/releases/download/v1.21.0/operator-sdk_linux_amd64"
ifeq ($(shell uname | tr '[:upper:]' '[:lower:]'), darwin)
OPERATOR_SDK_DOWNLOAD_URL = "https://github.com/operator-framework/operator-sdk/releases/download/v1.21.0/operator-sdk_darwin_amd64"
endif
OPERATOR_SDK = $(shell pwd)/bin/operator-sdk
operator-sdk:
$(call curl-get-tool,$(OPERATOR_SDK), $(OPERATOR_SDK_DOWNLOAD_URL))
HUSKY = $(shell pwd)/bin/husky
.PHONY: husky
husky: ## Download husky locally if necessary.
$(call go-get-tool,$(HUSKY),github.com/automation-co/[email protected])
# go-get-tool will 'go install' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
# curl-get-tool will download any content of $2 and install it to $1.
define curl-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
echo "Downloading $(2)" ;\
curl -Lo $(1) $(2) ;\
chmod +x $(1) ;\
rm -rf $$TMP_DIR ;\
}
endef