.PHONY: all
all: e2e

SELECTOR ?= ""
.PHONY: e2e
e2e: bin/e2e
	bin/e2e \
		--base-context arn:aws:eks:us-west-2:385595570414:cluster/staging-base-us-west-2 \
		--infra-api-context infra-staging \
		--aws.region us-west-2 \
		--aws.profile dbaas-dev \
		--aws.account aws-200683210682 \
		--aws.old-provider.runtime-type docker \
		--aws.old-provider.runtime-image 385595570414.dkr.ecr.us-west-2.amazonaws.com/tidbcloud/eks-provider:73c42a100a4621d0fddd6275d47ab2caa54af39d \
		--aws.old-provider.runtime-extra-args -v,$(HOME)/.aws:/.aws \
		--aws.old-provider.runtime-extra-args -v,$(shell which aws-iam-authenticator):/usr/local/bin/aws-iam-authenticator \
		--aws.old-provider.cmd /eks-provider \
		--aws.old-provider.config $(CURDIR)/config/old-config.yaml \
		--aws.new-provider.runtime-type docker \
		--aws.new-provider.runtime-image localhost/infra-provider \
		--aws.new-provider.runtime-extra-args -v,$(HOME)/.aws:/.aws \
		--aws.new-provider.runtime-extra-args -v,$(shell which aws-iam-authenticator):/usr/local/bin/aws-iam-authenticator \
		--aws.new-provider.cmd /eks-provider \
		--aws.new-provider.config $(CURDIR)/config/new-config.yaml \
		--selector $(SELECTOR)

.PHONY: bin/e2e
bin/e2e:
	go test -c ./e2e -o bin/e2e

.PHONY: bin/infra-provider
bin/infra-provider:
	go build -v -o bin/infra-provider github.com/tidbcloud/eks-provider

clean:
	kubectl delete --wait=false --ignore-not-found networkpeer -n tidbcloud-system --all
	kubectl delete --wait=false --ignore-not-found cluster -n tidbcloud-system test
	kubectl delete --wait=true --ignore-not-found function e2e-end-user-test
	kubectl delete --wait=true --ignore-not-found vpcendpoint e2e-end-user-test
	kubectl delete --wait=false --ignore-not-found securitygroup e2e-end-user-test
	kubectl delete --wait=false --ignore-not-found subnet e2e-end-user-us-west-2a-test e2e-end-user-us-west-2b-test e2e-end-user-us-west-2c-test
	kubectl delete --wait=true --ignore-not-found vpc e2e-end-user-test
