|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Copyright 2024 The Kubernetes Authors. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | + |
| 16 | +set -o errexit # exit immediately if a command exits with a non-zero status. |
| 17 | +set -o nounset # exit when script tries to use undeclared variables. |
| 18 | +set -o pipefail # make the pipeline fail if any command in it fails. |
| 19 | + |
| 20 | +REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. |
| 21 | + |
| 22 | +source_tilt_settings() { |
| 23 | + if [ "$#" -ne 1 ]; then |
| 24 | + echo "Usage: $0 <tilt-settings.yaml>" |
| 25 | + exit 1 |
| 26 | + fi |
| 27 | + |
| 28 | + TILT_SETTINGS_FILE="$1" |
| 29 | + |
| 30 | + # Check that the file exists |
| 31 | + if [ ! -f "$TILT_SETTINGS_FILE" ]; then |
| 32 | + echo "File not found: $TILT_SETTINGS_FILE" |
| 33 | + exit 1 |
| 34 | + fi |
| 35 | + |
| 36 | + echo "Reading variables from $TILT_SETTINGS_FILE under 'kustomize_substition'..." |
| 37 | + |
| 38 | + # Get the list of keys under kustomize_substition |
| 39 | + VAR_KEYS=$(yq e '.kustomize_substition | keys | .[]' "$TILT_SETTINGS_FILE" 2>/dev/null || true) |
| 40 | + |
| 41 | + # If there's no such key or it's empty, VAR_KEYS will be empty |
| 42 | + if [ -z "$VAR_KEYS" ]; then |
| 43 | + echo "No variables found under 'kustomize_substition'." |
| 44 | + else |
| 45 | + for key in $VAR_KEYS; do |
| 46 | + # Read the value of each key |
| 47 | + value=$(yq e ".kustomize_substition[\"$key\"]" "$TILT_SETTINGS_FILE") |
| 48 | + # Export the key/value pair |
| 49 | + export "$key=$value" |
| 50 | + echo "Exported $key=$value" |
| 51 | + done |
| 52 | + fi |
| 53 | + |
| 54 | + echo "All variables exported" |
| 55 | +} |
| 56 | + |
| 57 | + |
| 58 | +peer_vnets() { |
| 59 | + # ------------------------------------------------------------------------------ |
| 60 | + # Peer Vnets |
| 61 | + # ------------------------------------------------------------------------------ |
| 62 | + |
| 63 | + echo "--------Peering VNETs--------" |
| 64 | + az network vnet wait --resource-group ${AKS_RESOURCE_GROUP} --name ${AKS_MGMT_VNET_NAME} --created --timeout 180 |
| 65 | + export MGMT_VNET_ID=$(az network vnet show --resource-group ${AKS_RESOURCE_GROUP} --name ${AKS_MGMT_VNET_NAME} --query id --output tsv) |
| 66 | + echo " 1/8 ${AKS_MGMT_VNET_NAME} found " |
| 67 | + |
| 68 | + # wait for workload VNet to be created |
| 69 | + az network vnet wait --resource-group ${CLUSTER_NAME} --name ${CLUSTER_NAME}-vnet --created --timeout 180 |
| 70 | + export WORKLOAD_VNET_ID=$(az network vnet show --resource-group ${CLUSTER_NAME} --name ${CLUSTER_NAME}-vnet --query id --output tsv) |
| 71 | + echo " 2/8 ${CLUSTER_NAME}-vnet found" |
| 72 | + |
| 73 | + # peer mgmt vnet |
| 74 | + 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 |
| 75 | + 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 |
| 76 | + echo " 3/8 mgmt-to-${CLUSTER_NAME} peering created in ${AKS_MGMT_VNET_NAME}" |
| 77 | + |
| 78 | + # peer workload vnet |
| 79 | + 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 |
| 80 | + 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 |
| 81 | + echo " 4/8 ${CLUSTER_NAME}-to-mgmt peering created in ${CLUSTER_NAME}-vnet" |
| 82 | + |
| 83 | + # create private DNS zone |
| 84 | + az network private-dns zone create --resource-group ${CLUSTER_NAME} --name ${CLUSTER_NAME}-${APISERVER_LB_DNS_SUFFIX}.${AZURE_LOCATION}.cloudapp.azure.com --only-show-errors --output none |
| 85 | + az network private-dns zone wait --resource-group ${CLUSTER_NAME} --name ${CLUSTER_NAME}-${APISERVER_LB_DNS_SUFFIX}.${AZURE_LOCATION}.cloudapp.azure.com --created --timeout 300 --only-show-errors --output none |
| 86 | + echo " 5/8 ${CLUSTER_NAME}-${APISERVER_LB_DNS_SUFFIX}.${AZURE_LOCATION}.cloudapp.azure.com private DNS zone created in ${CLUSTER_NAME}" |
| 87 | + |
| 88 | + # link private DNS Zone to workload vnet |
| 89 | + az network private-dns link vnet create --resource-group ${CLUSTER_NAME} --zone-name ${CLUSTER_NAME}-${APISERVER_LB_DNS_SUFFIX}.${AZURE_LOCATION}.cloudapp.azure.com --name ${CLUSTER_NAME}-to-mgmt --virtual-network \"${WORKLOAD_VNET_ID}\" --registration-enabled false --only-show-errors --output none |
| 90 | + az network private-dns link vnet wait --resource-group ${CLUSTER_NAME} --zone-name ${CLUSTER_NAME}-${APISERVER_LB_DNS_SUFFIX}.${AZURE_LOCATION}.cloudapp.azure.com --name ${CLUSTER_NAME}-to-mgmt --created --timeout 300 --only-show-errors --output none |
| 91 | + echo " 6/8 workload cluster vnet ${CLUSTER_NAME}-vnet linked with private DNS zone" |
| 92 | + |
| 93 | + # link private DNS Zone to mgmt vnet |
| 94 | + az network private-dns link vnet create --resource-group ${CLUSTER_NAME} --zone-name ${CLUSTER_NAME}-${APISERVER_LB_DNS_SUFFIX}.${AZURE_LOCATION}.cloudapp.azure.com --name mgmt-to-${CLUSTER_NAME} --virtual-network \"${MGMT_VNET_ID}\" --registration-enabled false --only-show-errors --output none |
| 95 | + az network private-dns link vnet wait --resource-group ${CLUSTER_NAME} --zone-name ${CLUSTER_NAME}-${APISERVER_LB_DNS_SUFFIX}.${AZURE_LOCATION}.cloudapp.azure.com --name mgmt-to-${CLUSTER_NAME} --created --timeout 300 --only-show-errors --output none |
| 96 | + echo " 7/8 management cluster vnet ${AKS_MGMT_VNET_NAME} linked with private DNS zone" |
| 97 | + |
| 98 | + # create private DNS zone record |
| 99 | + az network private-dns record-set a add-record --resource-group ${CLUSTER_NAME} --zone-name ${CLUSTER_NAME}-${APISERVER_LB_DNS_SUFFIX}.${AZURE_LOCATION}.cloudapp.azure.com --record-set-name \"@\" --ipv4-address ${AZURE_INTERNAL_LB_PRIVATE_IP} --only-show-errors --output none |
| 100 | + echo " 8/8 \"@\" private DNS zone record created to point ${CLUSTER_NAME}-${APISERVER_LB_DNS_SUFFIX}.${AZURE_LOCATION}.cloudapp.azure.com to ${AZURE_INTERNAL_LB_PRIVATE_IP}" |
| 101 | +} |
0 commit comments