Skip to content

Commit

Permalink
chore(ci): use ephemeral AKS cluster with fallback (#2145)
Browse files Browse the repository at this point in the history
* chore(ci): AKS use ephemeral cluster with fallback

* Better log messages
  • Loading branch information
zdrapela authored Jan 6, 2025
1 parent d22cfc0 commit a0dff4b
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions .ibm/pipelines/jobs/aks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,30 @@ handle_aks() {
echo "Starting AKS deployment"
for file in ${DIR}/cluster/aks/*.sh; do source $file; done

export K8S_CLUSTER_TOKEN=$(cat /tmp/secrets/AKS_CLUSTER_TOKEN)
export K8S_CLUSTER_TOKEN_ENCODED=$(printf "%s" $K8S_CLUSTER_TOKEN | base64 | tr -d '\n')
export K8S_SERVICE_ACCOUNT_TOKEN=$K8S_CLUSTER_TOKEN_ENCODED
export OCM_CLUSTER_TOKEN=$K8S_CLUSTER_TOKEN_ENCODED

export K8S_CLUSTER_ROUTER_BASE=$AKS_INSTANCE_DOMAIN_NAME
export NAME_SPACE_K8S="showcase-k8s-ci-nightly"
export NAME_SPACE_RBAC_K8S="showcase-rbac-k8s-ci-nightly"

url="https://${K8S_CLUSTER_ROUTER_BASE}"

az_login
az_aks_start "${AKS_NIGHTLY_CLUSTER_NAME}" "${AKS_NIGHTLY_CLUSTER_RESOURCEGROUP}"
az_aks_approuting_enable "${AKS_NIGHTLY_CLUSTER_NAME}" "${AKS_NIGHTLY_CLUSTER_RESOURCEGROUP}"
az_aks_get_credentials "${AKS_NIGHTLY_CLUSTER_NAME}" "${AKS_NIGHTLY_CLUSTER_RESOURCEGROUP}"

export K8S_CLUSTER_URL=$(oc whoami --show-server)
export K8S_CLUSTER_API_SERVER_URL=$(printf "%s" "$K8S_CLUSTER_URL" | base64 | tr -d '\n')
export OCM_CLUSTER_URL=$(printf "%s" "$K8S_CLUSTER_URL" | base64 | tr -d '\n')
if kubectl auth whoami > /dev/null 2>&1; then
echo "Using an ephemeral AKS cluster."
else
echo "Falling back to a long-running AKS cluster."
export K8S_CLUSTER_TOKEN=$(cat /tmp/secrets/AKS_CLUSTER_TOKEN)
export K8S_CLUSTER_TOKEN_ENCODED=$(printf "%s" $K8S_CLUSTER_TOKEN | base64 | tr -d '\n')
export K8S_SERVICE_ACCOUNT_TOKEN=$K8S_CLUSTER_TOKEN_ENCODED
export OCM_CLUSTER_TOKEN=$K8S_CLUSTER_TOKEN_ENCODED

az_login
az_aks_start "${AKS_NIGHTLY_CLUSTER_NAME}" "${AKS_NIGHTLY_CLUSTER_RESOURCEGROUP}"
az_aks_approuting_enable "${AKS_NIGHTLY_CLUSTER_NAME}" "${AKS_NIGHTLY_CLUSTER_RESOURCEGROUP}"
az_aks_get_credentials "${AKS_NIGHTLY_CLUSTER_NAME}" "${AKS_NIGHTLY_CLUSTER_RESOURCEGROUP}"

export K8S_CLUSTER_URL=$(oc whoami --show-server)
export K8S_CLUSTER_API_SERVER_URL=$(printf "%s" "$K8S_CLUSTER_URL" | base64 | tr -d '\n')
export OCM_CLUSTER_URL=$(printf "%s" "$K8S_CLUSTER_URL" | base64 | tr -d '\n')
fi

initiate_aks_deployment
check_and_test "${RELEASE_NAME}" "${NAME_SPACE_K8S}" "${url}"
Expand All @@ -32,5 +37,3 @@ handle_aks() {
check_and_test "${RELEASE_NAME_RBAC}" "${NAME_SPACE_RBAC_K8S}" "${rbac_rhdh_base_url}"
delete_namespace "${NAME_SPACE_RBAC_K8S}"
}


0 comments on commit a0dff4b

Please sign in to comment.