Skip to content

Commit

Permalink
refactor: cleaning up the vnet guid resolution and the vnet subnet id…
Browse files Browse the repository at this point in the history
… resolution
  • Loading branch information
Bryce-Soghigian committed Feb 5, 2025
1 parent b3ec519 commit 2bb1f84
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 2 additions & 7 deletions Makefile-az.mk
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ az-all-cniv1: az-login az-create-workload-msi az-mkaks-cniv1 az-cre

az-all-cni-overlay: az-login az-create-workload-msi az-mkaks-overlay az-create-federated-cred az-perm az-perm-acr az-configure-values az-build az-run az-run-sample ## Provision the infra (ACR,AKS); build and deploy Karpenter; deploy sample Provisioner and workload

az-all-custom-vnet: az-login az-create-workload-msi az-mkaks-custom-vnet az-create-federated-cred az-perm-subnet-custom az-perm-acr az-configure-values-custom-vnet az-build az-run az-run-sample ## Provision the infra (ACR,AKS); build and deploy Karpenter; deploy sample Provisioner and workload
az-all-custom-vnet: az-login az-create-workload-msi az-mkaks-custom-vnet az-create-federated-cred az-perm-subnet-custom az-perm-acr az-configure-values az-build az-run az-run-sample ## Provision the infra (ACR,AKS); build and deploy Karpenter; deploy sample Provisioner and workload
az-all-user: az-login az-mkaks-user az-configure-values az-helm-install-snapshot az-run-sample ## Provision the cluster and deploy Karpenter snapshot release
# TODO: az-all-savm case is not currently built to support workload identity, need to re-evaluate
az-all-savm: az-login az-mkaks-savm az-perm-savm az-configure-values az-build az-run az-run-sample ## Provision the infra (ACR,AKS); build and deploy Karpenter; deploy sample Provisioner and workload - StandaloneVirtualMachines
Expand Down Expand Up @@ -116,12 +116,7 @@ az-rmrg: ## Destroy test ACR and AKS cluster by deleting the resource group (use
az group delete --name $(AZURE_RESOURCE_GROUP)

az-configure-values: ## Generate cluster-related values for Karpenter Helm chart
hack/deploy/configure-values.sh $(AZURE_CLUSTER_NAME) $(AZURE_RESOURCE_GROUP) $(KARPENTER_SERVICE_ACCOUNT_NAME) $(AZURE_KARPENTER_USER_ASSIGNED_IDENTITY_NAME)

az-configure-values-custom-vnet: ## Generate cluster-related values for Karpenter Helm chart (take custom subnet ID from first agentpool)
VNET_SUBNET_ID=$$(az aks show --name $(AZURE_CLUSTER_NAME) --resource-group $(AZURE_RESOURCE_GROUP) | jq -r ".agentPoolProfiles[0].vnetSubnetId"); \
VNET_GUID=$$(bash -c 's=$$(az aks show --name $(AZURE_CLUSTER_NAME) --resource-group $(AZURE_RESOURCE_GROUP) | jq -r ".agentPoolProfiles[0].vnetSubnetId"); vnet_id=$${s%/subnets*}; az network vnet show --ids "$$vnet_id" --query "resourceGuid" -o tsv'); \
$(MAKE) az-configure-values VNET_SUBNET_ID=$$VNET_SUBNET_ID VNET_GUID=$$VNET_GUID
hack/deploy/configure-values.sh $(AZURE_CLUSTER_NAME) $(AZURE_RESOURCE_GROUP) $(KARPENTER_SERVICE_ACCOUNT_NAME) $(AZURE_KARPENTER_USER_ASSIGNED_IDENTITY_NAME) $(VNET_GUID)

az-mkvmssflex: ## Create VMSS Flex (optional, only if creating VMs referencing this VMSS)
az vmss create --name $(AZURE_CLUSTER_NAME)-vmss --resource-group $(AZURE_RESOURCE_GROUP_MC) --location $(AZURE_LOCATION) \
Expand Down
9 changes: 8 additions & 1 deletion hack/deploy/configure-values.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ SSH_PUBLIC_KEY="$(cat ~/.ssh/id_rsa.pub) azureuser"
if [[ ! -v VNET_SUBNET_ID ]]; then
# first subnet of first VNet found
VNET_JSON=$(az network vnet list --resource-group "$AZURE_RESOURCE_GROUP_MC" | jq -r ".[0]")
# If the vnet is not in the same resource group as the cluster, we need to get the vnet from the subnet id in the cluster
if [[ -z $VNET_JSON ]]; then
VNET_JSON=$(az network vnet show --ids $(jq -r ".agentPoolProfiles[0].vnetSubnetId" <<< "$AKS_JSON") -o json)
fi
VNET_SUBNET_ID=$(jq -r ".subnets[0].id" <<< "$VNET_JSON")
if [[ -z $VNET_GUID ]]; then
VNET_GUID=$(jq -r ".properties.resourceGuid" <<< "$VNET_JSON")
fi
fi

# The // empty ensures that if the files is 'null' or not prsent jq will output nothing
Expand All @@ -51,7 +58,7 @@ KARPENTER_USER_ASSIGNED_CLIENT_ID=$(az identity show --resource-group "${AZURE_R

export CLUSTER_NAME AZURE_LOCATION AZURE_RESOURCE_GROUP_MC KARPENTER_SERVICE_ACCOUNT_NAME \
CLUSTER_ENDPOINT BOOTSTRAP_TOKEN SSH_PUBLIC_KEY VNET_SUBNET_ID KARPENTER_USER_ASSIGNED_CLIENT_ID NODE_IDENTITIES AZURE_SUBSCRIPTION_ID NETWORK_PLUGIN NETWORK_PLUGIN_MODE NETWORK_POLICY \
LOG_LEVEL
LOG_LEVEL VNET_GUID

# get karpenter-values-template.yaml, if not already present (e.g. outside of repo context)
if [ ! -f karpenter-values-template.yaml ]; then
Expand Down

0 comments on commit 2bb1f84

Please sign in to comment.