Skip to content

Commit

Permalink
Merge pull request WASdev#115 from majguo/fix-prefight-failure
Browse files Browse the repository at this point in the history
Fix deployment failure when using an existing ARO cluster
  • Loading branch information
venunathb authored Apr 5, 2024
2 parents f2f64a4 + 30a7286 commit 963b04a
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<groupId>com.ibm.websphere.azure</groupId>
<artifactId>azure.liberty.aro</artifactId>
<version>1.0.53</version>
<version>1.0.54</version>

<parent>
<groupId>com.microsoft.azure.iaas</groupId>
Expand Down
64 changes: 62 additions & 2 deletions src/main/arm/mainTemplate.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@
"name_clusterVNetName": "[concat('vnet', variables('const_suffix'))]",
"name_deploymentScriptName": "[concat('aroscript', variables('const_suffix'))]",
"name_preflightDSName": "[concat('preflight', variables('const_suffix'))]",
"name_roleAssignmentName": "[guid(format('{0}{1}Role assignment in group{0}', resourceGroup().id, variables('ref_identityId')))]",
"name_roleAssignmentName": "[guid(format('{0}{1}Role assignment in group{0}', resourceGroup().name, variables('ref_identityId')))]",
"name_roleAssignmentToCluserRGName": "[guid(format('{0}{1}Role assignment in group{0}', variables('const_clusterRGName'), variables('ref_identityId')))]",
"ref_identityId": "[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', variables('const_identityName'))]"
},
"resources": [
Expand Down Expand Up @@ -225,13 +226,68 @@
"principalType": "ServicePrincipal"
}
},
{
"condition": "[not(parameters('createCluster'))]",
"type": "Microsoft.Resources/deployments",
"apiVersion": "${azure.apiVersion.deployments}",
"name": "[variables('name_roleAssignmentToCluserRGName')]",
"resourceGroup": "[variables('const_clusterRGName')]",
"dependsOn": [
"[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', variables('const_identityName'))]"
],
"properties": {
"expressionEvaluationOptions": {
"scope": "inner"
},
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"roleAssignmentName": {
"type": "string"
},
"contributorRole": {
"type": "string"
},
"principalId": {
"type": "string"
}
},
"resources": [
{
"type": "Microsoft.Authorization/roleAssignments",
"apiVersion": "${azure.apiVersion.roleAssignment}",
"name": "[parameters('roleAssignmentName')]",
"properties": {
"roleDefinitionId": "[parameters('contributorRole')]",
"principalId": "[parameters('principalId')]",
"principalType": "ServicePrincipal"
}
}
]
},
"parameters": {
"roleAssignmentName": {
"value": "[variables('name_roleAssignmentToCluserRGName')]"
},
"contributorRole": {
"value": "[variables('const_contribRole')]"
},
"principalId": {
"value": "[reference(variables('ref_identityId')).principalId]"
}
}
}
},
{
"type": "Microsoft.Resources/deploymentScripts",
"apiVersion": "${azure.apiVersion.deploymentScript}",
"name": "[variables('name_preflightDSName')]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Authorization/roleAssignments', variables('name_roleAssignmentName'))]"
"[resourceId('Microsoft.Authorization/roleAssignments', variables('name_roleAssignmentName'))]",
"[resourceId(variables('const_clusterRGName'), 'Microsoft.Resources/deployments', variables('name_roleAssignmentToCluserRGName'))]"
],
"kind": "AzureCLI",
"identity": {
Expand All @@ -244,6 +300,10 @@
"AzCliVersion": "2.41.0",
"primaryScriptUri": "[uri(variables('const_scriptLocation'), concat('preflight.sh', parameters('_artifactsLocationSasToken')))]",
"environmentVariables": [
{
"name": "CREATE_CLUSTER",
"value": "[parameters('createCluster')]"
},
{
"name": "AAD_CLIENT_ID",
"value": "[parameters('aadClientId')]"
Expand Down
18 changes: 10 additions & 8 deletions src/main/scripts/preflight.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@

set -Eeuo pipefail

# Fail fast the deployment if object Id of the service principal is empty
if [[ -z "$AAD_OBJECT_ID" ]]; then
echo "The object Id of the service principal you just created is not successfully retrieved, please retry another deployment using its client id ${AAD_CLIENT_ID}." >&2
exit 1
fi
if [[ "${CREATE_CLUSTER,,}" == "true" ]]; then
# Fail fast the deployment if object Id of the service principal is empty
if [[ -z "$AAD_OBJECT_ID" ]]; then
echo "The object Id of the service principal you just created is not successfully retrieved, please retry another deployment using its client id ${AAD_CLIENT_ID}." >&2
exit 1
fi

# Wait 30s for service principal available after creation
# See https://github.com/WASdev/azure.liberty.aro/issues/59 & https://github.com/WASdev/azure.liberty.aro/issues/79
sleep 30
# Wait 30s for service principal available after creation
# See https://github.com/WASdev/azure.liberty.aro/issues/59 & https://github.com/WASdev/azure.liberty.aro/issues/79
sleep 30
fi

0 comments on commit 963b04a

Please sign in to comment.