-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistAROClustersWithoutAnyWorkloads.ps1
More file actions
35 lines (27 loc) · 1.19 KB
/
listAROClustersWithoutAnyWorkloads.ps1
File metadata and controls
35 lines (27 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# TODO:
# This script will not identify any clusters probably as in the system namespace there are always some workloads running.
# Need to find a way to exclude system namespace from the list of workloads.
# Login to Azure
Connect-AzAccount
# Get all ARO clusters
$aroClusters = Get-AzAroCluster
# Initialize an array to store unused ARO clusters
$unusedAroClusters = @()
# Check each ARO cluster for nodes and workloads
foreach ($aroCluster in $aroClusters) {
$resourceGroupName = $aroCluster.ResourceGroupName
$aroClusterName = $aroCluster.Name
# Get the nodes in the ARO cluster
$nodes = Get-AzAroNode -ResourceGroupName $resourceGroupName -ClusterName $aroClusterName
# Get the workloads in the ARO cluster using oc command
$kubeconfig = (Get-AzAroKubeconfig -ResourceGroupName $resourceGroupName -Name $aroClusterName).Value
& oc login --token=$kubeconfig
$workloads = & oc get pods --all-namespaces
if ($nodes.Count -eq 0 -and $workloads.Count -eq 0) {
$unusedAroClusters += $aroCluster
}
}
# Display the unused ARO clusters
$unusedAroClusters | ForEach-Object {
Write-Output "ARO Cluster: $($_.Name) - Resource Group: $($_.ResourceGroupName)"
}