Skip to content

Commit

Permalink
add required environment variables checks
Browse files Browse the repository at this point in the history
Signed-off-by: kksat <[email protected]>
  • Loading branch information
kksat committed Aug 26, 2024
1 parent c1c9ee3 commit ebecce0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
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'

0 comments on commit ebecce0

Please sign in to comment.