Skip to content

Commit

Permalink
Merge pull request #2593 from janegilring/arcbox_3.0
Browse files Browse the repository at this point in the history
ArcBox 3.0 - Updated workbooks and improved monitoring of the deployment status of clusters in DataOps
  • Loading branch information
janegilring authored Jul 5, 2024
2 parents a9f1c8e + abaf3ed commit 6e09ca2
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 26 deletions.
6 changes: 4 additions & 2 deletions azure_jumpstart_arcbox/artifacts/Bootstrap.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ Write-Host "Fetching Artifacts for All Flavors"
Invoke-WebRequest "https://raw.githubusercontent.com/Azure/arc_jumpstart_docs/main/img/wallpaper/arcbox_wallpaper_dark.png" -OutFile $Env:ArcBoxDir\wallpaper.png
Invoke-WebRequest ($templateBaseUrl + "artifacts/MonitorWorkbookLogonScript.ps1") -OutFile $Env:ArcBoxDir\MonitorWorkbookLogonScript.ps1
Invoke-WebRequest ($templateBaseUrl + "artifacts/mgmtMonitorWorkbook.parameters.json") -OutFile $Env:ArcBoxDir\mgmtMonitorWorkbook.parameters.json
Invoke-WebRequest ($templateBaseUrl + "artifacts/monitoring/arc-inventory-workbook.json") -OutFile "$Env:ArcBoxDir\arc-inventory-workbook.json"
Invoke-WebRequest ($templateBaseUrl + "artifacts/monitoring/arc-osperformance-workbook.json") -OutFile "$Env:ArcBoxDir\arc-osperformance-workbook.json"
Invoke-WebRequest ($templateBaseUrl + "artifacts/DeploymentStatus.ps1") -OutFile $Env:ArcBoxDir\DeploymentStatus.ps1
Invoke-WebRequest ($templateBaseUrl + "artifacts/LogInstructions.txt") -OutFile $Env:ArcBoxLogsDir\LogInstructions.txt
Invoke-WebRequest ($templateBaseUrl + "artifacts/dsc/common.dsc.yml") -OutFile $Env:ArcBoxDscDir\common.dsc.yml
Expand Down Expand Up @@ -360,9 +362,9 @@ if ($flavor -eq "DataOps") {

# Joining ClientVM to AD DS domain
if ($null -eq $addsDomainName){
$addsDomainName = "jumpstart.local"
$addsDomainName = "jumpstart.local"
}

$netbiosname = $addsDomainName.Split(".")[0]
$computername = $env:COMPUTERNAME

Expand Down
6 changes: 2 additions & 4 deletions azure_jumpstart_arcbox/artifacts/DataOpsLogonScript.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if (-not (Get-SecretVault -Name $KeyVault.VaultName -ErrorAction Ignore)) {
# Retrieve Azure Key Vault secrets and store as runtime environment variables
$AZDATA_PASSWORD = Get-Secret -Name 'AZDATAPASSWORD' -AsPlainText

# Register Azure providers.
# Register Azure providers.
# ---- MOVE THESE INTO PRE-REQUISITES DOCUMENT AND REMOVE---
#Write-Header "Registering Providers"
#az provider register --namespace Microsoft.Kubernetes --wait
Expand Down Expand Up @@ -334,9 +334,7 @@ Stop-Transcript
# - Deploying data services on k3s cluster
################################################

Start-Process pwsh.exe -ArgumentList "-NoExit", "-Command", "[System.Console]::Title = 'k3s Cluster'; for (0 -lt 1) { kubectl get pods -n arc --kubeconfig ""C:\Users\$Env:USERNAME\.kube\config-k3s"" ; Start-Sleep -Seconds 5; Clear-Host }"
Start-Process pwsh.exe -ArgumentList "-NoExit", "-Command", "[System.Console]::Title = 'AKS Cluster'; for (0 -lt 1) { kubectl get pods -n arc --kubeconfig ""C:\Users\$Env:USERNAME\.kube\config-aks"" ; Start-Sleep -Seconds 5; Clear-Host }"
Start-Process pwsh.exe -ArgumentList "-NoExit", "-Command", "[System.Console]::Title = 'AKS-DR Cluster'; for (0 -lt 1) { kubectl get pods -n arc --kubeconfig ""C:\Users\$Env:USERNAME\.kube\config-aksdr"" ; Start-Sleep -Seconds 5; Clear-Host }"
wt --% --maximized new-tab pwsh.exe -NoExit -Command Show-K8sPodStatus -kubeconfig "C:\Users\$Env:USERNAME\.kube\config-k3s" -clusterName 'k3s Cluster'; split-pane -p "PowerShell" pwsh.exe -NoExit -Command Show-K8sPodStatus -kubeconfig "C:\Users\$Env:USERNAME\.kube\config-aks" -clusterName 'AKS Cluster'; split-pane -H pwsh.exe -NoExit -Command Show-K8sPodStatus -kubeconfig "C:\Users\$Env:USERNAME\.kube\config-aksdr" -clusterName 'AKS-DR Cluster'

Write-Header "Deploying Azure Arc Data Controllers on Kubernetes cluster"
$clusters | Foreach-Object -ThrottleLimit 5 -Parallel {
Expand Down
51 changes: 33 additions & 18 deletions azure_jumpstart_arcbox/artifacts/MonitorWorkbookLogonScript.ps1
Original file line number Diff line number Diff line change
@@ -1,35 +1,50 @@
$ArcBoxDir = "C:\ArcBox"
$ArcBoxDir = 'C:\ArcBox'
$ArcBoxLogsDir = "$ArcBoxDir\Logs"

Start-Transcript -Path $ArcBoxLogsDir\MonitorWorkbookLogonScript.log

# Required for CLI commands
Write-Header "Az CLI Login"
Write-Header 'Az CLI Login'
az login --identity
az account set -s $env:subscriptionId

Write-Host "[$(Get-Date -Format t)] INFO: Configuring Azure Monitor Workbook ARM template for $($env:flavor)"

# Configure mgmtMonitorWorkbook.json template with subscription ID and resource group values
Write-Host "Configuring Azure Monitor Workbook ARM template."
Write-Host "`n"
$monitorWorkbook = "$ArcBoxDir\mgmtMonitorWorkbook.json"
(Get-Content -Path $monitorWorkbook) -replace '<subscriptionId>',$Env:subscriptionId | Set-Content -Path $monitorWorkbook
(Get-Content -Path $monitorWorkbook) -replace '<resourceGroup>',$Env:resourceGroup | Set-Content -Path $monitorWorkbook
(Get-Content -Path $monitorWorkbook) -replace '<workspaceName>',$Env:workspaceName | Set-Content -Path $monitorWorkbook

# Configure mgmtMonitorWorkbook.parameters.json template with workspace resource id
$monitorWorkbookParameters = "$ArcBoxDir\mgmtMonitorWorkbook.parameters.json"
$workspaceResourceId = $(az resource show --resource-group $Env:resourceGroup --name $Env:workspaceName --resource-type "Microsoft.OperationalInsights/workspaces" --query id -o tsv)
(Get-Content -Path $monitorWorkbookParameters) -replace 'workbookResourceId-stage',$workspaceResourceId | Set-Content -Path $monitorWorkbookParameters
if ($env:flavor -eq 'ITPro') {

Write-Host "Deploying Azure Monitor Workbook ARM template."
Write-Host "`n"
az deployment group create --resource-group $Env:resourceGroup --template-file "$ArcBoxDir\mgmtMonitorWorkbook.json" --parameters "$ArcBoxDir\mgmtMonitorWorkbook.parameters.json"
Write-Host "`n"
Deploy-Workbook -MonitoringDir C:\ArcBox -workbookFileName arc-inventory-workbook.json
Deploy-Workbook -MonitoringDir C:\ArcBox -workbookFileName arc-osperformance-workbook.json


} else {


Write-Host "`n"

# Configure mgmtMonitorWorkbook.json template with subscription ID and resource group values

$monitorWorkbook = "$ArcBoxDir\mgmtMonitorWorkbook.json"
(Get-Content -Path $monitorWorkbook) -replace '<subscriptionId>', $Env:subscriptionId | Set-Content -Path $monitorWorkbook
(Get-Content -Path $monitorWorkbook) -replace '<resourceGroup>', $Env:resourceGroup | Set-Content -Path $monitorWorkbook
(Get-Content -Path $monitorWorkbook) -replace '<workspaceName>', $Env:workspaceName | Set-Content -Path $monitorWorkbook

# Configure mgmtMonitorWorkbook.parameters.json template with workspace resource id
$monitorWorkbookParameters = "$ArcBoxDir\mgmtMonitorWorkbook.parameters.json"
$workspaceResourceId = $(az resource show --resource-group $Env:resourceGroup --name $Env:workspaceName --resource-type 'Microsoft.OperationalInsights/workspaces' --query id -o tsv)
(Get-Content -Path $monitorWorkbookParameters) -replace 'workbookResourceId-stage', $workspaceResourceId | Set-Content -Path $monitorWorkbookParameters

Write-Host 'Deploying Azure Monitor Workbook ARM template.'
Write-Host "`n"
az deployment group create --resource-group $Env:resourceGroup --template-file "$ArcBoxDir\mgmtMonitorWorkbook.json" --parameters "$ArcBoxDir\mgmtMonitorWorkbook.parameters.json"
Write-Host "`n"

}

# Removing the LogonScript Scheduled Task so it won't run on next reboot
if ($null -ne (Get-ScheduledTask -TaskName "MonitorWorkbookLogonScript" -ErrorAction SilentlyContinue)) {
Unregister-ScheduledTask -TaskName "MonitorWorkbookLogonScript" -Confirm:$false
if ($null -ne (Get-ScheduledTask -TaskName 'MonitorWorkbookLogonScript' -ErrorAction SilentlyContinue)) {
Unregister-ScheduledTask -TaskName 'MonitorWorkbookLogonScript' -Confirm:$false
}

Start-Sleep -Seconds 5

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'Azure.Arc.Jumpstart.Common.psm1'

# Version number of this module.
ModuleVersion = '0.0.4'
ModuleVersion = '0.0.6'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -69,7 +69,7 @@ Description = 'Common functions for Azure Arc Jumpstart'
# NestedModules = @()

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = 'Set-JSDesktopBackground','Convert-JSImageToBitMap'
FunctionsToExport = 'Set-JSDesktopBackground','Convert-JSImageToBitMap','Show-K8sPodStatus','Deploy-Workbook'

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = ''
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function Deploy-Workbook {
param(
[string]$MonitoringDir,
[string]$workbookFileName
)

Write-Host "[$(Get-Date -Format t)] INFO: Deploying Azure Workbook $workbookFileName."
Write-Host "`n"
$workbookTemplateFilePath = "$MonitoringDir\$workbookFileName"
# Read the content of the workbook template-file
$content = Get-Content -Path $workbookTemplateFilePath -Raw
# Replace placeholders with actual values
$updatedContent = $content -replace 'rg-placeholder', $env:resourceGroup
$updatedContent = $updatedContent -replace '/subscriptions/00000000-0000-0000-0000-000000000000', "/subscriptions/$($env:subscriptionId)"
$updatedContent = $updatedContent -replace "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/$env:resourceGroup/providers/Microsoft.OperationalInsights/workspaces/xxxx", "/subscriptions/$($env:subscriptionId)/resourceGroups/$($env:resourceGroup)/providers/Microsoft.OperationalInsights/workspaces/$($env:workspaceName)"

# Write the updated content back to the file
Set-Content -Path $workbookTemplateFilePath -Value $updatedContent

# Deploy the workbook
try {
New-AzResourceGroupDeployment -ResourceGroupName $Env:resourceGroup -TemplateFile $workbookTemplateFilePath -ErrorAction Stop
Write-Host "[$(Get-Date -Format t)] INFO: Deployment of template-file $workbookTemplateFilePath succeeded."
} catch {
Write-Error "[$(Get-Date -Format t)] ERROR: Deployment of template-file $workbookTemplateFilePath failed. Error details: $PSItem.Exception.Message"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function Show-K8sPodStatus {
param (
[string]$kubeconfig,
[string]$clusterName
)

while ($true) {
Write-Host "Status for $clusterName at $(Get-Date)" -ForegroundColor Green
kubectl get pods -n arc --kubeconfig $kubeconfig
Start-Sleep -Seconds 5
Clear-Host
}
}

0 comments on commit 6e09ca2

Please sign in to comment.