-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathMakefile
More file actions
491 lines (417 loc) · 21.7 KB
/
Copy pathMakefile
File metadata and controls
491 lines (417 loc) · 21.7 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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
# ====================================================================================
# Setup Project
PROJECT_NAME := crossplane-provider-btp
PROJECT_REPO := github.com/sap/$(PROJECT_NAME)
# Terraform Related variables
# OpenTofu (MPL-2.0) is used as the `terraform` CLI to avoid the BSL of
# Terraform CLI ≥ 1.6. We install the `tofu` binary under the name `terraform`
# everywhere upjet expects it — upjet's executor hardcodes the binary name
# "terraform" (workspace.go:413). OpenTofu is a drop-in replacement at the
# CLI level. Required for the identity-injector workaround (#521): identity
# forwarding to the provider lands in CLI 1.12+; OpenTofu 1.12+ has it too.
export TERRAFORM_VERSION ?= 1.12.3
export TERRAFORM_PROVIDER_SOURCE ?= SAP/btp
export TERRAFORM_PROVIDER_REPO ?= https://github.com/SAP/terraform-provider-btp
export TERRAFORM_PROVIDER_VERSION ?= 1.25.0
export TERRAFORM_PROVIDER_DOWNLOAD_NAME ?= terraform-provider-btp
export TERRAFORM_PROVIDER_DOWNLOAD_URL_PREFIX ?= https://releases.hashicorp.com/$(TERRAFORM_PROVIDER_DOWNLOAD_NAME)/$(TERRAFORM_PROVIDER_VERSION)
export TERRAFORM_NATIVE_PROVIDER_BINARY ?= terraform-provider-btp_v1.23.1_x5
export TERRAFORM_DOCS_PATH ?= docs/resources
# set BUILD_ID if its not running in an action
BUILD_ID ?= $(shell date +"%H%M%S")
export TEST_CRS_PATH ?= test/e2e/testdata/crs
export TEST_CRS_GENERATED_PATH ?= $(abspath .work/rendered-crs/e2e)
export UPGRADE_TEST_CRS_PATH ?= test/upgrade/testdata
export UPGRADE_TEST_CRS_GENERATED_PATH ?= $(abspath .work/rendered-crs/upgrade)
PLATFORMS ?= linux_amd64
#get version from current git release tag
VERSION ?= $(shell git describe --tags --exact-match 2>/dev/null || echo "v0.0.0-$$(git rev-parse HEAD)")
$(info VERSION is $(VERSION))
# Override to be Crossplane v2 compatible
ROOT_DIR := $(shell pwd)
export BUILD_REGISTRY := index.docker.io/build-$(shell echo $(HOSTNAME)-$(ROOT_DIR) | sha256sum | cut -c1-8)
-include build/makelib/common.mk
# Setup Output
-include build/makelib/output.mk
# Setup Versions
GO_REQUIRED_VERSION=1.25
GOLANGCILINT_VERSION ?= 2.12.2
NPROCS ?= 1
GO_TEST_PARALLEL := $(shell echo $$(( $(NPROCS) / 2 )))
GO_STATIC_PACKAGES = $(GO_PROJECT)/cmd/provider $(GO_PROJECT)/cmd/exporter
GO_LDFLAGS += -X $(GO_PROJECT)/internal/version.Version=$(VERSION)
# this version will eventually be passed to the terraform provider
GO_LDFLAGS += -X $(GO_PROJECT)/internal/version.ProviderVersion=$(VERSION)
GO_SUBDIRS += cmd internal apis
GO111MODULE = on
GOTOOLCHAIN = local
-include build/makelib/golang.mk
# Override the GO_LINT_ARGS from golang.mk to use updated golangci-lint parameters
# this can potentially be removed when we update to a newer version of the build
GO_LINT_ARGS = --output.checkstyle.path=$(GO_LINT_OUTPUT)/checkstyle.xml --output.text.path=stdout
# kind-related versions
KIND_VERSION ?= v0.23.0
KIND_NODE_IMAGE_TAG ?= v1.30.2
# Setup Kubernetes tools
-include build/makelib/k8s_tools.mk
# Setup Images
IMAGES = provider-btp
-include build/makelib/imagelight.mk
export UUT_CONFIG = $(BUILD_REGISTRY)/provider-btp-$(ARCH):latest
export UUT_XPKG = $(BUILD_REGISTRY)/provider-btp-xpkg:latest
export UUT_IMAGES = {"crossplane/provider-btp":"$(UUT_XPKG)"}
testFilter ?= .*
.PHONY: local-build
local-build: build xpkg.build.provider-btp
$(INFO) "Loading xpkg into docker as $(UUT_XPKG)"
@XPKG_FILE=$(XPKG_OUTPUT_DIR)/$(PLATFORM)/provider-btp-$(VERSION).xpkg && \
XPKG_SHA=$$(docker load -i $$XPKG_FILE | sed -n 's/.*ID: //p') && \
docker tag $$XPKG_SHA $(UUT_XPKG);
$(OK) "Built local images: $(UUT_CONFIG) $(UUT_XPKG)"
.PHONY: local-deploy-prebuilt
local-deploy-prebuilt:
$(INFO) "Loading prebuilt xpkg into docker as $(UUT_XPKG)"
@XPKG_FILE=$$(find $(XPKG_OUTPUT_DIR)/$(PLATFORM) -name "*.xpkg" | head -1) && \
XPKG_SHA=$$(docker load -i $$XPKG_FILE | sed -n 's/.*ID: //p') && \
docker tag $$XPKG_SHA $(UUT_XPKG)
$(OK) "Prebuilt xpkg loaded as $(UUT_XPKG)"
# ====================================================================================
# Setup XPKG
XPKGS ?= provider-btp
XPKG_REG_ORGS ?= ghcr.io/sap/crossplane-provider-btp/crossplane
-include build/makelib/xpkg.mk
# NOTE(hasheddan): we force image building to happen prior to xpkg build so that
# we ensure image is present in daemon.
xpkg.build.provider-btp: do.build.images
# NOTE(hasheddan): we ensure up is installed prior to running platform-specific
# build steps in parallel to avoid encountering an installation race condition.
build.init: $(UP)
# ====================================================================================
# Fallthrough
# run `make help` to see the targets and options
# We want submodules to be set up the first time `make` is run.
# We manage the build/ folder and its Makefiles as a submodule.
# The first time `make` is run, the includes of build/*.mk files will
# all fail, and this target will be run. The next time, the default as defined
# by the includes will be run instead.
fallthrough: submodules
@echo Initial setup complete. Running make again . . .
@make
# ====================================================================================
# Setup Terraform for fetching provider schema
TERRAFORM := $(TOOLS_HOST_DIR)/terraform-$(TERRAFORM_VERSION)
TERRAFORM_WORKDIR := $(WORK_DIR)/terraform
TERRAFORM_PROVIDER_SCHEMA := config/schema.json
terraform.buildvars: common.buildvars
@echo TERRAFORM_VERSION=$(TERRAFORM_VERSION)
@echo TERRAFORM_PROVIDER_SOURCE=$(TERRAFORM_PROVIDER_SOURCE)
@echo TERRAFORM_PROVIDER_REPO=$(TERRAFORM_PROVIDER_REPO)
@echo TERRAFORM_PROVIDER_VERSION=$(TERRAFORM_PROVIDER_VERSION)
@echo TERRAFORM_PROVIDER_DOWNLOAD_NAME=$(TERRAFORM_PROVIDER_DOWNLOAD_NAME)
@echo TERRAFORM_NATIVE_PROVIDER_BINARY=$(TERRAFORM_NATIVE_PROVIDER_BINARY)
@echo TERRAFORM_DOCS_PATH=$(TERRAFORM_DOCS_PATH)
@echo TERRAFORM=$(TERRAFORM)
@echo TERRAFORM_WORKDIR=$(TERRAFORM_WORKDIR)
@echo TERRAFORM_PROVIDER_SCHEMA=$(TERRAFORM_PROVIDER_SCHEMA)
$(TERRAFORM_PROVIDER_SCHEMA): $(TERRAFORM)
@$(INFO) generating provider schema for $(TERRAFORM_PROVIDER_SOURCE) $(TERRAFORM_PROVIDER_VERSION)
@mkdir -p $(TERRAFORM_WORKDIR)
@echo '{"terraform":[{"required_providers":[{"provider":{"source":"'"$(TERRAFORM_PROVIDER_SOURCE)"'","version":"'"$(TERRAFORM_PROVIDER_VERSION)"'"}}],"required_version":"'"$(TERRAFORM_VERSION)"'"}]}' > $(TERRAFORM_WORKDIR)/main.tf.json
@echo $(TERRAFORM_PROVIDER_VERSION)
@$(TERRAFORM) -chdir=$(TERRAFORM_WORKDIR) init > $(TERRAFORM_WORKDIR)/terraform-logs.txt 2>&1
@echo $(TERRAFORM_WORKDIR)
@$(TERRAFORM) -chdir=$(TERRAFORM_WORKDIR) providers schema -json=true > $(TERRAFORM_PROVIDER_SCHEMA) 2>> $(TERRAFORM_WORKDIR)/terraform-logs.txt
@echo $(TERRAFORM)
@echo $(TERRAFORM_PROVIDER_SOURCE)
@$(OK) generating provider schema for $(TERRAFORM_PROVIDER_SOURCE) $(TERRAFORM_PROVIDER_VERSION)
$(TERRAFORM):
@$(INFO) installing opentofu $(TERRAFORM_VERSION) as terraform $(HOSTOS)-$(HOSTARCH)
@mkdir -p $(TOOLS_HOST_DIR)/tmp-terraform
@curl -fsSL https://github.com/opentofu/opentofu/releases/download/v$(TERRAFORM_VERSION)/tofu_$(TERRAFORM_VERSION)_$(SAFEHOST_PLATFORM).zip -o $(TOOLS_HOST_DIR)/tmp-terraform/terraform.zip
@unzip $(TOOLS_HOST_DIR)/tmp-terraform/terraform.zip -d $(TOOLS_HOST_DIR)/tmp-terraform
@mv $(TOOLS_HOST_DIR)/tmp-terraform/tofu $(TERRAFORM)
@rm -fr $(TOOLS_HOST_DIR)/tmp-terraform
@$(OK) installing opentofu $(TERRAFORM_VERSION) as terraform $(HOSTOS)-$(HOSTARCH)
pull-docs:
@$(INFO) pull-docs called
@if [ ! -d "$(WORK_DIR)/$(TERRAFORM_PROVIDER_SOURCE)" ]; then \
mkdir -p "$(WORK_DIR)/$(TERRAFORM_PROVIDER_SOURCE)" && \
git clone -c advice.detachedHead=false --depth 1 --filter=blob:none --branch "v$(TERRAFORM_PROVIDER_VERSION)" --sparse "$(TERRAFORM_PROVIDER_REPO)" "$(WORK_DIR)/$(TERRAFORM_PROVIDER_SOURCE)"; \
fi
@git -C "$(WORK_DIR)/$(TERRAFORM_PROVIDER_SOURCE)" sparse-checkout set "$(TERRAFORM_DOCS_PATH)"
# cleans the .work directory used for upjet/tf provider. Necessary after tf provider version upgrades so we just do this every time to have a clean dir
.PHONY: clean-work
clean-work:
@$(INFO) cleaning work directory
@rm -rf .work
.PHONY: install-tools
install-tools:
@$(INFO) installing Go tools from go.mod
@$(GO) install tool
@$(OK) installing Go tools from go.mod
generate.init: install-tools clean-work $(TERRAFORM_PROVIDER_SCHEMA) pull-docs
.PHONY: $(TERRAFORM_PROVIDER_SCHEMA) pull-docs terraform.buildvars
# Update the submodules, such as the common build scripts.
submodules:
@git submodule sync
@git submodule update --init --recursive
# NOTE(hasheddan): the build submodule currently overrides XDG_CACHE_HOME in
# order to force the Helm 3 to use the .work/helm directory. This causes Go on
# Linux machines to use that directory as the build cache as well. We should
# adjust this behavior in the build submodule because it is also causing Linux
# users to duplicate their build cache, but for now we just make it easier to
# identify its location in CI so that we cache between builds.
go.cachedir:
@go env GOCACHE
# This is for running out-of-cluster locally, and is for convenience. Running
# this make target will print out the command which was used. For more control,
# try running the binary directly with different arguments.
run: go.build
@$(INFO) Running Crossplane locally out-of-cluster . . .
@# To see other arguments that can be provided, run the command with --help instead
$(GO_OUT_DIR)/provider --debug
debug: go.build
dlv debug ./cmd/provider --headless --listen=:2345 --log --api-version=2 --accept-multiclient -- --debug
dev-debug: $(KIND) $(KUBECTL)
@$(INFO) Creating kind cluster
@$(KIND) create cluster --name=$(PROJECT_NAME)-dev
@$(KUBECTL) cluster-info --context kind-$(PROJECT_NAME)-dev
@$(INFO) Installing Provider Template CRDs
@$(KUBECTL) apply -R -f package/crds
@$(INFO) Creating crossplane-system namespace
@$(KUBECTL) create ns crossplane-system
@$(INFO) Creating provider config and secret
@$(KUBECTL) apply -R -f examples/provider
@$(INFO) Now you can debug the provider with the IDE...
dev: $(KIND) $(KUBECTL)
@$(INFO) Creating kind cluster
@$(KIND) create cluster --name=$(PROJECT_NAME)-dev
@$(KUBECTL) cluster-info --context kind-$(PROJECT_NAME)-dev
@$(INFO) Installing Provider Template CRDs
@$(KUBECTL) apply -R -f package/crds
@$(INFO) Starting Provider Template controllers
@$(GO) run cmd/provider/main.go --debug
dev-clean: $(KIND) $(KUBECTL)
@$(INFO) Deleting kind cluster
@$(KIND) delete cluster --name=$(PROJECT_NAME)-dev
.PHONY: submodules fallthrough test-integration run dev dev-clean e2e.run-final
# ====================================================================================
# Special Targets
# Install gomplate
GOMPLATE_VERSION := 3.10.0
GOMPLATE := $(TOOLS_HOST_DIR)/gomplate-$(GOMPLATE_VERSION)
$(GOMPLATE):
@$(INFO) installing gomplate $(SAFEHOSTPLATFORM)
@mkdir -p $(TOOLS_HOST_DIR)
@curl -fsSLo $(GOMPLATE) https://github.com/hairyhenderson/gomplate/releases/download/v$(GOMPLATE_VERSION)/gomplate_$(SAFEHOSTPLATFORM) || $(FAIL)
@chmod +x $(GOMPLATE)
@$(OK) installing gomplate $(SAFEHOSTPLATFORM)
export GOMPLATE
# This target adds a new api type and its controller.
# You would still need to register new api in "apis/<provider>.go" and
# controller in "internal/controller/<provider>.go".
# Arguments:
# provider: Camel case name of your provider, e.g. GitHub, PlanetScale
# group: API group for the type you want to add.
# kind: Kind of the type you want to add
# apiversion: API version of the type you want to add. Optional and defaults to "v1alpha1"
provider.addtype: $(GOMPLATE)
@[ "${provider}" ] || ( echo "argument \"provider\" is not set"; exit 1 )
@[ "${group}" ] || ( echo "argument \"group\" is not set"; exit 1 )
@[ "${kind}" ] || ( echo "argument \"kind\" is not set"; exit 1 )
@PROVIDER=$(provider) GROUP=$(group) KIND=$(kind) APIVERSION=$(apiversion) ./hack/helpers/addtype.sh
define CROSSPLANE_MAKE_HELP
Crossplane Targets:
submodules Update the submodules, such as the common build scripts.
run Run crossplane locally, out-of-cluster. Useful for development.
endef
# The reason CROSSPLANE_MAKE_HELP is used instead of CROSSPLANE_HELP is because the crossplane
# binary will try to use CROSSPLANE_HELP if it is set, and this is for something different.
export CROSSPLANE_MAKE_HELP
crossplane.help:
@echo "$$CROSSPLANE_MAKE_HELP"
help-special: crossplane.help
.PHONY: crossplane.help help-special
######## Our Targets ###########
# run unit tests
test.run: go.test.unit
# e2e tests
e2e.run: test-acceptance
#run single test-e2e-long test with <make e2e testFilter=functionNameOfTest>
test-e2e-long: local-build $(KIND) $(HELM3) generate-test-crs
@$(INFO) running integration tests
go test -v $(PROJECT_REPO)/test/e2e -tags=e2e_long -count=1 -test.v -run '^$(testFilter)$$' -timeout 150m 2>&1 | tee test-output.log
@$(OK) integration tests passed
@echo "===========Test Summary==========="
@grep -E "PASS|FAIL" test-output.log
@case `tail -n 1 test-output.log` in \
*FAIL*) echo "❌ Error: Test failed"; exit 1 ;; \
*) echo "✅ All tests passed"; $(OK) integration tests passed ;; \
esac
#run single e2e test with <make e2e testFilter=functionNameOfTest>
# Deploy mechanism for test-acceptance. Default rebuilds locally (local dev);
# CI overrides to local-deploy-prebuilt to consume artifacts from the build job.
ACCEPTANCE_DEPLOY ?= local-build
.PHONY: test-acceptance
test-acceptance: $(ACCEPTANCE_DEPLOY) $(KIND) generate-test-crs
@$(INFO) running end-to-end tests
@$(INFO) Skipping long running tests
go test -v $(PROJECT_REPO)/test/e2e -tags=e2e -count=1 -test.v -run '^$(testFilter)$$' -timeout 120m 2>&1 | tee test-output.log
@echo "===========Test Summary==========="
@grep -E "PASS|FAIL" test-output.log
@case `tail -n 1 test-output.log` in \
*FAIL*) echo "❌ Error: Test failed"; exit 1 ;; \
*) echo "✅ All tests passed"; $(OK) integration tests passed ;; \
esac
.PHONY: test-acceptance-debug
test-acceptance-debug: local-build $(KIND) $(HELM3) generate-test-crs
@$(INFO) running end-to-end tests
@$(INFO) Skipping long running tests
go test -gcflags="all=-N -l" -c -v $(PROJECT_REPO)/test/e2e/ -tags=e2e -o ./test/e2e/test-acceptance-debug.test -timeout 30m
dlv exec ./test/e2e/test-acceptance-debug.test --wd ./test/e2e/ --headless --listen=:2345 --log --api-version=2 --accept-multiclient -- -test.count=1 -test.v -test.run '^$(testFilter)$$'; EXIT_CODE=$$?; rm ./test/e2e/test-acceptance-debug.test; exit $$EXIT_CODE
@$(OK) end-to-end tests passed
.PHONY: generate-test-crs
generate-test-crs:
@$(INFO) Rendering CRS templates from $(TEST_CRS_PATH) into $(TEST_CRS_GENERATED_PATH)
@if [ "$(abspath $(TEST_CRS_PATH))" = "$(abspath $(TEST_CRS_GENERATED_PATH))" ]; then \
echo "❌ TEST_CRS_PATH and TEST_CRS_GENERATED_PATH must differ; both point at $(TEST_CRS_PATH)"; \
exit 1; \
fi
@rm -rf "$(TEST_CRS_GENERATED_PATH)"
@mkdir -p "$(TEST_CRS_GENERATED_PATH)"
@cp -R "$(TEST_CRS_PATH)/." "$(TEST_CRS_GENERATED_PATH)/"
@# envsubst with an explicit allowlist — any other $VAR-shaped string in the
@# YAML (e.g. unrelated provider-config references) is preserved verbatim.
@for template in $$(find "$(TEST_CRS_GENERATED_PATH)" -type f -name "*.yaml"); do \
envsubst '$$BUILD_ID $$IDP_URL $$SECOND_DIRECTORY_ADMIN_EMAIL $$TECHNICAL_USER_EMAIL $$SERVICE_BROKER_URL $$SERVICE_BROKER_USERNAME' < $$template > $$template.tmp && mv $$template.tmp $$template; \
done
@$(OK) CRS rendered
# Generate external-name documentation from *_types.go files
.PHONY: docs.generate-external-name
docs.generate-external-name:
@$(INFO) Generating external-name documentation from *_types.go files
@$(GO) run ./scripts/generate-external-name-docs.go
@$(OK) External-name documentation generated
# ====================================================================================
# Upgrade Tests
# ====================================================================================
# If UPGRADE_TEST_CRS_TAG is not set, use UPGRADE_TEST_FROM_TAG as default
UPGRADE_TEST_CRS_TAG ?= $(UPGRADE_TEST_FROM_TAG)
.PHONY: generate-upgrade-test-crs
# Renders the upgrade-test fixtures from UPGRADE_TEST_CRS_PATH into
# UPGRADE_TEST_CRS_GENERATED_PATH. Templates stay untouched on disk.
generate-upgrade-test-crs: TEST_CRS_PATH := $(UPGRADE_TEST_CRS_PATH)
generate-upgrade-test-crs: TEST_CRS_GENERATED_PATH := $(UPGRADE_TEST_CRS_GENERATED_PATH)
generate-upgrade-test-crs: generate-test-crs
.PHONY: check-upgrade-test-vars
check-upgrade-test-vars:
@for var in UPGRADE_TEST_FROM_TAG UPGRADE_TEST_TO_TAG; do \
if [ -z "$${!var}" ]; then \
echo "❌ Error: $$var is not set"; exit 1; \
fi; \
done
.PHONY: pull-upgrade-test-version-crs
pull-upgrade-test-version-crs:
@if [ -z "$(UPGRADE_TEST_CRS_TAG)" ]; then \
echo "❌ Error: UPGRADE_TEST_CRS_TAG or UPGRADE_TEST_FROM_TAG is not set"; exit 1; \
fi
@$(INFO) "Pulling CRs from $(UPGRADE_TEST_CRS_TAG)"
@if [ "$(UPGRADE_TEST_CRS_TAG)" = "local" ]; then \
$(OK) "Using local CRs from test/upgrade/testdata/baseCRs/ (UPGRADE_TEST_CRS_TAG is \"local\")"; \
else \
$(INFO) "Attempting to check out CRs from tag $(UPGRADE_TEST_CRS_TAG)"; \
if git ls-tree -r $(UPGRADE_TEST_CRS_TAG) --name-only | grep -q "^test/upgrade/testdata/baseCRs/"; then \
$(INFO) "Checking out CRs to test/upgrade/testdata/baseCRs from $(UPGRADE_TEST_CRS_TAG)"; \
rm -r test/upgrade/testdata/baseCRs; \
mkdir -p test/upgrade/testdata/baseCRs; \
git archive $(UPGRADE_TEST_CRS_TAG) test/upgrade/testdata/baseCRs | tar -x --strip-components=2 -C test/upgrade; \
$(OK) "Checked out CRs to test/upgrade/testdata/baseCRs from $(UPGRADE_TEST_CRS_TAG)"; \
else \
$(WARN) "No CRs found for tag $(UPGRADE_TEST_CRS_TAG) at path test/upgrade/testdata/baseCRs/. Defaulting to local CRs"; \
fi; \
fi
.PHONY: build-upgrade-test-images
build-upgrade-test-images:
@if [ "$(UPGRADE_TEST_FROM_TAG)" == "local" ] || [ "$(UPGRADE_TEST_TO_TAG)" == "local" ]; then \
$(INFO) "Building local images (UPGRADE_TEST_FROM_TAG or UPGRADE_TEST_TO_TAG is \"local\")"; \
$(MAKE) local-build; \
$(OK) "Built local images for upgrade tests"; \
fi
.PHONY: upgrade-test
upgrade-test: $(KIND) check-upgrade-test-vars build-upgrade-test-images pull-upgrade-test-version-crs generate-upgrade-test-crs
@$(INFO) Running upgrade tests
@go test -tags=upgrade ./test/upgrade -v -short -count=1 -run '^$(testFilter)$$' -timeout 120m 2>&1 | tee upgrade-test-output.log
@echo "===========Test Summary==========="
@grep -E "PASS|FAIL" upgrade-test-output.log
@case `tail -n 1 upgrade-test-output.log` in \
*FAIL*) echo "❌ Error: Test failed"; exit 1 ;; \
*) echo "✅ All tests passed"; $(OK) Upgrade tests passed ;; \
esac
.PHONY: upgrade-test-debug
upgrade-test-debug: $(KIND) check-upgrade-test-vars build-upgrade-test-images pull-upgrade-test-version-crs generate-upgrade-test-crs
@$(INFO) Running upgrade tests
@cd test/upgrade && dlv test --listen=:2345 --headless=true --api-version=2 --build-flags="-tags=upgrade" -- -test.v -test.short -test.count=1 -test.timeout 120m -test.run '^$(testFilter)$$' 2>&1 | tee upgrade-test-output.log
@echo "===========Test Summary==========="
@grep -E "PASS|FAIL" upgrade-test-output.log
@case `tail -n 1 upgrade-test-output.log` in \
*FAIL*) echo "❌ Error: Test failed"; exit 1 ;; \
*) echo "✅ All tests passed"; $(OK) Upgrade tests passed ;; \
esac
.PHONY: upgrade-test-restore-crs
# Restores `test/upgrade/testdata/baseCRs` to HEAD. This undoes the working-tree
# overwrite that `pull-upgrade-test-version-crs` performs.
upgrade-test-restore-crs:
@$(INFO) Restoring test/upgrade/testdata/baseCRs
@git restore test/upgrade/testdata/baseCRs
@$(OK) CRs restored
.PHONY: upgrade-test-clean
upgrade-test-clean: upgrade-test-restore-crs
@$(INFO) Cleaning upgrade test artifacts
@rm -rf test/upgrade/logs
@rm -f upgrade-test-output.log
@$(OK) Upgrade test artifacts cleaned
@$(INFO) Deleting kind clusters
@$(KIND) get clusters 2>/dev/null | grep e2e | xargs -r -n1 $(KIND) delete cluster --name || true
@$(OK) Kind clusters deleted
@$(INFO) Cleaning BTP artifacts
@$(GO) run .github/workflows/cleanup.go
@$(OK) BTP artifacts cleaned
# ====================================================================================
# E2E Test Environment Setup
# ====================================================================================
# Interactively ask for the file paths containing each required e2e configuration value
# and write them into a .env file. Each variable's value is read from the specified file
# so that secrets never need to be typed on the command line.
.PHONY: e2e-tests-create-dot-env-from-files
e2e-tests-create-dot-env-from-files:
@echo "This target creates a .env file for e2e tests by reading each required"
@echo "configuration value from a file you specify."
@echo "See https://github.com/SAP/crossplane-provider-btp#required-configuration"
@echo ""
@> .env
@for entry in \
"BTP_TECHNICAL_USER:JSON file with BTP technical user credentials (email/username/password)" \
"CIS_CENTRAL_BINDING:JSON file with the cis-central service binding data" \
"CLI_SERVER_URL:File containing the BTP CLI server URL (e.g. https://cli.btp.cloud.sap/)" \
"GLOBAL_ACCOUNT:File containing the global account subdomain" \
"IDP_URL:File containing the IDP URL connectable to the global account" \
"SECOND_DIRECTORY_ADMIN_EMAIL:File containing a second admin email (different from technical user)" \
"TECHNICAL_USER_EMAIL:File containing the email address of the BTP technical user" \
; do \
varname=$${entry%%:*}; \
description=$${entry#*:}; \
printf "%s\n (%s)\n Path: " "$$varname" "$$description" >&2; \
read -r filepath; \
if [ -z "$$filepath" ]; then \
echo "⚠️ Skipping $$varname (no path provided)" >&2; \
continue; \
fi; \
if [ ! -f "$$filepath" ]; then \
echo "❌ Error: file not found: $$filepath" >&2; exit 1; \
fi; \
value=$$(cat "$$filepath"); \
printf '%s=%s\n' "$$varname" "$$value" >> .env; \
echo "✅ $$varname written" >&2; \
done
@echo ""
@$(OK) .env file created