Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add makefile checks for missing required environment variables #20

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ ifneq (,$(wildcard ./.env))
export
endif

defined = $(strip $(filter-out undefined,$(flavor $1)))

required-environment-variables = \
$(eval .required-environment-variables :=) \
$(foreach V,$(sort $1), \
$(if $(call defined,$V),,$(eval .required-environment-variables += $V)) \
) \
$(if $(strip ${.required-environment-variables}), \
$(foreach V,${.required-environment-variables}, \
$(info Variable is not defined but required: $$$V) \
) \
$(error Not all required variables are defined) \
)

PYTHON?=python3.10
export PYTHON
TOX?=tox
Expand Down
11 changes: 11 additions & 0 deletions bicep.makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ ARO_VERSION?=4.14.16

.PHONY: aro-remove
aro-remove: ## Remove ARO
$(call required-environment-variables,ARO_RESOURCE_GROUP)
az deployment group create --resource-group ${ARO_RESOURCE_GROUP} --template-file bicep/empty.bicep --mode Complete

.PHONY: aro-deploy
aro-deploy: domain-zone-exists network-deploy ## Deploy ARO
$(call required-environment-variables,ARO_RESOURCE_GROUP ARO_CLUSTER_NAME ARO_DOMAIN ARO_VERSION CLIENT_ID CLIENT_SECRET)
@az deployment group create --resource-group ${ARO_RESOURCE_GROUP} \
--template-file bicep/aro.bicep \
--parameters \
Expand All @@ -24,23 +26,27 @@ aro-deploy: domain-zone-exists network-deploy ## Deploy ARO
.PHONY: domain-records
.ONESHELL:
domain-records: ## Create domain records for ARO
$(call required-environment-variables,ARO_RESOURCE_GROUP ARO_CLUSTER_NAME ARO_DOMAIN)
hack/domain-records.sh \
--domain ${ARO_DOMAIN} \
--aro-name ${ARO_CLUSTER_NAME} \
--aro-resource-group ${ARO_RESOURCE_GROUP}

.PHONY: network-deploy
network-deploy: ## Deploy network
$(call required-environment-variables,ARO_RESOURCE_GROUP)
az deployment group create --resource-group ${ARO_RESOURCE_GROUP} \
--template-file bicep/network.bicep

.PHONY: resource-group
resource-group: ## Create resource group
$(call required-environment-variables,ARO_RESOURCE_GROUP ARO_LOCATION)
az group create --name ${ARO_RESOURCE_GROUP} --location ${ARO_LOCATION} --query name -o tsv

.PHONY: service-principal
.ONESHELL:
service-principal: ## Create sevice principal for ARO deployment
$(call required-environment-variables,ARO_RESOURCE_GROUP)
az ad sp create-for-rbac \
--name "aro-service-principal" \
--role Contributor \
Expand All @@ -51,22 +57,27 @@ service-principal: ## Create sevice principal for ARO deployment
.PHONY: arorp-service-principal
.ONESHELL:
arorp-service-principal: ## Assign required roles to "Azure Red Hat Openshift" RP service principal
$(call required-environment-variables,ARO_RESOURCE_GROUP)
az role assignment create --assignee $$(az ad sp list --display-name "Azure Red Hat OpenShift RP" --query "[0].id" -o tsv) \
--role Contributor \
--scope "/subscriptions/$$(az account show --query id -o tsv)/resourceGroups/${ARO_RESOURCE_GROUP}"

aro-credentials: ## Get ARO credentials
$(call required-environment-variables,ARO_RESOURCE_GROUP ARO_CLUSTER_NAME)
@az aro list-credentials --name ${ARO_CLUSTER_NAME} --resource-group ${ARO_RESOURCE_GROUP}

aro-url: ## Get ARO URL
$(call required-environment-variables,ARO_RESOURCE_GROUP ARO_CLUSTER_NAME)
@az aro show --name ${ARO_CLUSTER_NAME} --resource-group ${ARO_RESOURCE_GROUP} --query "apiserverProfile.url" -o tsv

.PHONY: domain-zone-exists
domain-zone-exists: ## Fail if DNS domain zone does not exists
$(call required-environment-variables,ARO_DOMAIN)
ARO_DOMAIN=${ARO_DOMAIN} hack/domain-zone-exists.sh

.PHONY: oc-login
oc-login: ## Login with oc to existing ARO cluster
$(call required-environment-variables,ARO_CLUSTER_NAME ARO_RESOURCE_GROUP)
oc login "$(shell az aro show --name ${ARO_CLUSTER_NAME} --resource-group ${ARO_RESOURCE_GROUP} --query "apiserverProfile.url" -o tsv)" \
-u "$(shell az aro list-credentials --name ${ARO_CLUSTER_NAME} --resource-group ${ARO_RESOURCE_GROUP} --query 'kubeadminUsername' -o tsv)" \
-p "$(shell az aro list-credentials --name ${ARO_CLUSTER_NAME} --resource-group ${ARO_RESOURCE_GROUP} --query 'kubeadminPassword' -o tsv)"
9 changes: 9 additions & 0 deletions rosa.makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ CLUSTER_NAME?=sapeic

.PHONY: rosa-login
rosa-login: ## Login using ROSA token
$(call required-environment-variables,ROSA_TOKEN)
@rosa login --token="${ROSA_TOKEN}"

.PHONY: rosa-init
Expand All @@ -14,36 +15,44 @@ rosa-account-roles: ## Login using ROSA token

.PHONY: rosa-cluster
rosa-cluster: ## Create ROSA cluster
$(call required-environment-variables,ROSA_TOKEN CLUSTER_NAME)
rosa create cluster --cluster-name "${CLUSTER_NAME}"

.PHONY: rosa-cluster-status
rosa-cluster-status: ## Get ROSA cluster status
$(call required-environment-variables,ROSA_TOKEN CLUSTER_NAME)
rosa describe cluster --cluster "${CLUSTER_NAME}"

.PHONY: rosa-cluster-hibernate
rosa-cluster-hibernate: ## Hibernate ROSA cluster
$(call required-environment-variables,ROSA_TOKEN CLUSTER_NAME)
rosa hibernate cluster --cluster "${CLUSTER_NAME}"

.PHONY: rosa-cluster-resume
rosa-cluster-resume: ## Resume ROSA cluster
$(call required-environment-variables,ROSA_TOKEN CLUSTER_NAME)
rosa resume cluster --cluster "${CLUSTER_NAME}"

.PHONY: rosa-cluster-delete
rosa-cluster-delete: ## Delete ROSA cluster
$(call required-environment-variables,ROSA_TOKEN CLUSTER_NAME)
rosa delete cluster --cluster "${CLUSTER_NAME}"

.PHONY: rosa-cluster-admin
rosa-cluster-admin: ## Create cluster admin
$(call required-environment-variables,ROSA_TOKEN CLUSTER_NAME CLUSTER_ADMIN_PASSWORD)
@rosa create admin --cluster ${CLUSTER_NAME} --password ${CLUSTER_ADMIN_PASSWORD} >/dev/null
$(info cluster admin created)

.PHONY: rosa-cluster-admin-reset
rosa-cluster-admin-reset: ## Reset cluster admin password
$(call required-environment-variables,ROSA_TOKEN CLUSTER_NAME CLUSTER_ADMIN_PASSWORD)
@rosa delete admin --cluster ${CLUSTER_NAME} --yes >/dev/null
$(info cluster admin deleted)
@rosa create admin --cluster ${CLUSTER_NAME} --password ${CLUSTER_ADMIN_PASSWORD} >/dev/null
$(info cluster admin password reset)

.PHONY: rosa-cluster-oc-login
rosa-cluster-oc-login: ## OC cli login to existing cluster (cluster-admin should already exist)
$(call required-environment-variables,ROSA_TOKEN CLUSTER_NAME)
@rosa describe admin --cluster=${CLUSTER_NAME} | grep -v 'INFO'