Skip to content

Commit

Permalink
rewrite the IPs of the CIDRs
Browse files Browse the repository at this point in the history
  • Loading branch information
nawazkh committed Feb 5, 2025
1 parent 4ea0464 commit 2e73a3f
Show file tree
Hide file tree
Showing 27 changed files with 174 additions and 150 deletions.
36 changes: 30 additions & 6 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,10 @@ def flavors():
os.environ.update({az_key_name: read_file_from_path(default_key_path)})

# Prefer templates/internal if subscription-type is msft
# TODO: improve this subscription type check
template_list = []
if settings.get("subscription-type", "") == "msft":
print("Using Azure subscription type: msft. CAPZ flavors from ./templates/internal will be used.")
print("Using Azure subscription type: corporate. Selecting CAPZ flavors from ./templates/internal .")
template_list = [item for item in listdir("./templates/internal")]
else:
template_list = [item for item in listdir("./templates")]
Expand Down Expand Up @@ -343,6 +344,7 @@ def deploy_worker_templates(template, substitutions):
fail(template + " not found")

yaml = str(read_file(template))
parsed_yamls=decode_yaml_stream(yaml)
flavor = os.path.basename(template).replace("cluster-template-", "").replace(".yaml", "")

# for the base cluster-template, flavor is "default"
Expand Down Expand Up @@ -396,12 +398,34 @@ def deploy_worker_templates(template, substitutions):
flavor_name = os.path.basename(flavor)
flavor_cmd = "RANDOM=$(bash -c 'echo $RANDOM'); "


if settings.get("subscription-type", "") == "msft":
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":
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)
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\"; "
# 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\"; "
Expand Down
12 changes: 6 additions & 6 deletions templates/internal/aad/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,41 @@ patches:
patch: |-
- op: replace
path: /spec/template/spec/preKubeadmCommands/0
value: echo '${AZURE_INTERNAL_LB_PRIVATE_IP:-50.0.0.100} ${CLUSTER_NAME}-${APISERVER_LB_DNS_SUFFIX}.${AZURE_LOCATION}.cloudapp.azure.com' >> /etc/hosts
value: echo '${AZURE_INTERNAL_LB_PRIVATE_IP:-31.0.0.100} ${CLUSTER_NAME}-${APISERVER_LB_DNS_SUFFIX}.${AZURE_LOCATION}.cloudapp.azure.com' >> /etc/hosts
options:
allowResourceNotFound: true
- target:
kind: AzureCluster
patch: |-
- op: replace
path: /spec/networkSpec/apiServerLB/frontendIPs/1/privateIP
value: ${AZURE_INTERNAL_LB_PRIVATE_IP:-50.0.0.100}
value: ${AZURE_INTERNAL_LB_PRIVATE_IP:-31.0.0.100}
- target:
kind: AzureCluster
patch: |-
- op: replace
path: /spec/networkSpec/vnet/cidrBlocks/0
value: 50.0.0.0/8
value: 31.0.0.0/8
- target:
kind: AzureCluster
patch: |-
- op: replace
path: /spec/networkSpec/subnets/0/cidrBlocks/0
value: 50.0.0.0/16
value: 31.0.0.0/16
- target:
kind: AzureCluster
patch: |-
- op: replace
path: /spec/networkSpec/subnets/1/cidrBlocks/0
value: 50.1.0.0/16
value: 31.1.0.0/16
- target:
kind: KubeadmConfigTemplate
name: .*-md-win
patch: |-
- op: replace
path: /spec/template/spec/preKubeadmCommands/0
value:
powershell -Command "Add-Content -Path 'C:\\Windows\\System32\\drivers\\etc\\hosts' -Value '${AZURE_INTERNAL_LB_PRIVATE_IP:-50.0.0.100} ${CLUSTER_NAME}-${APISERVER_LB_DNS_SUFFIX}.${AZURE_LOCATION}.cloudapp.azure.com'"
powershell -Command "Add-Content -Path 'C:\\Windows\\System32\\drivers\\etc\\hosts' -Value '${AZURE_INTERNAL_LB_PRIVATE_IP:-31.0.0.100} ${CLUSTER_NAME}-${APISERVER_LB_DNS_SUFFIX}.${AZURE_LOCATION}.cloudapp.azure.com'"
options:
allowResourceNotFound: true

Expand Down
12 changes: 6 additions & 6 deletions templates/internal/azure-bastion/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,41 @@ patches:
patch: |-
- op: replace
path: /spec/template/spec/preKubeadmCommands/0
value: echo '${AZURE_INTERNAL_LB_PRIVATE_IP:-60.0.0.100} ${CLUSTER_NAME}-${APISERVER_LB_DNS_SUFFIX}.${AZURE_LOCATION}.cloudapp.azure.com' >> /etc/hosts
value: echo '${AZURE_INTERNAL_LB_PRIVATE_IP:-32.0.0.100} ${CLUSTER_NAME}-${APISERVER_LB_DNS_SUFFIX}.${AZURE_LOCATION}.cloudapp.azure.com' >> /etc/hosts
options:
allowResourceNotFound: true
- target:
kind: AzureCluster
patch: |-
- op: replace
path: /spec/networkSpec/apiServerLB/frontendIPs/1/privateIP
value: ${AZURE_INTERNAL_LB_PRIVATE_IP:-60.0.0.100}
value: ${AZURE_INTERNAL_LB_PRIVATE_IP:-32.0.0.100}
- target:
kind: AzureCluster
patch: |-
- op: replace
path: /spec/networkSpec/vnet/cidrBlocks/0
value: 60.0.0.0/8
value: 32.0.0.0/8
- target:
kind: AzureCluster
patch: |-
- op: replace
path: /spec/networkSpec/subnets/0/cidrBlocks/0
value: 60.0.0.0/16
value: 32.0.0.0/16
- target:
kind: AzureCluster
patch: |-
- op: replace
path: /spec/networkSpec/subnets/1/cidrBlocks/0
value: 60.1.0.0/16
value: 32.1.0.0/16
- target:
kind: KubeadmConfigTemplate
name: .*-md-win
patch: |-
- op: replace
path: /spec/template/spec/preKubeadmCommands/0
value:
powershell -Command "Add-Content -Path 'C:\\Windows\\System32\\drivers\\etc\\hosts' -Value '${AZURE_INTERNAL_LB_PRIVATE_IP:-60.0.0.100} ${CLUSTER_NAME}-${APISERVER_LB_DNS_SUFFIX}.${AZURE_LOCATION}.cloudapp.azure.com'"
powershell -Command "Add-Content -Path 'C:\\Windows\\System32\\drivers\\etc\\hosts' -Value '${AZURE_INTERNAL_LB_PRIVATE_IP:-32.0.0.100} ${CLUSTER_NAME}-${APISERVER_LB_DNS_SUFFIX}.${AZURE_LOCATION}.cloudapp.azure.com'"
options:
allowResourceNotFound: true

Expand Down
12 changes: 6 additions & 6 deletions templates/internal/azure-cni-v1/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,41 @@ patches:
patch: |-
- op: replace
path: /spec/template/spec/preKubeadmCommands/0
value: echo '${AZURE_INTERNAL_LB_PRIVATE_IP:-70.0.0.100} ${CLUSTER_NAME}-${APISERVER_LB_DNS_SUFFIX}.${AZURE_LOCATION}.cloudapp.azure.com' >> /etc/hosts
value: echo '${AZURE_INTERNAL_LB_PRIVATE_IP:-33.0.0.100} ${CLUSTER_NAME}-${APISERVER_LB_DNS_SUFFIX}.${AZURE_LOCATION}.cloudapp.azure.com' >> /etc/hosts
options:
allowResourceNotFound: true
- target:
kind: AzureCluster
patch: |-
- op: replace
path: /spec/networkSpec/apiServerLB/frontendIPs/1/privateIP
value: ${AZURE_INTERNAL_LB_PRIVATE_IP:-70.0.0.100}
value: ${AZURE_INTERNAL_LB_PRIVATE_IP:-33.0.0.100}
- target:
kind: AzureCluster
patch: |-
- op: replace
path: /spec/networkSpec/vnet/cidrBlocks/0
value: 70.0.0.0/8
value: 33.0.0.0/8
- target:
kind: AzureCluster
patch: |-
- op: replace
path: /spec/networkSpec/subnets/0/cidrBlocks/0
value: 70.0.0.0/16
value: 33.0.0.0/16
- target:
kind: AzureCluster
patch: |-
- op: replace
path: /spec/networkSpec/subnets/1/cidrBlocks/0
value: 70.1.0.0/16
value: 33.1.0.0/16
- target:
kind: KubeadmConfigTemplate
name: .*-md-win
patch: |-
- op: replace
path: /spec/template/spec/preKubeadmCommands/0
value:
powershell -Command "Add-Content -Path 'C:\\Windows\\System32\\drivers\\etc\\hosts' -Value '${AZURE_INTERNAL_LB_PRIVATE_IP:-70.0.0.100} ${CLUSTER_NAME}-${APISERVER_LB_DNS_SUFFIX}.${AZURE_LOCATION}.cloudapp.azure.com'"
powershell -Command "Add-Content -Path 'C:\\Windows\\System32\\drivers\\etc\\hosts' -Value '${AZURE_INTERNAL_LB_PRIVATE_IP:-33.0.0.100} ${CLUSTER_NAME}-${APISERVER_LB_DNS_SUFFIX}.${AZURE_LOCATION}.cloudapp.azure.com'"
options:
allowResourceNotFound: true

Expand Down
10 changes: 5 additions & 5 deletions templates/internal/cluster-template-aad.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions templates/internal/cluster-template-azure-bastion.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions templates/internal/cluster-template-azure-cni-v1.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions templates/internal/cluster-template-dual-stack.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions templates/internal/cluster-template-edgezone.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions templates/internal/cluster-template-ephemeral.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2e73a3f

Please sign in to comment.