Skip to content
Draft
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
35 changes: 17 additions & 18 deletions aksarc_jumpstart/deployaksarc.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ param (
[string] $workingDir
)

# Initialize execution status tracking via shared helpers
. "$PSScriptRoot/status-reporting.ps1"
Initialize-ExecutionStatus -ScriptName 'deployaksarc.ps1'

if ([string]::IsNullOrEmpty($workingDir)) {
$workingDir = "E:\AKSArc"
}
Expand Down Expand Up @@ -64,23 +68,18 @@ $scriptToExecute = [ordered] @{
foreach ($script in $scriptToExecute.GetEnumerator()) {
$scriptUrl = $script.Key
$scriptName = $script.Value

$deploymentName = "executescript-$($vmName)-$($scriptName.Split(" ")[0].Replace('.ps1',''))"
$commandToExecute = "powershell.exe -ExecutionPolicy Unrestricted -File $scriptName"
Write-Host "Executing $commandToExecute from $scriptUrl on VM $vmName ..."
try {
az deployment group create --name $deploymentName --resource-group $GroupName --template-file ./configuration/executescript-template.json --parameters location=$Location vmName=$vmName scriptFileUri=$scriptUrl commandToExecute=$commandToExecute # --debug
if ($LASTEXITCODE -ne 0) {
Write-Host "Azure CLI command failed with exit code $LASTEXITCODE"
throw "Failed to execute script $scriptName on VM $vmName. Exit code: $LASTEXITCODE"
}
}
catch {
Write-Error "An error occurred during AKS Arc cluster deployment: $_"
Write-Error "Exception details: $($_.Exception.Message)"
Write-Error "Stack trace: $($_.ScriptStackTrace)"
throw
}
$scriptBaseName = $scriptName.Split(" ")[0]
Invoke-VmScriptDeployment `
-StepName "ExecuteScript_$scriptBaseName" `
-ResourceGroup $GroupName `
-Location $Location `
-VmName $vmName `
-ScriptFileUri $scriptUrl `
-InnerScript $scriptName
}

Write-Host "Setup is ready for AKS Arc deployment"
Write-Host "Setup is ready for AKS Arc deployment"

# Final execution status - Success
$script:ExecutionStatus.Status = "Success"
Write-ExecutionStatus
57 changes: 23 additions & 34 deletions aksarc_jumpstart/deployaksarc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ VM_NAME="jumpstartVM"
SUBNET_NAME="jumpstartSubnet"
WORKING_DIR="E:\\AKSArc"

# Source shared status reporting helpers (also handles ARM extension failure
# detection via post-deployment instance view inspection).
source "$(dirname "$0")/status-reporting.sh"
init_execution_status "deployaksarc.sh"

# Function to print usage
usage() {
echo "Usage: $0 [OPTIONS]"
Expand Down Expand Up @@ -168,11 +173,8 @@ log " Subscription ID: $SUBSCRIPTION_ID"

# Set the subscription context
log "Setting Azure subscription context..."
az account set --subscription "$SUBSCRIPTION_ID"
if [[ $? -ne 0 ]]; then
echo "Error: Failed to set subscription context"
exit 1
fi
az account set --subscription "$SUBSCRIPTION_ID" \
|| handle_error "SetSubscription" "Failed to set subscription context to '$SUBSCRIPTION_ID'" $?

# Get git repository information
log "Getting git repository information..."
Expand All @@ -185,44 +187,27 @@ log "Script location: $SCRIPT_LOCATION"
# Check for required template file
EXEC_TEMPLATE="./configuration/executescript-template.json"
if [[ ! -f "$EXEC_TEMPLATE" ]]; then
echo "Error: Execute script template not found: $EXEC_TEMPLATE"
echo "Please ensure all required ARM templates are present in the configuration directory"
exit 1
handle_error "PreflightChecks" "Execute script template not found: $EXEC_TEMPLATE -- ensure all required ARM templates are present in the configuration directory"
fi

# Execute deployment scripts on VM in sequence
log "Executing AKS Arc deployment scripts on VM..."

# Define script execution order and details
# Wrapper that combines script_name + script_params into the InnerScript form
# expected by invoke_vm_script_deployment.
execute_script() {
local script_name="$1"
local script_params="$2"
local script_url="${SCRIPT_LOCATION}/${script_name}"
local deployment_name="executescript-${VM_NAME}-${script_name%.*}"
local command_to_execute="powershell.exe -ExecutionPolicy Unrestricted -File ${script_name} ${script_params}"

log "Executing ${script_name%.*} from $script_url on VM $VM_NAME..."

az deployment group create \
--name "$deployment_name" \
--resource-group "$GROUP_NAME" \
--template-file "$EXEC_TEMPLATE" \
--parameters \
location="$LOCATION" \
vmName="$VM_NAME" \
scriptFileUri="$script_url" \
commandToExecute="$command_to_execute"

if [[ $? -ne 0 ]]; then
echo "Error: Failed to execute script ${script_name%.*}"
echo "This may be due to:"
echo " - MOC not being properly installed"
echo " - Network connectivity issues"
echo " - Azure resource quota limitations"
echo " - Previous deployment steps not completed"
exit 1
fi

local inner_script="${script_name} ${script_params}"
invoke_vm_script_deployment \
"ExecuteScript_${script_name%.*}" \
"$GROUP_NAME" \
"$LOCATION" \
"$VM_NAME" \
"$script_url" \
"$inner_script" \
"$EXEC_TEMPLATE"
log "Successfully completed: ${script_name%.*}"
}

Expand Down Expand Up @@ -262,3 +247,7 @@ log ""
log "4. Connect to the cluster using kubectl"
log ""
log "Setup is ready for AKS Arc workload deployment!"

# Final execution status - Success
EXECUTION_STATUS="Success"
print_execution_status
60 changes: 38 additions & 22 deletions aksarc_jumpstart/jumpstart.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,55 @@ param (
$subscriptionId
)

. "$PSScriptRoot/status-reporting.ps1"
Initialize-ExecutionStatus -ScriptName 'jumpstart.ps1'

# Create Resource Group
az group create --name $GroupName --location $Location
az group create --name $GroupName --location $Location
if ($LASTEXITCODE -ne 0) {
Write-Host "Azure CLI command failed with exit code $LASTEXITCODE"
exit $LASTEXITCODE
Invoke-StepFailure -StepName "CreateResourceGroup" -ExitCode $LASTEXITCODE `
-ErrorText "Failed to create resource group '$GroupName' in location '$Location'. Azure CLI command failed with exit code $LASTEXITCODE"
}
Add-CompletedStep -StepName "CreateResourceGroup"

# Create Vnet and VM
az deployment group create --resource-group $GroupName --template-file ./configuration/vnet-template.json --parameters vnetName=$vnetName location=$Location subnetName=$subnetName
if ($LASTEXITCODE -ne 0) {
Write-Host "Azure CLI command failed with exit code $LASTEXITCODE"
exit $LASTEXITCODE
Invoke-StepFailure -StepName "CreateVirtualNetwork" -ExitCode $LASTEXITCODE `
-ErrorText "Failed to create virtual network '$vnetName' and subnet '$subnetName'. Azure CLI command failed with exit code $LASTEXITCODE"
}
Add-CompletedStep -StepName "CreateVirtualNetwork"

az deployment group create --resource-group $GroupName --template-file ./configuration/vm-template.json --parameters adminUsername=$userName adminPassword=$password vmName=$vmName location=$Location vnetName=$vnetName vmSize="Standard_E16s_v4" subnetName=$subnetName
if ($LASTEXITCODE -ne 0) {
Write-Host "Azure CLI command failed with exit code $LASTEXITCODE"
exit $LASTEXITCODE
Invoke-StepFailure -StepName "CreateVirtualMachine" -ExitCode $LASTEXITCODE `
-ErrorText "Failed to create virtual machine '$vmName'. Azure CLI command failed with exit code $LASTEXITCODE"
}
Add-CompletedStep -StepName "CreateVirtualMachine"

# Assign Managed Identity and Contributor Role to VM
az vm identity assign --resource-group $GroupName --name $vmName
if ($LASTEXITCODE -ne 0) {
Write-Host "Azure CLI command failed with exit code $LASTEXITCODE"
exit $LASTEXITCODE
Invoke-StepFailure -StepName "AssignManagedIdentity" -ExitCode $LASTEXITCODE `
-ErrorText "Failed to assign managed identity to VM '$vmName'. Azure CLI command failed with exit code $LASTEXITCODE"
}
Add-CompletedStep -StepName "AssignManagedIdentity"
$principalId = az vm show --resource-group $GroupName --name $vmName --query identity.principalId -o tsv
az role assignment create --assignee $principalId --role Contributor --scope /subscriptions/$subscriptionId
if ($LASTEXITCODE -ne 0) {
Invoke-StepFailure -StepName "AssignContributorRole" -ExitCode $LASTEXITCODE `
-ErrorText "Failed to assign Contributor role to VM identity. Azure CLI command failed with exit code $LASTEXITCODE"
}
Add-CompletedStep -StepName "AssignContributorRole"

#az deployment group create --resource-group $GroupName --template-file a4s-template.json --parameters location=$Location vmName=$vmName arcResourceGroup=$GroupName subscriptionId=$subscriptionId tenantId=$tenantId
# Enable Nested Virtualization
az vm update --resource-group $GroupName --name $vmName --set additionalCapabilities.enableNestedVirtualization=true
if ($LASTEXITCODE -ne 0) {
Invoke-StepFailure -StepName "EnableNestedVirtualization" -ExitCode $LASTEXITCODE `
-ErrorText "Failed to enable nested virtualization on VM '$vmName'. Azure CLI command failed with exit code $LASTEXITCODE"
}
Add-CompletedStep -StepName "EnableNestedVirtualization"

$gitSource = (git config --get remote.origin.url).Replace("github.com", "raw.githubusercontent.com").Replace("aksArc.git", "aksArc")
$branch = (git branch --show-current)
Expand All @@ -74,18 +91,17 @@ $scriptToExecute = [ordered] @{
foreach ($script in $scriptToExecute.GetEnumerator()) {
$scriptUrl = $script.Key
$scriptName = $script.Value
$deploymentName = "executescript-$($vmName)-$($scriptName.Replace('.ps1',''))"
$commandToExecute = "powershell.exe -ExecutionPolicy Unrestricted -File $scriptName"
Write-Host "Executing $scriptName from $scriptUrl on VM $vmName ..."
try {
az deployment group create --name $deploymentName --resource-group $GroupName --template-file ./configuration/executescript-template.json --parameters location=$Location vmName=$vmName scriptFileUri=$scriptUrl commandToExecute=$commandToExecute
}
catch {
Write-Error "An error occurred during AKS Arc cluster deployment: $_"
Write-Error "Exception details: $($_.Exception.Message)"
Write-Error "Stack trace: $($_.ScriptStackTrace)"
throw
}
Invoke-VmScriptDeployment `
-StepName "ExecuteScript_$scriptName" `
-ResourceGroup $GroupName `
-Location $Location `
-VmName $vmName `
-ScriptFileUri $scriptUrl `
-InnerScript $scriptName
}

Write-Host "Login to the VM using Bastion or RDP. Wait for MOC install to finish. Then continue with aksarc deployment by running the script deployaksarc.ps1."
Write-Host "Login to the VM using Bastion or RDP. Wait for MOC install to finish. Then continue with aksarc deployment by running the script deployaksarc.ps1."

# Final execution status - Success
$script:ExecutionStatus.Status = "Success"
Write-ExecutionStatus
Loading