forked from openshift/assisted-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
355 lines (274 loc) · 13.8 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
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
NAMESPACE := $(or ${NAMESPACE},assisted-installer)
PWD = $(shell pwd)
BUILD_FOLDER = $(PWD)/build/$(NAMESPACE)
ROOT_DIR = $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
BUILD_TYPE := $(or ${BUILD_TYPE},standalone)
TARGET := $(or ${TARGET},minikube)
PROFILE := $(or $(PROFILE),minikube)
KUBECTL=kubectl -n $(NAMESPACE)
ifeq ($(BUILD_TYPE), standalone)
UNIT_TEST_TARGET = unit-test
else
UNIT_TEST_TARGET = convert-coverage
endif
ifeq ($(TARGET), minikube)
ifdef E2E_TESTS_MODE
E2E_TESTS_CONFIG = --img-expr-time=5m --img-expr-interval=5m
endif
define get_service
minikube -p $(PROFILE) service --url $(1) -n $(NAMESPACE) | sed 's/http:\/\///g'
endef # get_service
VERIFY_CLUSTER = _verify_minikube
else
define get_service
kubectl get service $(1) -n $(NAMESPACE) | grep $(1) | awk '{print $$4 ":" $$5}' | \
awk '{split($$0,a,":"); print a[1] ":" a[2]}'
endef # get_service
VERIFY_CLUSTER = _verify_cluster
endif # TARGET
ASSISTED_ORG := $(or ${ASSISTED_ORG},quay.io/ocpmetal)
ASSISTED_TAG := $(or ${ASSISTED_TAG},latest)
SERVICE := $(or ${SERVICE},${ASSISTED_ORG}/assisted-service:${ASSISTED_TAG})
CONTAINER_BUILD_PARAMS = --network=host --label git_revision=${GIT_REVISION} ${CONTAINER_BUILD_EXTRA_PARAMS}
# RHCOS_VERSION should be consistent with BaseObjectName in pkg/s3wrapper/client.go
RHCOS_BASE_ISO := $(or ${RHCOS_BASE_ISO},https://mirror.openshift.com/pub/openshift-v4/dependencies/rhcos/4.6/latest/rhcos-live.x86_64.iso)
OPENSHIFT_VERSIONS := $(or ${OPENSHIFT_VERSIONS}, $(shell cat default_ocp_versions.json | tr -d "\n\t "))
DUMMY_IGNITION := $(or ${DUMMY_IGNITION},False)
GIT_REVISION := $(shell git rev-parse HEAD)
PUBLISH_TAG := $(or ${GIT_REVISION})
APPLY_NAMESPACE := $(or ${APPLY_NAMESPACE},True)
ROUTE53_SECRET := ${ROUTE53_SECRET}
OCM_CLIENT_ID := ${OCM_CLIENT_ID}
OCM_CLIENT_SECRET := ${OCM_CLIENT_SECRET}
ENABLE_AUTH := $(or ${ENABLE_AUTH},False)
WITH_AMS_SUBSCRIPTIONS := $(or ${WITH_AMS_SUBSCRIPTIONS},False)
CHECK_CLUSTER_VERSION := $(or ${CHECK_CLUSTER_VERSION},False)
DELETE_PVC := $(or ${DELETE_PVC},False)
PUBLIC_CONTAINER_REGISTRIES := $(or ${PUBLIC_CONTAINER_REGISTRIES},quay.io)
PODMAN_PULL_FLAG := $(or ${PODMAN_PULL_FLAG},--pull always)
ENABLE_KUBE_API := $(or ${ENABLE_KUBE_API},false)
ifeq ($(ENABLE_KUBE_API),true)
ENABLE_KUBE_API_CMD = --enable-kube-api true
endif
# We decided to have an option to change replicas count only while running in minikube
# That line is checking if we run on minikube
# check if SERVICE_REPLICAS_COUNT was set and if yes change default value to required one
# Default for 1 replica
REPLICAS_COUNT = $(shell if ! [ "${TARGET}" = "minikube" ] && ! [ "${TARGET}" = "oc" ];then echo 3; else echo $(or ${SERVICE_REPLICAS_COUNT},1);fi)
ifdef INSTALLATION_TIMEOUT
INSTALLATION_TIMEOUT_FLAG = --installation-timeout $(INSTALLATION_TIMEOUT)
endif
# define focus flag for test so users can run individual tests or suites
ifdef FOCUS
GINKGO_FOCUS_FLAG = -ginkgo.focus="$(FOCUS)"
endif
REPORTS = $(ROOT_DIR)/reports
TEST_PUBLISH_FLAGS = --junitfile-testsuite-name=relative --junitfile-testcase-classname=relative --junitfile $(REPORTS)/unittest.xml
.EXPORT_ALL_VARIABLES:
all: build
ci-lint:
${ROOT_DIR}/tools/check-commits.sh
${ROOT_DIR}/tools/handle_ocp_versions.py
skipper $(MAKE) generate-all
git diff --exit-code # this will fail if generate-all caused any diff
lint:
golangci-lint run -v
$(BUILD_FOLDER):
mkdir -p $(BUILD_FOLDER)
format:
golangci-lint run --fix -v
generate:
./hack/generate.sh print_help
generate-%: ${BUILD_FOLDER}
./hack/generate.sh generate_$(subst -,_,$*)
##################
# Build & Update #
##################
.PHONY: build docs
build: lint $(UNIT_TEST_TARGET) build-minimal
build-all: build-in-docker
build-in-docker:
skipper make build-image
build-minimal: $(BUILD_FOLDER)
CGO_ENABLED=0 go build -o $(BUILD_FOLDER)/assisted-service cmd/main.go
build-image: build
docker build $(CONTAINER_BUILD_PARAMS) -f Dockerfile.assisted-service . -t $(SERVICE)
update-service: build-in-docker
docker push $(SERVICE)
update: build-all
docker push $(SERVICE)
update-minimal: build-minimal
docker build $(CONTAINER_BUILD_PARAMS) -f Dockerfile.assisted-service . -t $(SERVICE)
_update-minikube: build
eval $$(SHELL=$${SHELL:-/bin/sh} minikube -p $(PROFILE) docker-env) && \
docker build $(CONTAINER_BUILD_PARAMS) -f Dockerfile.assisted-service . -t $(SERVICE)
define publish_image
${1} tag ${2} ${3}
${1} push ${3}
endef # publish_image
publish:
$(call publish_image,docker,${SERVICE},quay.io/ocpmetal/assisted-service:${PUBLISH_TAG})
build-openshift-ci-test-bin:
pip3 install pyyaml waiting
##########
# Deploy #
##########
ifdef DEPLOY_TAG
DEPLOY_TAG_OPTION = --deploy-tag "$(DEPLOY_TAG)"
else ifdef DEPLOY_MANIFEST_PATH
DEPLOY_TAG_OPTION = --deploy-manifest-path "$(DEPLOY_MANIFEST_PATH)"
else ifdef DEPLOY_MANIFEST_TAG
DEPLOY_TAG_OPTION = --deploy-manifest-tag "$(DEPLOY_MANIFEST_TAG)"
endif
_verify_cluster:
$(KUBECTL) cluster-info
_verify_minikube:
minikube -p $(PROFILE) update-context
minikube -p $(PROFILE) status
deploy-all: $(BUILD_FOLDER) $(VERIFY_CLUSTER) deploy-namespace deploy-postgres deploy-s3 deploy-ocm-secret deploy-route53 deploy-service
echo "Deployment done"
deploy-ui: deploy-namespace
python3 ./tools/deploy_ui.py --target "$(TARGET)" --domain "$(INGRESS_DOMAIN)" --namespace "$(NAMESPACE)" --profile "$(PROFILE)" $(DEPLOY_TAG_OPTION)
deploy-namespace: $(BUILD_FOLDER)
python3 ./tools/deploy_namespace.py --deploy-namespace $(APPLY_NAMESPACE) --namespace "$(NAMESPACE)" --profile "$(PROFILE)" --target "$(TARGET)"
deploy-s3-secret:
python3 ./tools/deploy_scality_configmap.py --namespace "$(NAMESPACE)" --profile "$(PROFILE)" --target "$(TARGET)"
deploy-s3: deploy-namespace
python3 ./tools/deploy_s3.py --namespace "$(NAMESPACE)" --profile "$(PROFILE)" --target "$(TARGET)"
sleep 5; # wait for service to get an address
make deploy-s3-secret
deploy-route53: deploy-namespace
python3 ./tools/deploy_route53.py --secret "$(ROUTE53_SECRET)" --namespace "$(NAMESPACE)" --profile "$(PROFILE)" --target "$(TARGET)"
deploy-ocm-secret: deploy-namespace
python3 ./tools/deploy_sso_secret.py --secret "$(OCM_CLIENT_SECRET)" --id "$(OCM_CLIENT_ID)" --namespace "$(NAMESPACE)" --profile "$(PROFILE)" --target "$(TARGET)"
deploy-inventory-service-file: deploy-namespace
python3 ./tools/deploy_inventory_service.py --target "$(TARGET)" --domain "$(INGRESS_DOMAIN)" --namespace "$(NAMESPACE)" --profile "$(PROFILE)"
sleep 5; # wait for service to get an address
deploy-service-requirements: deploy-namespace deploy-inventory-service-file
python3 ./tools/deploy_assisted_installer_configmap.py --target "$(TARGET)" --domain "$(INGRESS_DOMAIN)" \
--base-dns-domains "$(BASE_DNS_DOMAINS)" --namespace "$(NAMESPACE)" --profile "$(PROFILE)" \
$(INSTALLATION_TIMEOUT_FLAG) $(DEPLOY_TAG_OPTION) --enable-auth "$(ENABLE_AUTH)" --with-ams-subscriptions "$(WITH_AMS_SUBSCRIPTIONS)" $(TEST_FLAGS) \
--ocp-versions '$(subst ",\",$(OPENSHIFT_VERSIONS))' --public-registries "$(PUBLIC_CONTAINER_REGISTRIES)" \
--check-cvo $(CHECK_CLUSTER_VERSION) $(ENABLE_KUBE_API_CMD) $(E2E_TESTS_CONFIG)
deploy-resources: generate-manifests
python3 ./tools/deploy_crd.py $(ENABLE_KUBE_API_CMD) --profile "$(PROFILE)" --target "$(TARGET)"
deploy-service: deploy-namespace deploy-service-requirements deploy-role deploy-resources
python3 ./tools/deploy_assisted_installer.py $(DEPLOY_TAG_OPTION) --namespace "$(NAMESPACE)" \
--profile "$(PROFILE)" $(TEST_FLAGS) --target "$(TARGET)" --replicas-count $(REPLICAS_COUNT) \
$(ENABLE_KUBE_API_CMD)
python3 ./tools/wait_for_assisted_service.py --target $(TARGET) --namespace "$(NAMESPACE)" \
--profile "$(PROFILE)" --domain "$(INGRESS_DOMAIN)"
deploy-role: deploy-namespace generate-manifests
python3 ./tools/deploy_role.py --namespace "$(NAMESPACE)" --profile "$(PROFILE)" --target "$(TARGET)" \
$(ENABLE_KUBE_API_CMD)
deploy-postgres: deploy-namespace
python3 ./tools/deploy_postgres.py --namespace "$(NAMESPACE)" --profile "$(PROFILE)" --target "$(TARGET)"
deploy-service-on-ocp-cluster:
export TARGET=ocp && $(MAKE) deploy-postgres deploy-ocm-secret deploy-s3-secret deploy-service
deploy-ui-on-ocp-cluster:
export TARGET=ocp && $(MAKE) deploy-ui
jenkins-deploy-for-subsystem: ci-deploy-for-subsystem
ci-deploy-for-subsystem: $(VERIFY_CLUSTER) generate-keys
export TEST_FLAGS=--subsystem-test && export ENABLE_AUTH="True" && export DUMMY_IGNITION=${DUMMY_IGNITION} && WITH_AMS_SUBSCRIPTIONS="True" && \
$(MAKE) deploy-wiremock deploy-all
deploy-test: $(VERIFY_CLUSTER) generate-keys
export ASSISTED_ORG=minikube-local-registry && export ASSISTED_TAG=minikube-test && export TEST_FLAGS=--subsystem-test && \
export ENABLE_AUTH="True" && export DUMMY_IGNITION="True" && export WITH_AMS_SUBSCRIPTIONS="True" && \
$(MAKE) _update-minikube deploy-wiremock deploy-all
# $SERVICE is built with docker. If we want the latest version of $SERVICE
# we need to pull it from the docker daemon before deploy-onprem.
podman-pull-service-from-docker-daemon:
podman pull "docker-daemon:${SERVICE}"
deploy-onprem:
# Format: ip:hostPort:containerPort | ip::containerPort | hostPort:containerPort | containerPort
podman pod create --name assisted-installer -p 5432:5432,8000:8000,8090:8090,8080:8080
# These are required because when running on RHCOS livecd, the coreos-installer binary and
# livecd are bind-mounted from the host into the assisted-service container at runtime.
[ -f livecd.iso ] || ./hack/retry.sh 5 1 "curl $(RHCOS_BASE_ISO) -o livecd.iso"
[ -f coreos-installer ] || podman run --privileged --pull=always -it --rm \
-v .:/data -w /data --entrypoint /bin/bash \
quay.io/coreos/coreos-installer:v0.7.0 -c 'cp /usr/sbin/coreos-installer /data/coreos-installer'
podman run -dt --pod assisted-installer --env-file onprem-environment --pull always --name db quay.io/ocpmetal/postgresql-12-centos7
podman run -dt --pod assisted-installer --env-file onprem-environment --pull always -v $(PWD)/deploy/ui/nginx.conf:/opt/bitnami/nginx/conf/server_blocks/nginx.conf:z --name ui quay.io/ocpmetal/ocp-metal-ui:latest
podman run -dt --pod assisted-installer --env-file onprem-environment ${PODMAN_PULL_FLAG} --env DUMMY_IGNITION=$(DUMMY_IGNITION) \
-v ./livecd.iso:/data/livecd.iso:z \
-v ./coreos-installer:/data/coreos-installer:z \
--restart always --name installer $(SERVICE)
./hack/retry.sh 90 2 "curl http://127.0.0.1:8090/ready"
deploy-onprem-for-subsystem:
export DUMMY_IGNITION="true" && $(MAKE) deploy-onprem
deploy-on-openshift-ci:
ln -s $(shell which oc) $(shell dirname $(shell which oc))/kubectl
export TARGET='oc' && export PROFILE='openshift-ci' && unset GOFLAGS && \
$(MAKE) ci-deploy-for-subsystem
oc get pods
docs:
mkdocs build
docs_serve:
mkdocs serve
########
# Test #
########
subsystem-run: test subsystem-clean
test:
INVENTORY=$(shell $(call get_service,assisted-service) | sed 's/http:\/\///g') \
DB_HOST=$(shell $(call get_service,postgres) | sed 's/http:\/\///g' | cut -d ":" -f 1) \
DB_PORT=$(shell $(call get_service,postgres) | sed 's/http:\/\///g' | cut -d ":" -f 2) \
OCM_HOST=$(shell $(call get_service,wiremock) | sed 's/http:\/\///g') \
TEST_TOKEN="$(shell cat $(BUILD_FOLDER)/auth-tokenString)" \
TEST_TOKEN_ADMIN="$(shell cat $(BUILD_FOLDER)/auth-tokenAdminString)" \
TEST_TOKEN_UNALLOWED="$(shell cat $(BUILD_FOLDER)/auth-tokenUnallowedString)" \
ENABLE_AUTH="true" \
WITH_AMS_SUBSCRIPTIONS="true" \
go test -v ./subsystem/... -count=1 $(GINKGO_FOCUS_FLAG) -ginkgo.v -timeout 120m
deploy-wiremock: deploy-namespace
python3 ./tools/deploy_wiremock.py --target $(TARGET) --namespace "$(NAMESPACE)" --profile "$(PROFILE)"
deploy-olm: deploy-namespace
python3 ./tools/deploy_olm.py --target $(TARGET) --profile $(PROFILE)
deploy-prometheus: $(BUILD_FOLDER) deploy-namespace
python3 ./tools/deploy_prometheus.py --target $(TARGET) --namespace "$(NAMESPACE)" --profile "$(PROFILE)"
deploy-grafana: $(BUILD_FOLDER)
python3 ./tools/deploy_grafana.py --target $(TARGET) --namespace "$(NAMESPACE)" --profile "$(PROFILE)"
deploy-monitoring: deploy-olm deploy-prometheus deploy-grafana
unit-test: $(REPORTS)
docker ps -q --filter "name=postgres" | xargs -r docker kill && sleep 3
docker run -d --rm --name postgres -e POSTGRES_PASSWORD=admin -e POSTGRES_USER=admin -p 127.0.0.1:5432:5432 \
quay.io/ocpmetal/postgres:12.3-alpine -c 'max_connections=10000'
timeout 5m ./hack/wait_for_postgres.sh
SKIP_UT_DB=1 gotestsum --format=pkgname $(TEST_PUBLISH_FLAGS) -- -cover -coverprofile=$(REPORTS)/coverage.out $(or ${TEST},${TEST},$(shell go list ./... | grep -v subsystem)) $(GINKGO_FOCUS_FLAG) \
-ginkgo.v -timeout 30m -count=1 || (docker kill postgres && /bin/false)
docker kill postgres
convert-coverage: unit-test
gocov convert $(REPORTS)/coverage.out | gocov-xml > $(REPORTS)/coverage.xml
$(REPORTS):
-mkdir -p $(REPORTS)
test-onprem:
INVENTORY=127.0.0.1:8090 \
DB_HOST=127.0.0.1 \
DB_PORT=5432 \
DEPLOY_TARGET=onprem \
go test -v ./subsystem/... -count=1 $(GINKGO_FOCUS_FLAG) -ginkgo.v -timeout 30m
test-on-openshift-ci:
export TARGET='oc' && export PROFILE='openshift-ci' && unset GOFLAGS && \
$(MAKE) test FOCUS="[minimal-set]"
#########
# Clean #
#########
clear-all: clean subsystem-clean clear-deployment clear-images clean-onprem
clean:
-rm -rf $(BUILD_FOLDER) $(REPORTS)
subsystem-clean:
-$(KUBECTL) get pod -o name | grep createimage | xargs -r $(KUBECTL) delete --force --grace-period=0 1> /dev/null || true
clear-deployment:
-python3 ./tools/clear_deployment.py --delete-namespace $(APPLY_NAMESPACE) --delete-pvc $(DELETE_PVC) --namespace "$(NAMESPACE)" --profile "$(PROFILE)" --target "$(TARGET)" || true
clear-images:
-docker rmi -f $(SERVICE)
-docker rmi -f $(ISO_CREATION)
clean-onprem:
podman pod rm -f assisted-installer || true
rm livecd.iso || true
rm coreos-installer || true
delete-minikube-profile:
minikube delete -p $(PROFILE)
delete-all-minikube-profiles:
minikube delete --all