-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
252 lines (201 loc) · 10.5 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
# Copyright 2020 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.
$(eval GIT_COMMIT := $(shell git rev-parse --short HEAD))
$(eval VCS_REF := $(GIT_COMMIT))
GIT_REMOTE_URL = $(shell git config --get remote.origin.url)
$(eval DOCKER_BUILD_OPTS := --build-arg "VCS_REF=$(VCS_REF)" --build-arg "VCS_URL=$(GIT_REMOTE_URL)")
# Default goal
.DEFAULT_GOAL:=help
# This repo is build locally for dev/test by default;
# Override this variable in CI env.
BUILD_LOCALLY ?= 1
# The namespace that the test operator will be deployed in
NAMESPACE=ibm-common-services
# Image URL to use all building/pushing image targets;
# Use your own docker registry and image name for dev/test by overridding the IMG and REGISTRY environment variable.
IMG ?= ibm-helm-repo-operator
REGISTRY ?= "hyc-cloud-private-integration-docker-local.artifactory.swg-devops.com/ibmcom"
CSV_VERSION ?= 3.6.4
QUAY_USERNAME ?=
QUAY_PASSWORD ?=
# Github host to use for checking the source tree;
# Override this variable ue with your own value if you're working on forked repo.
GIT_HOST ?= github.com/IBM
BASE_DIR := ibm-helm-repo-operator
TESTARGS_DEFAULT := "-v"
export TESTARGS ?= $(TESTARGS_DEFAULT)
DEST := $(GIT_HOST)/$(BASE_DIR)
VERSION ?= $(shell cat ./helm-charts/helm-repo/Chart.yaml | grep "^version" | awk '{print $$2}')
LOCAL_OS := $(shell uname)
LOCAL_ARCH := $(shell uname -m)
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
all: check test build images
include commonUtil/Makefile.common.mk
############################################################
# check section
############################################################
check: lint ## Check all files lint error
# All available linters: lint-dockerfiles lint-scripts lint-yaml lint-copyright-banner lint-go lint-python lint-helm lint-markdown lint-sass lint-typescript lint-protos
# Default value will run all linters, override these make target with your requirements:
# eg: lint: lint-go lint-yaml
lint: lint-all
############################################################
# csv section
############################################################
generate-csv: ## Generate CSV
- operator-sdk generate csv --csv-version $(CSV_VERSION) --make-manifests=false
- cp deploy/crds/*_crd.yaml deploy/olm-catalog/$(BASE_DIR)/$(CSV_VERSION)/
push-csv: ## Push CSV package to the catalog
@RELEASE=${CSV_VERSION} commonUtil/scripts/push-csv.sh
############################################################
# test section
############################################################
generate-scorecard: ## Generate scorecard yaml
@echo ... Generating .osdk-scorecard.yaml ...
- commonUtil/scripts/generate-scorecard.sh $(CSV_VERSION)
scorecard: ## Run scorecard test
@echo ... Running the scorecard test
- operator-sdk scorecard --verbose
test: test-e2e ## Run integration e2e tests with different options
test-e2e:
@echo ... Running the same e2e tests with different args ...
@echo ... Running locally ...
- operator-sdk test local ./test/e2e --verbose --up-local --namespace=${NAMESPACE}
# @echo ... Running with the param ...
# - operator-sdk test local ./test/e2e --namespace=${NAMESPACE}
############################################################
# images section
############################################################
ifeq ($(BUILD_LOCALLY),0)
export CONFIG_DOCKER_TARGET = config-docker
config-docker:
endif
build: install-operator-sdk $(CONFIG_DOCKER_TARGET) build-amd64 build-ppc64le build-s390x ## Build multi-arch operator images
build-amd64:
$(eval ARCH := $(shell uname -m|sed 's/x86_64/amd64/'))
@echo "Building the ${IMG} amd64 binary..."
@operator-sdk build --image-build-args "-f build/Dockerfile $(DOCKER_BUILD_OPTS)" $(REGISTRY)/$(IMG)-amd64:$(VERSION)
build-ppc64le:
@echo "Building the ${IMG} ppc64le binary..."
@operator-sdk build --image-build-args "-f build/Dockerfile.ppc64le $(DOCKER_BUILD_OPTS)" $(REGISTRY)/$(IMG)-ppc64le:$(VERSION)
build-s390x:
@echo "Building the ${IMG} s390x binary..."
@operator-sdk build --image-build-args "-f build/Dockerfile.s390x $(DOCKER_BUILD_OPTS)" $(REGISTRY)/$(IMG)-s390x:$(VERSION)
############################################################
# Image section
############################################################
images: clean build push ## Release multi-arch operator image
push: push-amd64 push-ppc64le push-s390x push-multi-arch
push-amd64:
docker push $(REGISTRY)/$(IMG)-amd64:$(VERSION)
push-ppc64le:
docker push $(REGISTRY)/$(IMG)-ppc64le:$(VERSION)
push-s390x:
docker push $(REGISTRY)/$(IMG)-s390x:$(VERSION)
push-multi-arch:
ifeq ($(TARGET_OS),$(filter $(TARGET_OS),linux darwin))
@curl -L -o /tmp/manifest-tool https://github.com/estesp/manifest-tool/releases/download/v0.7.0/manifest-tool-$(TARGET_OS)-amd64
@chmod +x /tmp/manifest-tool
@echo "Merging and push multi-arch image $(REGISTRY)/$(IMG):latest"
@/tmp/manifest-tool --username $(QUAY_USERNAME) --password $(QUAY_PASSWORD) push from-args --platforms linux/amd64,linux/ppc64le,linux/s390x --template $(REGISTRY)/$(IMG)-ARCH:$(VERSION) --target $(REGISTRY)/$(IMG):latest --ignore-missing
@echo "Merging and push multi-arch image $(REGISTRY)/$(IMG):v$(VERSION)"
@/tmp/manifest-tool --username $(QUAY_USERNAME) --password $(QUAY_PASSWORD) push from-args --platforms linux/amd64,linux/ppc64le,linux/s390x --template $(REGISTRY)/$(IMG)-ARCH:$(VERSION) --target $(REGISTRY)/$(IMG):$(VERSION) --ignore-missing
endif
############################################################
# Dev image section
############################################################
dev-image: clean build-amd64 push-amd64-dev ## Release development amd64 operator image
push-amd64-dev:
@docker tag $(REGISTRY)/$(IMG)-amd64:$(VERSION) quay.io/opencloudio/$(IMG):dev
@docker push quay.io/opencloudio/$(IMG):dev
############################################################
# application section
############################################################
install: ## Install all resources (CR/CRD's, RBCA and Operator)
@echo ....... Set environment variables ......
- export DEPLOY_DIR=deploy/crds
- export WATCH_NAMESPACE=${NAMESPACE}
@echo ....... Applying CRDS and Operator .......
- for crd in $(shell ls deploy/crds/*_crd.yaml); do kubectl apply -f $${crd}; done
@echo ....... Applying RBAC .......
- kubectl apply -f deploy/service_account.yaml -n ${NAMESPACE}
- kubectl apply -f deploy/role.yaml -n ${NAMESPACE}
- kubectl apply -f deploy/role_binding.yaml -n ${NAMESPACE}
@echo ....... Applying Operator .......
- cat deploy/olm-catalog/${BASE_DIR}/${CSV_VERSION}/${BASE_DIR}.v${CSV_VERSION}.clusterserviceversion.yaml | sed -f hack/csv_images.sed | kubectl -n ${NAMESPACE} apply -f -
@echo ....... Creating the Instance .......
- kubectl apply -f deploy/crds/operator.ibm.com_*_cr.yaml -n ${NAMESPACE}
uninstall: ## Uninstall all that all performed in the $ make install
@echo ....... Uninstalling .......
@echo ....... Deleting CR .......
- kubectl delete -f deploy/crds/operator.ibm.com_*_cr.yaml -n ${NAMESPACE}
@echo ....... Deleting Operator .......
- kubectl delete -f deploy/olm-catalog/${BASE_DIR}/${CSV_VERSION}/${BASE_DIR}.v${CSV_VERSION}.clusterserviceversion.yaml -n ${NAMESPACE}
@echo ....... Deleting CRDs.......
- for crd in $(shell ls deploy/crds/*_crd.yaml); do kubectl delete -f $${crd}; done
@echo ....... Deleting Rules and Service Account .......
- kubectl delete -f deploy/role_binding.yaml -n ${NAMESPACE}
- kubectl delete -f deploy/service_account.yaml -n ${NAMESPACE}
- kubectl delete -f deploy/role.yaml -n ${NAMESPACE}
clean-cluster: ## Clean up all the artifacts left in cluster
@echo ....... Cleaning up .......
- kubectl -n ${NAMESPACE} get helmrepos -o name | xargs kubectl -n ${NAMESPACE} delete
- kubectl -n ${NAMESPACE} get csv -o name | grep helm-repo | xargs kubectl -n ${NAMESPACE} delete
- kubectl -n ${NAMESPACE} get sub -o name | grep helm-repo | xargs kubectl -n ${NAMESPACE} delete
- kubectl -n ${NAMESPACE} get installplans | grep helm-repo | awk '{print $$1}' | xargs kubectl -n ${NAMESPACE} delete installplan
- kubectl -n ${NAMESPACE} get serviceaccounts -o name | grep helm-repo | xargs kubectl -n ${NAMESPACE} delete
- kubectl get clusterrole -o name | grep helm-repo | xargs kubectl delete
- kubectl get clusterrolebinding -o name | grep helm-repo | xargs kubectl delete
- kubectl get crd -o name | grep helmrepo | xargs kubectl delete
############################################################
# operator source section
############################################################
operatorsource: ## Create opencloud-operators operator source
- kubectl delete -f commonUtil/resources/opencloud-operators.yaml
- kubectl apply -f commonUtil/resources/opencloud-operators.yaml
############################################################
# bump up csv section
############################################################
bump-up-csv: ## Bump up CSV version
@commonUtil/scripts/bump-up-csv.sh ${BASE_DIR} $(CSV_VERSION)
############################################################
# configure githooks
############################################################
configure-githooks: ## Configure githooks
- git config core.hooksPath .githooks
############################################################
# clean section
############################################################
clean: ## Clean build binary
@docker images | grep "${REGISTRY}/${IMG}" | tr -s ' ' | awk -F' ' '{print $$3}' | xargs -I {} docker rmi {}
@rm -f build/_output/bin/$(IMG)
############################################################
# help section
############################################################
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: all build check lint test images