From 1c496869647f5dc2506ef0050500fc9b2694b984 Mon Sep 17 00:00:00 2001 From: Cam Soper <cam.soper@microsoft.com> Date: Mon, 11 Dec 2023 23:12:37 +0000 Subject: [PATCH 1/2] Retry making ACR instance --- deploy/k8s/create-acr.sh | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/deploy/k8s/create-acr.sh b/deploy/k8s/create-acr.sh index 4ec60710..92001867 100755 --- a/deploy/k8s/create-acr.sh +++ b/deploy/k8s/create-acr.sh @@ -97,10 +97,21 @@ then echo fi -eshopRegistry=`az acr show -n $eshopAcrName --query "loginServer" -otsv` -if [ -z "$eshopRegistry" ] -then +echo "Giving AKS access to ACR instance \"$eshopAcrName\"..." +retryCount=0 +eshopRegistry="" + +while [ -z "$eshopRegistry" ] && [ $retryCount -lt 10 ]; do + eshopRegistry=$(az acr show -n $eshopAcrName --query "loginServer" -otsv) + if [ -z "$eshopRegistry" ]; then + echo "ACR instance wasn't ready. If this takes more than a minute or two, something is probably wrong. Trying again in 5 seconds..." + sleep 5 + retryCount=$((retryCount+1)) + fi +done + +if [ -z "$eshopRegistry" ]; then echo "${newline}${errorStyle}ERROR! ACR server $eshopAcrName doesn't exist!${defaultTextStyle}${newline}" exit 1 fi @@ -119,6 +130,7 @@ then az role assignment create \ --role AcrPull \ --assignee-object-id $aksIdentityObjectId \ + --assignee-principal-type ServicePrincipal \ --scope $acrResourceId \ --output none fi From 1b85024c5c7bd9aa20524aefe0dc40d85336bb70 Mon Sep 17 00:00:00 2001 From: Cam Soper <cam.soper@microsoft.com> Date: Tue, 12 Dec 2023 18:36:49 +0000 Subject: [PATCH 2/2] Better wait logic for ACR --- deploy/k8s/create-acr.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/deploy/k8s/create-acr.sh b/deploy/k8s/create-acr.sh index 92001867..b9195024 100755 --- a/deploy/k8s/create-acr.sh +++ b/deploy/k8s/create-acr.sh @@ -103,10 +103,13 @@ retryCount=0 eshopRegistry="" while [ -z "$eshopRegistry" ] && [ $retryCount -lt 10 ]; do + exec &> /dev/null eshopRegistry=$(az acr show -n $eshopAcrName --query "loginServer" -otsv) + exec >& /dev/tty + if [ -z "$eshopRegistry" ]; then - echo "ACR instance wasn't ready. If this takes more than a minute or two, something is probably wrong. Trying again in 5 seconds..." - sleep 5 + echo "ACR instance wasn't ready. I'll keep trying for up to 5 minutes..." + sleep 30 retryCount=$((retryCount+1)) fi done @@ -126,7 +129,6 @@ aksIdentityObjectId=$(az aks show -g $eshopRg -n $ESHOP_AKSNAME --query identity if [ ! -z "$aksIdentityObjectId" ] then acrResourceId=$(az acr show -n $eshopAcrName -g $eshopRg --query id -o tsv) - az role assignment create \ --role AcrPull \ --assignee-object-id $aksIdentityObjectId \