@@ -23,8 +23,8 @@ settings = {
23
23
"capi_version" : "v1.8.5" ,
24
24
"caaph_version" : "v0.2.5" ,
25
25
"cert_manager_version" : "v1.16.1" ,
26
- "kubernetes_version" : "v1.28.3 " ,
27
- "aks_kubernetes_version" : "v1.28.3 " ,
26
+ "kubernetes_version" : "v1.28.15 " ,
27
+ "aks_kubernetes_version" : "v1.28.15 " ,
28
28
"flatcar_version" : "3374.2.1" ,
29
29
"azure_location" : "eastus" ,
30
30
"control_plane_machine_count" : "1" ,
@@ -212,10 +212,10 @@ def capz():
212
212
yaml = str (kustomizesub ("./hack/observability" )) # build an observable kind deployment by default
213
213
214
214
# add extra_args if they are defined
215
- if settings .get ("extra_args " ):
216
- azure_extra_args = settings .get ("extra_args " ).get ("azure " )
215
+ if settings .get ("container_args " ):
216
+ capz_container_args = settings .get ("container_args " ).get ("capz-controller-manager " )
217
217
yaml_dict = decode_yaml_stream (yaml )
218
- append_arg_for_container_in_deployment (yaml_dict , "capz-controller-manager" , "capz-system" , "cluster-api-azure-controller" , azure_extra_args )
218
+ append_arg_for_container_in_deployment (yaml_dict , "capz-controller-manager" , "capz-system" , "cluster-api-azure-controller" , capz_container_args )
219
219
yaml = str (encode_yaml_stream (yaml_dict ))
220
220
yaml = fixup_yaml_empty_arrays (yaml )
221
221
@@ -317,9 +317,14 @@ def flavors():
317
317
for template in template_list :
318
318
deploy_worker_templates (template , substitutions )
319
319
320
+ delete_all_workload_clusters = kubectl_cmd + " delete clusters --all --wait=false"
321
+
322
+ if "aks" in settings .get ("kustomize_substitutions" , {}).get ("MGMT_CLUSTER_NAME" , "" ):
323
+ delete_all_workload_clusters += clear_aks_vnet_peerings ()
324
+
320
325
local_resource (
321
326
name = "delete-all-workload-clusters" ,
322
- cmd = kubectl_cmd + " delete clusters --all --wait=false" ,
327
+ cmd = [ "sh" , "-ec" , delete_all_workload_clusters ] ,
323
328
auto_init = False ,
324
329
trigger_mode = TRIGGER_MODE_MANUAL ,
325
330
labels = ["flavors" ],
@@ -382,17 +387,29 @@ def deploy_worker_templates(template, substitutions):
382
387
383
388
yaml = shlex .quote (yaml )
384
389
flavor_name = os .path .basename (flavor )
385
- flavor_cmd = "RANDOM=$(bash -c 'echo $RANDOM'); export CLUSTER_NAME=" + flavor .replace ("windows" , "win" ) + "-$RANDOM; make generate-flavors; echo " + yaml + "> ./.tiltbuild/" + flavor + "; cat ./.tiltbuild/" + flavor + " | " + envsubst_cmd + " | " + kubectl_cmd + " apply -f -; echo \" Cluster \' $CLUSTER_NAME\' created, don't forget to delete\" "
390
+ flavor_cmd = "RANDOM=$(bash -c 'echo $RANDOM')"
391
+ flavor_cmd += "; export CLUSTER_NAME=" + flavor .replace ("windows" , "win" ) + "-$RANDOM; echo " + yaml + "> ./.tiltbuild/" + flavor + "; cat ./.tiltbuild/" + flavor + " | " + envsubst_cmd + " | " + kubectl_cmd + " apply -f -"
392
+ flavor_cmd += "; echo \" Cluster \' $CLUSTER_NAME\' created, don't forget to delete\" "
386
393
387
394
# wait for kubeconfig to be available
388
- flavor_cmd += "; until " + kubectl_cmd + " get secret ${CLUSTER_NAME}-kubeconfig > /dev/null 2>&1; do sleep 5; done; " + kubectl_cmd + " get secret ${CLUSTER_NAME}-kubeconfig -o jsonpath={.data.value} | base64 --decode > ./${CLUSTER_NAME}.kubeconfig; chmod 600 ./${CLUSTER_NAME}.kubeconfig; until " + kubectl_cmd + " --kubeconfig=./${CLUSTER_NAME}.kubeconfig get nodes > /dev/null 2>&1; do sleep 5; done"
395
+ flavor_cmd += "; echo \" Waiting for kubeconfig to be available\" "
396
+ flavor_cmd += "; until " + kubectl_cmd + " get secret ${CLUSTER_NAME}-kubeconfig > /dev/null 2>&1; do sleep 5; done"
397
+ flavor_cmd += "; " + kubectl_cmd + " get secret ${CLUSTER_NAME}-kubeconfig -o jsonpath={.data.value} | base64 --decode > ./${CLUSTER_NAME}.kubeconfig"
398
+ flavor_cmd += "; chmod 600 ./${CLUSTER_NAME}.kubeconfig"
399
+ flavor_cmd += "; echo \" Kubeconfig for $CLUSTER_NAME created and saved in the local\" "
400
+ flavor_cmd += "; echo \" Waiting for $CLUSTER_NAME API Server to be accessible\" "
401
+ flavor_cmd += "; until " + kubectl_cmd + " --kubeconfig=./${CLUSTER_NAME}.kubeconfig get nodes > /dev/null 2>&1; do sleep 5; done"
402
+ flavor_cmd += "; echo \" API Server of $CLUSTER_NAME is accessible\" "
389
403
390
404
# copy the kubeadm configmap to the calico-system namespace.
391
405
# This is a workaround needed for the calico-node-windows daemonset to be able to run in the calico-system namespace.
392
406
if "windows" in flavor_name :
393
407
flavor_cmd += "; until " + kubectl_cmd + " --kubeconfig ./${CLUSTER_NAME}.kubeconfig get configmap kubeadm-config --namespace=kube-system > /dev/null 2>&1; do sleep 5; done"
394
408
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 -"
395
409
410
+ if "aks" in settings .get ("kustomize_substitutions" , {}).get ("MGMT_CLUSTER_NAME" , "" ):
411
+ flavor_cmd += peer_vnets ()
412
+
396
413
flavor_cmd += get_addons (flavor_name )
397
414
398
415
local_resource (
@@ -454,6 +471,63 @@ def waitforsystem():
454
471
local (kubectl_cmd + " wait --for=condition=ready --timeout=300s pod --all -n capi-kubeadm-control-plane-system" )
455
472
local (kubectl_cmd + " wait --for=condition=ready --timeout=300s pod --all -n capi-system" )
456
473
474
+ def peer_vnets ():
475
+ # TODO: check for az cli to be installed in local
476
+ # wait for AKS VNet to be in the state created
477
+ peering_cmd = "; echo \" --------Peering VNETs--------\" "
478
+ peering_cmd += "; az network vnet wait --resource-group ${AKS_RESOURCE_GROUP} --name ${AKS_MGMT_VNET_NAME} --created --timeout 180"
479
+ peering_cmd += "; export MGMT_VNET_ID=$(az network vnet show --resource-group ${AKS_RESOURCE_GROUP} --name ${AKS_MGMT_VNET_NAME} --query id --output tsv)"
480
+ peering_cmd += "; echo \" 1/8 ${AKS_MGMT_VNET_NAME} found \" "
481
+
482
+ # wait for workload VNet to be created
483
+ peering_cmd += "; az network vnet wait --resource-group ${CLUSTER_NAME} --name ${CLUSTER_NAME}-vnet --created --timeout 180"
484
+ peering_cmd += "; export WORKLOAD_VNET_ID=$(az network vnet show --resource-group ${CLUSTER_NAME} --name ${CLUSTER_NAME}-vnet --query id --output tsv)"
485
+ peering_cmd += "; echo \" 2/8 ${CLUSTER_NAME}-vnet found \" "
486
+
487
+ # peer mgmt vnet
488
+ peering_cmd += "; az network vnet peering create --name mgmt-to-${CLUSTER_NAME} --resource-group ${AKS_RESOURCE_GROUP} --vnet-name ${AKS_MGMT_VNET_NAME} --remote-vnet \" ${WORKLOAD_VNET_ID}\" --allow-vnet-access true --allow-forwarded-traffic true --only-show-errors --output none"
489
+ peering_cmd += "; az network vnet peering wait --name mgmt-to-${CLUSTER_NAME} --resource-group ${AKS_RESOURCE_GROUP} --vnet-name ${AKS_MGMT_VNET_NAME} --created --timeout 300 --only-show-errors --output none"
490
+ peering_cmd += "; echo \" 3/8 mgmt-to-${CLUSTER_NAME} peering created in ${AKS_MGMT_VNET_NAME}\" "
491
+
492
+ # peer workload vnet
493
+ peering_cmd += "; az network vnet peering create --name ${CLUSTER_NAME}-to-mgmt --resource-group ${CLUSTER_NAME} --vnet-name ${CLUSTER_NAME}-vnet --remote-vnet \" ${MGMT_VNET_ID}\" --allow-vnet-access true --allow-forwarded-traffic true --only-show-errors --output none"
494
+ peering_cmd += "; az network vnet peering wait --name ${CLUSTER_NAME}-to-mgmt --resource-group ${CLUSTER_NAME} --vnet-name ${CLUSTER_NAME}-vnet --created --timeout 300 --only-show-errors --output none"
495
+ peering_cmd += "; echo \" 4/8 ${CLUSTER_NAME}-to-mgmt peering created in ${CLUSTER_NAME}-vnet\" "
496
+
497
+ # create private DNS zone
498
+ peering_cmd += "; az network private-dns zone create --resource-group ${CLUSTER_NAME} --name ${AZURE_LOCATION}.cloudapp.azure.com --only-show-errors --output none"
499
+ peering_cmd += "; az network private-dns zone wait --resource-group ${CLUSTER_NAME} --name ${AZURE_LOCATION}.cloudapp.azure.com --created --timeout 300 --only-show-errors --output none"
500
+ peering_cmd += "; echo \" 5/8 ${AZURE_LOCATION}.cloudapp.azure.com private DNS zone created in ${CLUSTER_NAME}\" "
501
+
502
+ # link private DNS Zone to workload vnet
503
+ peering_cmd += "; az network private-dns link vnet create --resource-group ${CLUSTER_NAME} --zone-name ${AZURE_LOCATION}.cloudapp.azure.com --name ${CLUSTER_NAME}-to-mgmt --virtual-network \" ${WORKLOAD_VNET_ID}\" --registration-enabled false --only-show-errors --output none"
504
+ peering_cmd += "; az network private-dns link vnet wait --resource-group ${CLUSTER_NAME} --zone-name ${AZURE_LOCATION}.cloudapp.azure.com --name ${CLUSTER_NAME}-to-mgmt --created --timeout 300 --only-show-errors --output none"
505
+ peering_cmd += "; echo \" 6/8 workload cluster vnet ${CLUSTER_NAME}-vnet linked with private DNS zone\" "
506
+
507
+ # link private DNS Zone to mgmt vnet
508
+ peering_cmd += "; az network private-dns link vnet create --resource-group ${CLUSTER_NAME} --zone-name ${AZURE_LOCATION}.cloudapp.azure.com --name mgmt-to-${CLUSTER_NAME} --virtual-network \" ${MGMT_VNET_ID}\" --registration-enabled false --only-show-errors --output none"
509
+ peering_cmd += "; az network private-dns link vnet wait --resource-group ${CLUSTER_NAME} --zone-name ${AZURE_LOCATION}.cloudapp.azure.com --name mgmt-to-${CLUSTER_NAME} --created --timeout 300 --only-show-errors --output none"
510
+ peering_cmd += "; echo \" 7/8 management cluster vnet ${AKS_MGMT_VNET_NAME} linked with private DNS zone\" "
511
+
512
+ # create private DNS zone record
513
+ # TODO: 10.0.0.100 should be customizable
514
+ peering_cmd += "; az network private-dns record-set a add-record --resource-group ${CLUSTER_NAME} --zone-name ${AZURE_LOCATION}.cloudapp.azure.com --record-set-name ${CLUSTER_NAME}-${APISERVER_LB_DNS_SUFFIX} --ipv4-address 10.0.0.100 --only-show-errors --output none"
515
+ peering_cmd += "; echo \" 8/8 ${CLUSTER_NAME}-${APISERVER_LB_DNS_SUFFIX} private DNS zone record created\n \" "
516
+
517
+ return peering_cmd
518
+
519
+ def clear_aks_vnet_peerings ():
520
+ delete_peering_cmd = "; echo \" --------Clearing AKS MGMT VNETs Peerings--------\" "
521
+ delete_peering_cmd += "; az network vnet wait --resource-group ${AKS_RESOURCE_GROUP} --name ${AKS_MGMT_VNET_NAME} --created --timeout 180"
522
+ delete_peering_cmd += "; echo \" ${AKS_MGMT_VNET_NAME} found \" "
523
+
524
+ # List all peering names and store them in an array
525
+ delete_peering_cmd += "; PEERING_NAMES=$(az network vnet peering list --resource-group ${AKS_RESOURCE_GROUP} --vnet-name ${AKS_MGMT_VNET_NAME} --query \" [].name\" --output tsv)"
526
+ delete_peering_cmd += "; 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"
527
+ delete_peering_cmd += "; echo \" All VNETs Peerings deleted in ${AKS_MGMT_VNET_NAME}\" "
528
+
529
+ return delete_peering_cmd
530
+
457
531
##############################
458
532
# Actual work happens here
459
533
##############################
0 commit comments