This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathdeploy_custom_metrics_adapter.sh
52 lines (46 loc) · 2.12 KB
/
deploy_custom_metrics_adapter.sh
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
source ./InfrastructureDeployment/setup_env.sh
# Application Insights Custom Metrics Adapter
if "$INSTALL_CUSTOM_METRICS_ADAPTER" = "true"
then
# Deploy the adapter.
echo "Creating Application Insights Custom Metrics Adapter."
kubectl apply -f https://raw.githubusercontent.com/Azure/azure-k8s-metrics-adapter/master/deploy/adapter.yaml
if [ $? -ne 0 ]
then
echo "Could not apply the Application Insights Custom Metrics Adapter."
echo "deploy_custom_metrics_adapter.sh failed"
exit $?
fi
# Create a service principal and secret.
sp_password=$(az ad sp create-for-rbac -n $SERVICE_PRINCIPAL_METRIC_ADAPTER_NAME --role "Monitoring Reader" --scopes /subscriptions/$AZURE_SUBSCRIPTION_ID/resourceGroups/$AKS_RESOURCE_GROUP_NAME --query password --output tsv)
if [ $? -ne 0 ]
then
echo "Could not create the service principal and secret for $SERVICE_PRINCIPAL_METRIC_ADAPTER_NAME."
echo "deploy_custom_metrics_adapter.sh failed"
exit $?
fi
# Get the appId, tenantId, and secret of the service principal.
app_id=$(az ad sp list --display-name $SERVICE_PRINCIPAL_METRIC_ADAPTER_NAME --query '[].{appId:appId}' --output tsv)
if [ $? -ne 0 ]
then
echo "Could not get the app id for $SERVICE_PRINCIPAL_METRIC_ADAPTER_NAME."
echo "deploy_custom_metrics_adapter.sh failed"
exit $?
fi
tenant_id=$(az ad sp show --id $app_id --query appOwnerTenantId --output tsv)
if [ $? -ne 0 ]
then
echo "Could not get the tenant id for $SERVICE_PRINCIPAL_METRIC_ADAPTER_NAME."
echo "deploy_custom_metrics_adapter.sh failed"
exit $?
fi
# Use values from service principal created above to create secret.
kubectl create secret generic azure-k8s-metrics-adapter -n custom-metrics --from-literal=azure-tenant-id=$tenant_id --from-literal=azure-client-id=$app_id --from-literal=azure-client-secret=$sp_password
if [ $? -ne 0 ]
then
echo "Could not create the secret required for teh custom metrics adapter."
echo "deploy_custom_metrics_adapter.sh failed"
exit $?
fi
fi