Skip to content

Commit

Permalink
peer vnets before the cluster kubeconfig is available
Browse files Browse the repository at this point in the history
  • Loading branch information
nawazkh committed Feb 5, 2025
1 parent 2e73a3f commit f097398
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -399,37 +399,34 @@ def deploy_worker_templates(template, substitutions):
flavor_cmd = "RANDOM=$(bash -c 'echo $RANDOM'); "


# for corp tenants, fetch the apiserver ilb ip from the parsed yaml
if settings.get("subscription-type", "") == "msft":
apiserver_lb_private_ip = os.getenv("AZURE_INTERNAL_LB_PRIVATE_IP", "")
if apiserver_lb_private_ip != "":
flavor_cmd += "export AZURE_INTERNAL_LB_PRIVATE_IP=\"" + apiserver_lb_private_ip + "\"; "
else:
azurecluster_doc = None

for d in parsed_yamls:
# Safely handle empty/null documents
if d not None and d.get("kind") == "AzureCluster":
# handle empty/null documents
if d != None and d.get("kind") == "AzureCluster":
azurecluster_doc = d
break

if azurecluster_doc == None:
fail("No AzureCluster kind found in YAML")
else:
print("Found an AzureCluster doc")
# For example, extract a field:
private_ip = azurecluster_doc["spec"]["networkSpec"]["apiServerLB"]["frontendIPs"][1]["privateIP"]
print("Private IP is:", private_ip)
# print("Private IP is:", private_ip)
flavor_cmd += "export AZURE_INTERNAL_LB_PRIVATE_IP=\"" + private_ip + "\"; "

# TODO: maintain a matrix for flavors and their respective internal LB IPs
# apiserver_lb_private_ip = os.getenv("AZURE_INTERNAL_LB_PRIVATE_IP", "")
# if "windows-apiserver-ilb" in flavor and apiserver_lb_private_ip == "":
# flavor_cmd += "export AZURE_INTERNAL_LB_PRIVATE_IP=\"40.0.11.100\"; "
# elif "apiserver-ilb" in flavor and apiserver_lb_private_ip == "":
# flavor_cmd += "export AZURE_INTERNAL_LB_PRIVATE_IP=\"30.0.11.100\"; "

flavor_cmd += "export CLUSTER_NAME=" + flavor.replace("windows", "win") + "-$RANDOM; echo " + yaml + "> ./.tiltbuild/" + flavor + "; cat ./.tiltbuild/" + flavor + " | " + envsubst_cmd + " | " + kubectl_cmd + " apply -f -; "
flavor_cmd += "echo \"Cluster ${CLUSTER_NAME} created, don't forget to delete\"; "

# if using AKS as mgmt cluster, peer vnets even before kubeconfig of the deployed cluster is available
if ("aks" in settings.get("kustomize_substitutions", {}).get("MGMT_CLUSTER_NAME", "")) and settings.get("subscription-type", "") == "msft":
flavor_cmd += peer_vnets()

# wait for kubeconfig to be available
flavor_cmd += "echo \"Waiting for kubeconfig to be available\"; "
flavor_cmd += "until " + kubectl_cmd + " get secret ${CLUSTER_NAME}-kubeconfig > /dev/null 2>&1; do sleep 5; done; "
Expand All @@ -446,8 +443,6 @@ def deploy_worker_templates(template, substitutions):
flavor_cmd += "until " + kubectl_cmd + " --kubeconfig ./${CLUSTER_NAME}.kubeconfig get configmap kubeadm-config --namespace=kube-system > /dev/null 2>&1; do sleep 5; done; "
flavor_cmd += kubectl_cmd + " --kubeconfig ./${CLUSTER_NAME}.kubeconfig create namespace calico-system --dry-run=client -o yaml | " + kubectl_cmd + " --kubeconfig ./${CLUSTER_NAME}.kubeconfig apply -f -; " + kubectl_cmd + " --kubeconfig ./${CLUSTER_NAME}.kubeconfig get configmap kubeadm-config --namespace=kube-system -o yaml | sed 's/namespace: kube-system/namespace: calico-system/' | " + kubectl_cmd + " --kubeconfig ./${CLUSTER_NAME}.kubeconfig apply -f -; "

if "aks" in settings.get("kustomize_substitutions", {}).get("MGMT_CLUSTER_NAME", ""):
flavor_cmd += peer_vnets()

flavor_cmd += get_addons(flavor_name)

Expand Down Expand Up @@ -516,13 +511,13 @@ def peer_vnets():
# wait for AKS VNet to be in the state created
peering_cmd = '''
echo \"--------Peering VNETs--------\";
az network vnet wait --resource-group ${AKS_RESOURCE_GROUP} --name ${AKS_MGMT_VNET_NAME} --created --timeout 180;
az network vnet wait --resource-group ${AKS_RESOURCE_GROUP} --name ${AKS_MGMT_VNET_NAME} --created --timeout 600;
export MGMT_VNET_ID=$(az network vnet show --resource-group ${AKS_RESOURCE_GROUP} --name ${AKS_MGMT_VNET_NAME} --query id --output tsv);
echo \" 1/8 ${AKS_MGMT_VNET_NAME} found \"; '''

# wait for workload VNet to be created
peering_cmd += '''
az network vnet wait --resource-group ${CLUSTER_NAME} --name ${CLUSTER_NAME}-vnet --created --timeout 180;
az network vnet wait --resource-group ${CLUSTER_NAME} --name ${CLUSTER_NAME}-vnet --created --timeout 600;
export WORKLOAD_VNET_ID=$(az network vnet show --resource-group ${CLUSTER_NAME} --name ${CLUSTER_NAME}-vnet --query id --output tsv);
echo \" 2/8 ${CLUSTER_NAME}-vnet found \"; '''

Expand Down

0 comments on commit f097398

Please sign in to comment.