-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathMakefile
More file actions
357 lines (291 loc) · 13.8 KB
/
Makefile
File metadata and controls
357 lines (291 loc) · 13.8 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
# Copyright 2022 IBM Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
.DEFAULT_GOAL:=help
# Allow Go to resolve the toolchain declared in go.mod during code generation.
export GOTOOLCHAIN ?= auto
export GOSUMDB ?= sum.golang.org
# Dependence tools
KUBECTL ?= $(shell which kubectl)
OPERATOR_SDK ?= $(shell which operator-sdk)
OPM ?= $(shell which opm)
KUSTOMIZE ?= $(shell which kustomize)
KUSTOMIZE_VERSION=v3.8.7
ENVCRDS_DIR=$(shell pwd)/testcrds
# CONTAINER_TOOL defines the container tool to be used for building images.
# Be aware that the target commands are only tested with Docker which is
# scaffolded by default. However, you might want to replace it to use other
# tools. (i.e. podman)
CONTAINER_TOOL ?= docker
# Specify whether this repo is build locally or not, default values is '1';
# If set to 1, then you need to also set 'DOCKER_USERNAME' and 'DOCKER_PASSWORD'
# environment variables before build the repo.
BUILD_LOCALLY ?= 1
VCS_REF ?= $(shell git rev-parse HEAD)
BUILD_VERSION ?= $(shell git describe --exact-match 2> /dev/null || \
git describe --match=$(git rev-parse --short=8 HEAD) --always --dirty --abbrev=8)
RELEASE_VERSION ?= $(shell cat ./version/version.go | grep "Version =" | awk '{ print $$3}' | tr -d '"')
LATEST_VERSION ?= latest
OPERATOR_SDK_VERSION=v1.32.0
YQ_VERSION=v4.42.1
DEFAULT_CHANNEL ?= v$(shell cat ./version/version.go | grep "Version =" | awk '{ print $$3}' | tr -d '"' | cut -d '.' -f1,2)
CHANNELS ?= $(DEFAULT_CHANNEL)
OPENSHIFT_VERSIONS ?= v4.12-v4.17
LOCAL_OS := $(shell uname)
ifeq ($(LOCAL_OS),Linux)
TARGET_OS ?= linux
XARGS_FLAGS="-r"
STRIP_FLAGS=
else ifeq ($(LOCAL_OS),Darwin)
TARGET_OS ?= darwin
XARGS_FLAGS=
STRIP_FLAGS="-x"
else
$(error "This system's OS $(LOCAL_OS) isn't recognized/supported")
endif
ARCH := $(shell uname -m)
# Auto-detect LOCAL_ARCH only when the caller hasn't provided one.
ifeq ($(origin LOCAL_ARCH), undefined)
LOCAL_ARCH := amd64
ifeq ($(ARCH),x86_64)
LOCAL_ARCH := amd64
else ifeq ($(ARCH),ppc64le)
LOCAL_ARCH := ppc64le
else ifeq ($(ARCH),s390x)
LOCAL_ARCH := s390x
else ifeq ($(ARCH),arm64)
LOCAL_ARCH := arm64
else
$(error "This system's ARCH $(ARCH) isn't recognized/supported")
endif
endif
# Default image repo
QUAY_REGISTRY ?= quay.io/opencloudio
ICR_REIGSTRY ?= icr.io/cpopen
ifeq ($(BUILD_LOCALLY),0)
DOCKER_REGISTRY ?= "docker-na-public.artifactory.swg-devops.com/hyc-cloud-private-integration-docker-local/ibmcom"
else
DOCKER_REGISTRY ?= "docker-na-public.artifactory.swg-devops.com/hyc-cloud-private-scratch-docker-local/ibmcom"
endif
BUILDX_BUILDER ?= operand-deployment-lifecycle-manager-builder
ifdef DEV_REGISTRY
DEV_REGISTRY := $(DEV_REGISTRY)
else
DEV_REGISTRY := ${QUAY_REGISTRY}
endif
RELEASE_IMAGE ?= $(DOCKER_REGISTRY)/$(OPERATOR_IMAGE_NAME):$(BUILD_VERSION)
RELEASE_IMAGE_ARCH ?= $(DOCKER_REGISTRY)/$(OPERATOR_IMAGE_NAME)-$(LOCAL_ARCH):$(BUILD_VERSION)
LOCAL_ARCH_IMAGE ?= $(OPERATOR_IMAGE_NAME)-$(LOCAL_ARCH):$(BUILD_VERSION)
# Current Operator image name
OPERATOR_IMAGE_NAME ?= odlm
# Current Operator bundle image name
BUNDLE_IMAGE_NAME ?= odlm-operator-bundle
# Current Operator version
OPERATOR_VERSION ?= 4.5.8
# Kind cluster name
KIND_CLUSTER_NAME ?= "odlm"
# Operator image tag for test
OPERATOR_TEST_TAG ?= dev-test
# Options for 'bundle-build'
ifneq ($(origin CHANNELS), undefined)
BUNDLE_CHANNELS := --channels=$(CHANNELS)
endif
ifneq ($(origin DEFAULT_CHANNEL), undefined)
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
endif
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
# 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
include common/Makefile.common.mk
##@ Development
check: lint-all ## Check all files lint error
yq: ## Install yq, a yaml processor
ifneq ($(shell yq -V | cut -d ' ' -f 3 | cut -d '.' -f 1 ), 4)
@{ \
if [ v$(shell ./bin/yq --version | cut -d ' ' -f3) != $(YQ_VERSION) ]; then\
set -e ;\
mkdir -p bin ;\
echo "Downloading yq ...";\
curl -sSLO https://github.com/mikefarah/yq/releases/download/$(YQ_VERSION)/yq_$(LOCAL_OS)_$(LOCAL_ARCH);\
mv yq_$(LOCAL_OS)_$(LOCAL_ARCH) ./bin/yq ;\
chmod +x ./bin/yq ;\
fi;\
}
YQ=$(realpath ./bin/yq)
else
YQ=$(shell which yq)
endif
kustomize: ## Install kustomize
ifeq (, $(shell which kustomize 2>/dev/null))
@{ \
set -e ;\
mkdir -p bin ;\
echo "Downloading kustomize ...";\
curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/$(KUSTOMIZE_VERSION)/kustomize_$(KUSTOMIZE_VERSION)_$(LOCAL_OS)_$(LOCAL_ARCH).tar.gz | tar xzf - -C bin/ ;\
}
KUSTOMIZE=$(realpath ./bin/kustomize)
else
KUSTOMIZE=$(shell which kustomize)
endif
operator-sdk:
ifneq ($(shell operator-sdk version | cut -d ',' -f1 | cut -d ':' -f2 | tr -d '"' | xargs | cut -d '.' -f1), v1)
@{ \
if [ "$(shell ./bin/operator-sdk version | cut -d ',' -f1 | cut -d ':' -f2 | tr -d '"' | xargs)" != $(OPERATOR_SDK_VERSION) ]; then \
set -e ; \
mkdir -p bin ;\
echo "Downloading operator-sdk..." ;\
curl -sSLo ./bin/operator-sdk "https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$(LOCAL_OS)_$(LOCAL_ARCH)" ;\
chmod +x ./bin/operator-sdk ;\
fi ;\
}
OPERATOR_SDK=$(realpath ./bin/operator-sdk)
else
OPERATOR_SDK=$(shell which operator-sdk)
endif
code-dev: ## Run the default dev commands which are the go tidy, fmt, vet then execute the $ make code-gen
@echo Running the common required commands for developments purposes
- make code-tidy
- make code-fmt
- make code-vet
@echo Running the common required commands for code delivery
- make check
- make test
manager: generate code-fmt code-vet ## Build manager binary
go build -o bin/manager main.go
run: generate code-fmt code-vet manifests ## Run against the configured Kubernetes cluster in ~/.kube/config
OPERATOR_NAMESPACE="ibm-common-services" INSTALL_SCOPE="namespaced" go run ./main.go -v=1
install: manifests kustomize ## Install CRDs into a cluster
$(KUSTOMIZE) build config/crd | kubectl apply -f -
uninstall: manifests kustomize ## Uninstall CRDs from a cluster
$(KUSTOMIZE) build config/crd | kubectl delete -f -
deploy: manifests kustomize ## Deploy controller in the configured Kubernetes cluster in ~/.kube/config
cd config/manager && $(KUSTOMIZE) edit set image icr.io/cpopen/odlm=$(QUAY_REGISTRY)/$(OPERATOR_IMAGE_NAME):$(OPERATOR_TEST_TAG)
$(KUSTOMIZE) build config/default | kubectl apply -f -
deploy-e2e: kustomize ## Deploy controller in the configured Kubernetes cluster in ~/.kube/config
cd config/e2e/manager && $(KUSTOMIZE) edit set image icr.io/cpopen/odlm=$(QUAY_REGISTRY)/$(OPERATOR_IMAGE_NAME):$(OPERATOR_TEST_TAG)
$(KUSTOMIZE) build config/e2e | kubectl apply -f -
##@ Generate code and manifests
manifests: controller-gen ## Generate manifests e.g. CRD, RBAC etc.
GOTOOLCHAIN=auto GOSUMDB=sum.golang.org $(CONTROLLER_GEN) crd rbac:roleName=operand-deployment-lifecycle-manager webhook paths="./..." output:crd:artifacts:config=config/crd/bases
generate: controller-gen ## Generate code e.g. API etc.
GOTOOLCHAIN=auto GOSUMDB=sum.golang.org $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
bundle-manifests: yq
cd config/manager && $(KUSTOMIZE) edit set image icr.io/cpopen/odlm=$(ICR_REIGSTRY)/$(OPERATOR_IMAGE_NAME):$(OPERATOR_VERSION)
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle \
-q --overwrite --version $(OPERATOR_VERSION) $(BUNDLE_METADATA_OPTS)
echo "\n # OpenShift annotations." >> bundle/metadata/annotations.yaml ;\
echo " com.redhat.openshift.versions: $(OPENSHIFT_VERSIONS)" >> bundle/metadata/annotations.yaml ;\
$(OPERATOR_SDK) bundle validate ./bundle
$(YQ) eval-all -i '.spec.relatedImages |= load("config/manifests/bases/operand-deployment-lifecycle-manager.clusterserviceversion.yaml").spec.relatedImages' bundle/manifests/operand-deployment-lifecycle-manager.clusterserviceversion.yaml
@# Need to replace fields this way to avoid changing PROJECT name and CSV file name, which may or may not impact CICD automation
$(YQ) e -i '.annotations["operators.operatorframework.io.bundle.package.v1"] = "ibm-odlm"' bundle/metadata/annotations.yaml
sed -i'' s/operand-deployment-lifecycle-manager/ibm-odlm/ bundle.Dockerfile
generate-all: yq manifests kustomize operator-sdk ## Generate bundle manifests, metadata and package manifests
GOTOOLCHAIN=auto GOSUMDB=sum.golang.org $(OPERATOR_SDK) generate kustomize manifests -q
- make bundle-manifests CHANNELS=v4.5 DEFAULT_CHANNEL=v4.5
##@ Test
test: setup-envtest ## Run unit test on prow
@echo "Running unit tests for the controllers."
@mkdir -p ${ENVCRDS_DIR}
@make fetch-test-crds
@$(ENVTEST) use 1.21
@OPERATOR_NAMESPACE="ibm-operators" go test ./controllers/... -coverprofile cover.out
@rm -rf ${ENVCRDS_DIR}
unit-test: generate code-fmt code-vet manifests ## Run unit test
@make test
e2e-test:
@echo ... Running the ODLM e2e test
@go test ./test/e2e/...
e2e-test-kind: build-test-operator-image kind-start kind-load-img deploy-e2e e2e-test kind-delete
e2e-test-fyre: build-push-test-image deploy-e2e
scorecard: operator-sdk ## Run scorecard test
@echo ... Running the scorecard test
- $(OPERATOR_SDK) scorecard bundle --verbose
kind-start: kind
@${KIND} get clusters | grep $(KIND_CLUSTER_NAME) >/dev/null 2>&1 && \
echo "KIND Cluster already exists" && exit 0 || \
echo "Creating KIND Cluster" && \
${KIND} create cluster --name ${KIND_CLUSTER_NAME} --config=./common/config/kind-config.yaml && \
common/scripts/install-olm.sh v0.24.0
kind-delete:
@echo Delete Kind cluster
@${KIND} delete cluster --name ${KIND_CLUSTER_NAME}
kind-load-img:
@echo Load ODLM images into Kind cluster
@${KIND} load docker-image $(QUAY_REGISTRY)/$(OPERATOR_IMAGE_NAME):$(OPERATOR_TEST_TAG) --name ${KIND_CLUSTER_NAME} -v 5
##@ Build
.PHONY: prepare-buildx
prepare-buildx:
@docker buildx inspect $(BUILDX_BUILDER) >/dev/null 2>&1 || docker buildx create --name $(BUILDX_BUILDER) --driver docker-container --use
@docker buildx use $(BUILDX_BUILDER)
build-operator-image: config-docker prepare-buildx ## Build the operator image.
@echo "Building the $(OPERATOR_IMAGE_NAME) docker image for $(LOCAL_ARCH)..."
@$(CONTAINER_TOOL) buildx build \
--builder $(BUILDX_BUILDER) \
--platform linux/$(LOCAL_ARCH) \
--build-arg VCS_REF=$(VCS_REF) \
--build-arg RELEASE_VERSION=$(RELEASE_VERSION) \
--build-arg TARGETOS=linux \
--build-arg TARGETARCH=$(LOCAL_ARCH) \
-t $(LOCAL_ARCH_IMAGE) \
--load \
-f Dockerfile .
@$(CONTAINER_TOOL) tag $(LOCAL_ARCH_IMAGE) $(RELEASE_IMAGE_ARCH)
build-push-image: config-docker build-operator-image ## Build and push the operator images.
@echo "Pushing $(OPERATOR_IMAGE_NAME) docker image for $(LOCAL_ARCH)..."
$(MAKE) docker-push IMG=$(RELEASE_IMAGE_ARCH)
.PHONY: docker-push
docker-push:
docker push $(IMG)
build-operator-dev-image: ## Build the operator dev image.
@echo "Building the $(DEV_REGISTRY)/$(OPERATOR_IMAGE_NAME) docker image..."
@docker build -t $(DEV_REGISTRY)/$(OPERATOR_IMAGE_NAME):$(BUILD_VERSION) \
--build-arg VCS_REF=$(VCS_REF) --build-arg RELEASE_VERSION=$(RELEASE_VERSION) \
--build-arg GOARCH=$(LOCAL_ARCH) -f Dockerfile .
build-test-operator-image: config-docker ## Build the operator test image.
@echo "Building the $(OPERATOR_IMAGE_NAME) docker image for testing..."
@docker build -t $(DEV_REGISTRY)/$(OPERATOR_IMAGE_NAME):$(OPERATOR_TEST_TAG) \
--build-arg VCS_REF=$(VCS_REF) --build-arg RELEASE_VERSION=$(RELEASE_VERSION) \
--build-arg GOARCH=$(LOCAL_ARCH) -f Dockerfile .
build-push-test-image: build-test-operator-image ## Build and push the operator test image.
@echo "Pushing the $(DEV_REGISTRY)/$(OPERATOR_IMAGE_NAME):$(OPERATOR_TEST_TAG) docker image to $(DEV_REGISTRY)..."
@docker push $(DEV_REGISTRY)/$(OPERATOR_IMAGE_NAME):$(OPERATOR_TEST_TAG)
##@ Release
build-push-dev-image: build-operator-dev-image ## Build and push the operator dev images.
@echo "Pushing the $(DEV_REGISTRY)/$(OPERATOR_IMAGE_NAME):$(BUILD_VERSION) docker image to $(DEV_REGISTRY)..."
@docker push $(DEV_REGISTRY)/$(OPERATOR_IMAGE_NAME):$(BUILD_VERSION)
build-push-bundle-image: yq
@docker build -f bundle.Dockerfile -t $(ICR_REIGSTRY)/$(BUNDLE_IMAGE_NAME)-$(LOCAL_ARCH):$(BUILD_VERSION) .
@echo "Pushing the $(BUNDLE_IMAGE_NAME) docker image for $(LOCAL_ARCH)..."
@docker push $(ICR_REIGSTRY)/$(BUNDLE_IMAGE_NAME)-$(LOCAL_ARCH):$(BUILD_VERSION)
build-catalog-source:
@opm -u docker index add --bundles $(ICR_REIGSTRY)/$(BUNDLE_IMAGE_NAME)-$(LOCAL_ARCH):$(BUILD_VERSION) --tag $(ICR_REIGSTRY)/$(OPERATOR_IMAGE_NAME)-catalog:$(BUILD_VERSION)
@docker push $(ICR_REIGSTRY)/$(OPERATOR_IMAGE_NAME)-catalog:$(BUILD_VERSION)
build-catalog: build-push-bundle-image build-catalog-source
multiarch-image: config-docker ## Generate multiarch images for operator image.
@MAX_PULLING_RETRY=20 RETRY_INTERVAL=30 common/scripts/multiarch_image.sh $(DOCKER_REGISTRY) $(OPERATOR_IMAGE_NAME) $(BUILD_VERSION) $(RELEASE_VERSION)
run-bundle:
$(OPERATOR_SDK) run bundle $(QUAY_REGISTRY)/$(BUNDLE_IMAGE_NAME)-$(LOCAL_ARCH):$(BUILD_VERSION) --install-mode OwnNamespace
cleanup-bundle:
$(OPERATOR_SDK) cleanup ibm-odlm
##@ Help
help: ## Display this help
@echo "Usage:\n make \033[36m<target>\033[0m"
@awk 'BEGIN {FS = ":.*##"}; \
/^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-20s\033[0m %s\n", $$1, $$2 } \
/^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
.PHONY: test