Skip to content

Commit 929f43f

Browse files
committed
update script
1 parent 61eb242 commit 929f43f

File tree

1 file changed

+35
-15
lines changed

1 file changed

+35
-15
lines changed

scripts/troubleshoot/cluster-migration/migrate-to-container-insights-msi.sh

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,43 @@ check_prerequisites() {
4343
local resource_group=$2
4444
local name=$3
4545

46-
# 1. Check if cluster uses managed identity
4746
if [ "$cluster_type" = "aks" ]; then
47+
# 1. Check AKS cluster health first
48+
local provisioning_state=$(az aks show -g "$resource_group" -n "$name" --query "provisioningState" -o tsv)
49+
if [ "$provisioning_state" != "Succeeded" ]; then
50+
echo "Cluster not ready (current state: $provisioning_state)" >&2
51+
return 1
52+
fi
53+
54+
# 2. Check if cluster uses managed identity
4855
local identity_type=$(az aks show -g "$resource_group" -n "$name" --query "identity.type" -o tsv)
4956
if [ "$identity_type" != "SystemAssigned" ] && [ "$identity_type" != "UserAssigned" ]; then
5057
echo "Current identity type: $identity_type (requires SystemAssigned or UserAssigned)" >&2
5158
echo "To migrate to managed identity, visit: https://learn.microsoft.com/en-us/azure/aks/use-managed-identity" >&2
5259
echo "Please migrate to managed identity and then rerun this script" >&2
5360
return 1
5461
fi
62+
63+
# 3. Check if monitoring is already using MSI
64+
local auth_mode=$(az aks show -g "$resource_group" -n "$name" --query "addonProfiles.omsagent.config.useAADAuth" -o tsv)
65+
if [ "$auth_mode" = "true" ]; then
66+
echo "Monitoring already using MSI authentication" >&2
67+
return 1
68+
fi
69+
5570
elif [ "$cluster_type" = "arc" ]; then
71+
# 1. Check Arc extension health first
72+
local extension_state=$(az k8s-extension show --name azuremonitor-containers \
73+
--cluster-name "$name" \
74+
--resource-group "$resource_group" \
75+
--cluster-type connectedClusters \
76+
--query "provisioningState" -o tsv)
77+
if [ "$extension_state" != "Succeeded" ]; then
78+
echo "Container insights extension not ready (current state: $extension_state)" >&2
79+
return 1
80+
fi
81+
82+
# 2. Check if cluster uses managed identity
5683
local identity_type=$(az connectedk8s show -g "$resource_group" -n "$name" --query "identity.type" -o tsv)
5784
if [ "$identity_type" != "SystemAssigned" ] && [ "$identity_type" != "UserAssigned" ]; then
5885
echo "Current identity type: $identity_type (requires SystemAssigned or UserAssigned)" >&2
@@ -64,26 +91,19 @@ check_prerequisites() {
6491
echo "Please migrate to managed identity and then rerun this script" >&2
6592
return 1
6693
fi
67-
fi
6894

69-
# 2. Check if monitoring is already using MSI
70-
if [ "$cluster_type" = "aks" ]; then
71-
local auth_mode=$(az aks show -g "$resource_group" -n "$name" --query "addonProfiles.omsagent.config.useAADAuth" -o tsv)
72-
if [ "$auth_mode" = "true" ]; then
95+
# 3. Check if using MSI authentication
96+
local use_aad_auth=$(az k8s-extension show --name azuremonitor-containers \
97+
--cluster-name "$name" \
98+
--resource-group "$resource_group" \
99+
--cluster-type connectedClusters \
100+
--query "configurationSettings.\"amalogs.useAADAuth\"" -o tsv)
101+
if [ "$use_aad_auth" = "true" ]; then
73102
echo "Monitoring already using MSI authentication" >&2
74103
return 1
75104
fi
76105
fi
77106

78-
# 3. Check cluster health
79-
if [ "$cluster_type" = "aks" ]; then
80-
local provisioning_state=$(az aks show -g "$resource_group" -n "$name" --query "provisioningState" -o tsv)
81-
if [ "$provisioning_state" != "Succeeded" ]; then
82-
echo "Cluster not ready (current state: $provisioning_state)" >&2
83-
return 1
84-
fi
85-
fi
86-
87107
return 0
88108
}
89109

0 commit comments

Comments
 (0)