Skip to content
Open
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
98 changes: 59 additions & 39 deletions tools/scripts/AksEdgeQuickStart/AksEdgeQuickStartForAio.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ param(
[String] $ClusterName,
[String] $CustomLocationOid,
[Switch] $UseK8s=$false,
[string] $AksEdgeInstallPath,
[string] $AksEdgeVhdxPath,
[string] $Tag
)
#Requires -RunAsAdministrator
Expand Down Expand Up @@ -42,7 +44,7 @@ function Wait-ApiServerReady

if ($retries -eq 0)
{
exit -1
exit -1
}
}

Expand All @@ -61,7 +63,7 @@ param(
Invoke-AksEdgeNodeCommand -command "sudo cat /etc/kubernetes/manifests/kube-apiserver.yaml | tee /home/aksedge-user/kube-apiserver.yaml | tee /home/aksedge-user/kube-apiserver.yaml.working > /dev/null"
Invoke-AksEdgeNodeCommand -command "sudo sed -i 's|service-account-issuer.*|service-account-issuer=$serviceAccountIssuer|' /home/aksedge-user/kube-apiserver.yaml"
Invoke-AksEdgeNodeCommand -command "sudo cp /home/aksedge-user/kube-apiserver.yaml /etc/kubernetes/manifests/kube-apiserver.yaml"
& kubectl delete pod -n kube-system -l component=kube-apiserver
& kubectl delete pod -n kube-system -l component=kube-apiserver
}
else
{
Expand Down Expand Up @@ -105,18 +107,18 @@ param(
if ((-Not $enableWorkloadIdentity) -Or ($connectedCluster.arcAgentProfile.agentState -eq "Succeeded"))
{
Write-Host "Cluster reached connected status"
break
break
}
}

Write-Host "Arc connection status is $($connectedCluster.ConnectivityStatus). Waiting for status to be connected..."
Start-Sleep -Seconds 10
}
}

if ($retries -eq 0)
{
exit -1
}
exit -1
}
}

function New-ConnectedCluster
Expand Down Expand Up @@ -155,15 +157,15 @@ param(
{
if (-Not [string]::IsNullOrEmpty($proxyArgs.Http))
{
$k8sConnectArgs += @("--proxy-http", $proxyArgs.Http)
$k8sConnectArgs += @("--proxy-http", $proxyArgs.Http)
}
if (-Not [string]::IsNullOrEmpty($proxyArgs.Https))
{
$k8sConnectArgs += @("--proxy-https", $proxyArgs.Https)
$k8sConnectArgs += @("--proxy-https", $proxyArgs.Https)
}
if (-Not [string]::IsNullOrEmpty($proxyArgs.No))
{
$k8sConnectArgs += @("--proxy-skip-range", $proxyArgs.No)
$k8sConnectArgs += @("--proxy-skip-range", $proxyArgs.No)
}
}

Expand All @@ -174,13 +176,13 @@ param(

if (-Not [string]::IsNullOrEmpty($arcArgs.GatewayResourceId))
{
$k8sConnectArgs += @("--gateway-resource-id", $arcArgs.GatewayResourceId)
$k8sConnectArgs += @("--gateway-resource-id", $arcArgs.GatewayResourceId)
}

Write-Host "Connect cmd args - $k8sConnectArgs"
$errOut = $($retVal = & {az connectedk8s connect $k8sConnectArgs}) 2>&1
if ($LASTEXITCODE -ne 0)
{
if ($LASTEXITCODE -ne 0)
{
throw "Arc Connection failed with error : $errOut"
}

Expand Down Expand Up @@ -212,6 +214,7 @@ if (! [Environment]::Is64BitProcess) {
Write-Host "Error: Run this in 64bit Powershell session" -ForegroundColor Red
exit -1
}

#Validate inputs
if ($arcLocations -inotcontains $Location) {
Write-Host "Error: Location $Location is not supported for Azure Arc" -ForegroundColor Red
Expand All @@ -220,24 +223,37 @@ if ($arcLocations -inotcontains $Location) {
}

# Validate az cli version.
$azVersion = (az version)[1].Split(":")[1].Split('"')[1]
$azMinRequiredVersion = "2.64.0"
if ($azVersion -lt $azMinRequiredVersion){
Write-Host "Installed Azure CLI version $azVersion is older than $azMinRequiredVersion. Please upgrade Azure CLI and retry." -ForegroundColor Red
exit -1
try {
$azVersion = (az version)[1].Split(":")[1].Split('"')[1]
$azMinRequiredVersion = "2.64.0"
if ($azVersion -lt $azMinRequiredVersion){
Write-Host "Installed Azure CLI version $azVersion is older than $azMinRequiredVersion. Please upgrade Azure CLI and retry." -ForegroundColor Red
exit -1
}
} catch {
Write-Host "Error: Azure CLI is not installed. Please install Azure CLI and retry." -ForegroundColor Red
exit -1
}


# Ensure logged into Azure
$azureLogin = az account show
if ( $null -eq $azureLogin){
Write-Host "Please login to azure via `az login` and retry." -ForegroundColor Red
exit -1
}

# Ensure Powershell Language Mode is "FullLanguage"
if ($ExecutionContext.SessionState.LanguageMode -ne "FullLanguage") {
Write-Host "Error: Powershell ExecutionContext.SessionState.LanguageMode is set to '$($ExecutionContext.SessionState.LanguageMode)'." -ForegroundColor Red
Write-Host "Powershell ExecutionContext.SessionState.LanguageMode must be set to 'FullLanguage'." -ForegroundColor Red
exit -1
}

# Ensure `connectedk8s` az cli extension is installed and up to date.
$errOut = $($retVal = & {az extension add --upgrade --name connectedk8s -y}) 2>&1
if ($LASTEXITCODE -ne 0)
{
if ($LASTEXITCODE -ne 0)
{
throw "Error upgrading extension connecktedk8s : $errOut"
}

Expand Down Expand Up @@ -275,7 +291,11 @@ $aideuserConfig = @"
"Password":""
}
},
"AksEdgeConfigFile": "aksedge-config.json"
"AksEdgeConfigFile": "aksedge-config.json",
"InstallOptions": {
"InstallPath": "$AksEdgeInstallPath",
"VhdxPath": "$AksEdgeVhdxPath"
}
}
"@
$aksedgeConfig = @"
Expand All @@ -289,10 +309,10 @@ $aksedgeConfig = @"
"Network": {
"NetworkPlugin": "$networkplugin",
"InternetDisabled": false,
"Proxy": {
"Http": null,
"Https": null,
"No": null
"Proxy": {
"Http": null,
"Https": null,
"No": null
}
},
"User": {
Expand Down Expand Up @@ -380,8 +400,8 @@ if ($retval) {
Write-Host "Step 3: Connect the cluster to Azure" -ForegroundColor Cyan
# Set the azure subscription
$errOut = $($retVal = & {az account set -s $SubscriptionId}) 2>&1
if ($LASTEXITCODE -ne 0)
{
if ($LASTEXITCODE -ne 0)
{
throw "Error setting Subscription ($SubscriptionId): $errOut"
}

Expand All @@ -390,8 +410,8 @@ $errOut = $($rgExists = & {az group show --resource-group $ResourceGroupName}) 2
if ($null -eq $rgExists) {
Write-Host "Creating resource group: $ResourceGroupName" -ForegroundColor Cyan
$errOut = $($retVal = & {az group create --location $Location --resource-group $ResourceGroupName --subscription $SubscriptionId}) 2>&1
if ($LASTEXITCODE -ne 0)
{
if ($LASTEXITCODE -ne 0)
{
throw "Error creating ResourceGroup ($ResourceGroupName): $errOut"
}
}
Expand All @@ -407,21 +427,21 @@ $resourceProviders =
foreach($rp in $resourceProviders)
{
$errOut = $($obj = & {az provider show -n $rp | ConvertFrom-Json}) 2>&1
if ($LASTEXITCODE -ne 0)
{
if ($LASTEXITCODE -ne 0)
{
throw "Error querying provider $rp : $errOut"
}

if ($obj.registrationState -eq "Registered")
{
continue
continue
}
$errOut = $($retVal = & {az provider register -n $rp}) 2>&1
if ($LASTEXITCODE -ne 0)
{

$errOut = $($retVal = & {az provider register -n $rp}) 2>&1
if ($LASTEXITCODE -ne 0)
{
throw "Error registering provider $rp : $errOut"
}
}
}

# Arc-enable the Kubernetes cluster
Expand All @@ -438,12 +458,12 @@ if ([string]::IsNullOrEmpty($objectId))
$errOut = $($objectId = & {az ad sp show --id $customLocationsAppId --query id -o tsv}) 2>&1
if ($null -eq $objectId)
{
throw "Error querying ObjectId for CustomLocationsAppId : $errOut"
throw "Error querying ObjectId for CustomLocationsAppId : $errOut"
}
}
$errOut = $($retVal = & {az connectedk8s enable-features -n $ClusterName -g $ResourceGroupName --custom-locations-oid $objectId --features cluster-connect custom-locations}) 2>&1
if ($LASTEXITCODE -ne 0)
{
if ($LASTEXITCODE -ne 0)
{
throw "Error enabling feature CustomLocations : $errOut"
}

Expand Down