Skip to content

Commit 17a7399

Browse files
authored
[Tilt] Drop SUBSCRIPTION_TYPE, do not peer vnets for all flavors and update vnet peering logic (#5587)
* remove setting SUBSCRIPTION_TYPE - update resource deletion commands - update docs * update docs
1 parent c3f0631 commit 17a7399

File tree

2 files changed

+76
-22
lines changed

2 files changed

+76
-22
lines changed

Tiltfile

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ if "aks_as_mgmt_settings" in settings and os_arch != "amd64":
9797
YELLOW = "\033[1;33m"
9898
RESET = "\033[0m"
9999
print("\n" + YELLOW + "ARCHITECTURE OVERRIDE: Using AKS as management cluster requires CAPZ to be built for amd64 architecture." + RESET)
100-
print(YELLOW + "Ignoring local GOARCH output and forcing CAPZ's os_arch to amd64" + RESET + "\n")
100+
print(YELLOW + "Ignoring local GOARCH=" + os_arch + " and building CAPZ images for os_arch=amd64" + RESET + "\n")
101101
os_arch = "amd64"
102102

103103
# deploy CAPI
@@ -365,7 +365,7 @@ def flavors():
365365

366366
delete_all_workload_clusters = kubectl_cmd + " delete clusters --all --wait=false;"
367367

368-
if "aks_as_mgmt_settings" in settings and os.getenv("SUBSCRIPTION_TYPE", "") == "corporate":
368+
if "aks_as_mgmt_settings" in settings:
369369
delete_all_workload_clusters += clear_aks_vnet_peerings()
370370

371371
local_resource(
@@ -445,7 +445,7 @@ def deploy_worker_templates(template, substitutions):
445445
# Flavor command is built from here
446446
flavor_cmd = "RANDOM=$(bash -c 'echo $RANDOM'); "
447447

448-
if "aks_as_mgmt_settings" in settings and os.getenv("SUBSCRIPTION_TYPE", "") == "corporate" and "aks" not in flavor_name:
448+
if "aks_as_mgmt_settings" in settings and needs_vnet_peering(flavor_name):
449449
apiserver_lb_private_ip = os.getenv("AZURE_INTERNAL_LB_PRIVATE_IP", "")
450450
if "windows-apiserver-ilb" in flavor and apiserver_lb_private_ip == "":
451451
flavor_cmd += "export AZURE_INTERNAL_LB_PRIVATE_IP=\"40.0.11.100\"; "
@@ -454,7 +454,7 @@ def deploy_worker_templates(template, substitutions):
454454

455455
flavor_cmd += "export CLUSTER_NAME=" + flavor.replace("windows", "win") + "-$RANDOM; echo " + yaml + "> ./.tiltbuild/" + flavor + "; cat ./.tiltbuild/" + flavor + " | " + envsubst_cmd + " | " + kubectl_cmd + " apply -f -; "
456456

457-
if "aks_as_mgmt_settings" in settings and os.getenv("SUBSCRIPTION_TYPE", "") == "corporate" and "aks" not in flavor_name:
457+
if "aks_as_mgmt_settings" in settings and needs_vnet_peering(flavor_name):
458458
flavor_cmd += peer_vnets()
459459

460460
# wait for kubeconfig to be available
@@ -478,7 +478,7 @@ def deploy_worker_templates(template, substitutions):
478478
""" + 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 -;
479479
"""
480480

481-
if "aks_as_mgmt_settings" in settings and os.getenv("SUBSCRIPTION_TYPE", "") == "corporate" and "aks" not in flavor_name:
481+
if "aks_as_mgmt_settings" in settings and needs_vnet_peering(flavor_name):
482482
flavor_cmd += create_private_dns_zone()
483483

484484
flavor_cmd += get_addons(flavor_name)
@@ -627,13 +627,32 @@ def check_nodes_ready(flavor_name):
627627

628628
def clear_aks_vnet_peerings():
629629
delete_peering_cmd = '''
630-
echo "--------Clearing AKS MGMT VNETs Peerings--------";
631-
az network vnet wait --resource-group ${AKS_RESOURCE_GROUP} --name ${AKS_MGMT_VNET_NAME} --created --timeout 180;
632-
echo "VNet ${AKS_MGMT_VNET_NAME} found ";
633630
634-
PEERING_NAMES=$(az network vnet peering list --resource-group ${AKS_RESOURCE_GROUP} --vnet-name ${AKS_MGMT_VNET_NAME} --query "[].name" --output tsv);
635-
for PEERING_NAME in ${PEERING_NAMES}; do echo "Deleting peering: ${PEERING_NAME}"; az network vnet peering delete --name ${PEERING_NAME} --resource-group ${AKS_RESOURCE_GROUP} --vnet-name ${AKS_MGMT_VNET_NAME}; done;
636-
echo "All VNETs Peerings deleted in ${AKS_MGMT_VNET_NAME}";
631+
# Bail out early if the VNet itself never shows up.
632+
if ! az network vnet wait \
633+
--resource-group "${AKS_RESOURCE_GROUP}" \
634+
--name "${AKS_MGMT_VNET_NAME}" \
635+
--created --timeout 180; then
636+
echo "VNet ${AKS_MGMT_VNET_NAME} not found in resource group ${AKS_RESOURCE_GROUP} after 180 seconds - bailing out"
637+
exit 0
638+
fi
639+
640+
az network vnet peering list \
641+
--resource-group "$AKS_RESOURCE_GROUP" \
642+
--vnet-name "$AKS_MGMT_VNET_NAME" \
643+
--query '[].name' -o tsv |
644+
while IFS= read -r PEERING; do
645+
[ -z "$PEERING" ] && continue
646+
647+
echo "Deleting peering: $PEERING"
648+
az network vnet peering delete \
649+
--name "$PEERING" \
650+
--resource-group "$AKS_RESOURCE_GROUP" \
651+
--vnet-name "$AKS_MGMT_VNET_NAME" \
652+
|| echo "Peering $PEERING already gone – skipping."
653+
done
654+
655+
echo "Done"
637656
'''
638657

639658
return delete_peering_cmd
@@ -739,6 +758,32 @@ def allow_tcp_udp_ports():
739758
allow_parallel = True,
740759
)
741760

761+
def needs_vnet_peering(flavor_name):
762+
"""
763+
Check if the flavor requires VNet peering configuration.
764+
765+
Args:
766+
flavor_name (str): The name of the flavor to check
767+
768+
Returns:
769+
bool: True if the flavor needs VNet peering, False otherwise
770+
771+
Flavors requiring VNet peering are:
772+
- apiserver-ilb
773+
- windows-apiserver-ilb
774+
- aks
775+
"""
776+
flavors_needing_vnet_peering = [
777+
"apiserver-ilb",
778+
"windows-apiserver-ilb",
779+
]
780+
781+
for f in flavors_needing_vnet_peering:
782+
if f in flavor_name:
783+
return True
784+
785+
return False
786+
742787
##############################
743788
# Actual work happens here
744789
##############################
@@ -766,7 +811,7 @@ create_crs()
766811

767812
flavors()
768813

769-
if "aks_as_mgmt_settings" in settings and os.getenv("SUBSCRIPTION_TYPE", "") == "corporate":
814+
if "aks_as_mgmt_settings" in settings:
770815
allow_tcp_udp_ports()
771816

772817
print("\n\n=== Active Tilt Configuration Settings ===")

docs/book/src/developers/tilt-with-aks-as-mgmt-ilb.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# Tilt with AKS as Management Cluster with Internal Load Balancer
22

33
## Introduction
4+
45
This guide is explaining how to set up and use Azure Kubernetes Service (AKS) as a management cluster for Cluster API Provider Azure (CAPZ) development using Tilt and an internal load balancer (ILB).
56

67
While the default Tilt setup recommends using a KIND cluster as the management cluster for faster development and experimentation, this guide demonstrates using AKS as an alternative management cluster. We also cover additional steps for working with stricter network policies - particularly useful for organizations that need to maintain all cluster communications within their Azure Virtual Network (VNet) infrastructure with enhanced access controls.
78

89
### Who is this for?
10+
911
- Developers who want to use AKS as the management cluster for CAPZ development.
1012
- Developers working in environments with strict network security requirements.
1113
- Teams that need to keep all Kubernetes API traffic within Azure VNet
@@ -31,8 +33,10 @@ While the default Tilt setup recommends using a KIND cluster as the management c
3133
- If `tilt-settings.yaml` file exists in the root of your repo, clear out any values in `kustomize_settings` unless you want to use them instead of the values that will be set by running `make aks-create`.
3234

3335
### Managed Identity & Registry Setup
36+
3437
1. Have a managed identity created from Azure Portal.
3538
2. Add the following lines to your shell config such as `~/.bashrc` or `~/.zshrc`
39+
3640
```shell
3741
export USER_IDENTITY="<user-assigned-managed-identity-name>"
3842
export AZURE_CLIENT_ID_USER_ASSIGNED_IDENTITY="<user-assigned-managed-identity-client-id>"
@@ -42,19 +46,24 @@ While the default Tilt setup recommends using a KIND cluster as the management c
4246
export AZURE_LOCATION="<azure-location-having-quota-for-B2s-and-D4s_v3-SKU>"
4347
export REGISTRY=<your-container-registry>
4448
```
49+
4550
3. Be sure to reload with `source ~/.bashrc` or `source ~/.zshrc` and then verify the correct env vars values return with `echo $AZURE_CLIENT_ID` and `echo $REGISTRY`.
4651

4752
## Steps to Use Tilt with AKS as the Management Cluster
4853

49-
1. In tilt-settings.yaml, set subscription_type to "corporate" and remove any other env values unless you want to override env variables created by `make aks-create`. Example:
50-
```
51-
.
52-
.
53-
.
54-
kustomize_substitutions:
55-
SUBSCRIPTION_TYPE: "corporate"
56-
.
54+
1. Ensure that the tilt-settings.yaml in root of the repository looks like below
55+
56+
```yaml
57+
kustomize_substitutions: {}
58+
allowed_contexts:
59+
- "kind-capz"
60+
container_args:
61+
capz-controller-manager:
62+
- "--v=4"
5763
```
64+
65+
- Add env variables in `kustomize_substitutions` if you want the added env variables to take precedence over the env values exported by running `make aks-create`.
66+
- Port over an variables set in `tilt-settings.json` to `tilt-settings.yaml`'s `kustomize_substitution:{}` and delete `tilt-settings.json` if present in your local.
5867
2. `make clean`
5968
- This make target does not need to be run every time. Run it to remove bin and kubeconfigs.
6069
3. `make generate`
@@ -96,7 +105,7 @@ Running an e2e test locally in a restricted environment calls for some workaroun
96105
2. Assign that managed identity a contributor role to your subscription
97106
3. Set `AZURE_CLIENT_ID_USER_ASSIGNED_IDENTITY`, `AZURE_OBJECT_ID_USER_ASSIGNED_IDENTITY`, and `AZURE_USER_ASSIGNED_IDENTITY_RESOURCE_ID` to the user-assigned managed identity.
98107

99-
#### Update prow template with apiserver ILB networking solution
108+
### Update prow template with apiserver ILB networking solution
100109

101110
There are three sections of a prow template that need an update.
102111

@@ -180,7 +189,7 @@ A sample kustomize command for updating a prow template via its kustomization.ya
180189
powershell -Command "Add-Content -Path 'C:\\Windows\\System32\\drivers\\etc\\hosts' -Value '${AZURE_INTERNAL_LB_PRIVATE_IP} ${CLUSTER_NAME}-${APISERVER_LB_DNS_SUFFIX}.${AZURE_LOCATION}.cloudapp.azure.com'"
181190
```
182191

183-
#### Peer Vnets of the management cluster and the workload cluster
192+
#### Peer VNets of the management cluster and the workload cluster
184193

185194
Peering VNets, creating a private DNS zone with the FQDN of the workload cluster, and updating NSGs of the management and workload clusters can be achieved by running `scripts/peer-vnets.sh`.
186195

0 commit comments

Comments
 (0)