
# VARIABLES

# API Docker Image
API_DOCKER_IMAGE_LOCAL_NAME = osl-camaraaas-qod-provisioning-api
API_DOCKER_IMAGE_LOCAL_TAG = latest
API_DOCKER_IMAGE_NAME_ON_REPOSITORY = osl-camaraaas-qod-provisioning-api
API_DOCKER_IMAGE_TAG_ON_REPOSITORY = latest

# Operator Docker Image
OPERATOR_DOCKER_IMAGE_LOCAL_NAME = osl-camaraaas-qod-provisioning-api-op
OPERATOR_DOCKER_IMAGE_LOCAL_TAG = latest
OPERATOR_DOCKER_IMAGE_NAME_ON_REPOSITORY = osl-camaraaas-qod-provisioning-api-op
OPERATOR_DOCKER_IMAGE_TAG_ON_REPOSITORY = latest

# VARIABLES TO UPDATE
REPOSITORY_HOST = atnog-harbor.av.it.pt/camaraaas
OPERATOR_NAMESPACE = osl-camara-controllers

# Dummy Operator Service
create-dummy-operator-crd:
	kubectl apply -f ./DummyOperatorService/crd.yaml

delete-dummy-operator-crd:
	kubectl delete -f ./DummyOperatorService/crd.yaml || true

create-dummy-operator-cr:
	kubectl apply -f ./DummyOperatorService/example-cr.yaml

delete-dummy-operator-cr:
	kubectl delete -f ./DummyOperatorService/example-cr.yaml || true

describe-dummy-operator-cr:
	kubectl describe dos example-dummy-operator-service || true


# CAMARAaaS QoD Provisioning API
build-api-docker-image:
	docker build -t $(API_DOCKER_IMAGE_LOCAL_NAME):$(API_DOCKER_IMAGE_LOCAL_TAG) ./QoDProvisioningAPI/API

tag-api-docker-image:
	docker tag $(API_DOCKER_IMAGE_LOCAL_NAME):$(API_DOCKER_IMAGE_LOCAL_TAG) $(REPOSITORY_HOST)/$(API_DOCKER_IMAGE_NAME_ON_REPOSITORY):$(API_DOCKER_IMAGE_TAG_ON_REPOSITORY)

push-api-docker-image:
	docker push $(REPOSITORY_HOST)/$(API_DOCKER_IMAGE_NAME_ON_REPOSITORY):$(API_DOCKER_IMAGE_TAG_ON_REPOSITORY)

api-docker-image: build-api-docker-image tag-api-docker-image push-api-docker-image


# CAMARAaaS QoD Provisioning API Operator
build-operator-docker-image:
	docker build -t $(OPERATOR_DOCKER_IMAGE_LOCAL_NAME):$(OPERATOR_DOCKER_IMAGE_LOCAL_TAG) ./QoDProvisioningAPI/Operator

tag-operator-docker-image:
	docker tag $(OPERATOR_DOCKER_IMAGE_LOCAL_NAME):$(OPERATOR_DOCKER_IMAGE_LOCAL_TAG) $(REPOSITORY_HOST)/$(OPERATOR_DOCKER_IMAGE_NAME_ON_REPOSITORY):$(OPERATOR_DOCKER_IMAGE_TAG_ON_REPOSITORY)

push-operator-docker-image:
	docker push $(REPOSITORY_HOST)/$(OPERATOR_DOCKER_IMAGE_NAME_ON_REPOSITORY):$(OPERATOR_DOCKER_IMAGE_TAG_ON_REPOSITORY)

operator-docker-image: build-operator-docker-image tag-operator-docker-image push-operator-docker-image


install-operator:
	helm install camaraaas-qod-prov-operator ./QoDProvisioningAPI/Operator/chart --set operator.image="$(REPOSITORY_HOST)/$(OPERATOR_DOCKER_IMAGE_NAME_ON_REPOSITORY):$(OPERATOR_DOCKER_IMAGE_TAG_ON_REPOSITORY)" --set camaraQoDAPI.image="$(REPOSITORY_HOST)/$(API_DOCKER_IMAGE_NAME_ON_REPOSITORY):$(API_DOCKER_IMAGE_TAG_ON_REPOSITORY)"  --namespace $(OPERATOR_NAMESPACE) --create-namespace

get-operator-logs:
	kubectl logs -f $$(kubectl get pods -n $(OPERATOR_NAMESPACE)  -l app=camaraaas-qod-provisioning-api-op -o jsonpath="{.items[0].metadata.name}") -n $(OPERATOR_NAMESPACE) 

uninstall-operator:
	helm uninstall camaraaas-qod-prov-operator -n $(OPERATOR_NAMESPACE) 


create-operator-test-cr:
	kubectl apply -f ./QoDProvisioningAPI/Operator/test-cr.yaml

describe-operator-test-cr:
	kubectl describe camaraaas-qod-provisioning-apis.org.etsi.osl test-qod-provisioning

delete-operator-test-cr:
	kubectl delete -f ./QoDProvisioningAPI/Operator/test-cr.yaml
