|
| 1 | +#!/usr/bin/env bash |
| 2 | +# shellcheck disable=SC1090,SC2034,SC2154 |
| 3 | + |
| 4 | +# Copyright Istio Authors |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | + |
| 18 | +# Initialize KUBECONFIG_FILES and KUBE_CONTEXTS |
| 19 | +_set_kube_vars |
| 20 | + |
| 21 | +source content/en/docs/ambient/install/multicluster/verify/snips.sh |
| 22 | + |
| 23 | +# set_single_network_vars initializes all variables for a single network config. |
| 24 | +function set_single_network_vars |
| 25 | +{ |
| 26 | + export KUBECONFIG_CLUSTER1="${KUBECONFIG_FILES[0]}" |
| 27 | + export KUBECONFIG_CLUSTER2="${KUBECONFIG_FILES[1]}" |
| 28 | + export CTX_CLUSTER1="${KUBE_CONTEXTS[0]}" |
| 29 | + export CTX_CLUSTER2="${KUBE_CONTEXTS[1]}" |
| 30 | +} |
| 31 | + |
| 32 | +# set_multi_network_vars initializes all variables for a multi-network config. |
| 33 | +function set_multi_network_vars |
| 34 | +{ |
| 35 | + export KUBECONFIG_CLUSTER1="${KUBECONFIG_FILES[0]}" |
| 36 | + export KUBECONFIG_CLUSTER2="${KUBECONFIG_FILES[2]}" |
| 37 | + export CTX_CLUSTER1="${KUBE_CONTEXTS[0]}" |
| 38 | + export CTX_CLUSTER2="${KUBE_CONTEXTS[2]}" |
| 39 | +} |
| 40 | + |
| 41 | +# configure_trust creates a hierarchy of |
| 42 | +function configure_trust |
| 43 | +{ |
| 44 | + # Keeps the certs under a separate directory. |
| 45 | + mkdir -p certs |
| 46 | + pushd certs || exit |
| 47 | + |
| 48 | + # Create the root cert. |
| 49 | + make -f ../tools/certs/Makefile.selfsigned.mk root-ca |
| 50 | + |
| 51 | + # Create and deploy intermediate certs for cluster1 and cluster2. |
| 52 | + make -f ../tools/certs/Makefile.selfsigned.mk cluster1-cacerts |
| 53 | + make -f ../tools/certs/Makefile.selfsigned.mk cluster2-cacerts |
| 54 | + |
| 55 | + # Create the istio-system namespace in each cluster so that we can create the secrets. |
| 56 | + kubectl --context="$CTX_CLUSTER1" create namespace istio-system |
| 57 | + kubectl --context="$CTX_CLUSTER2" create namespace istio-system |
| 58 | + |
| 59 | + # Deploy secret to each cluster |
| 60 | + kubectl --context="$CTX_CLUSTER1" create secret generic cacerts -n istio-system \ |
| 61 | + --from-file=cluster1/ca-cert.pem \ |
| 62 | + --from-file=cluster1/ca-key.pem \ |
| 63 | + --from-file=cluster1/root-cert.pem \ |
| 64 | + --from-file=cluster1/cert-chain.pem |
| 65 | + kubectl --context="$CTX_CLUSTER2" create secret generic cacerts -n istio-system \ |
| 66 | + --from-file=cluster2/ca-cert.pem \ |
| 67 | + --from-file=cluster2/ca-key.pem \ |
| 68 | + --from-file=cluster2/root-cert.pem \ |
| 69 | + --from-file=cluster2/cert-chain.pem |
| 70 | + |
| 71 | + popd || exit # Return to the previous directory. |
| 72 | +} |
| 73 | + |
| 74 | +# cleanup_istioctl removes all resources created by the tests with istioctl. |
| 75 | +function cleanup_istioctl |
| 76 | +{ |
| 77 | + # Remove temp files. |
| 78 | + rm -f cluster1.yaml cluster2.yaml certs |
| 79 | + |
| 80 | + # Cleanup both clusters concurrently |
| 81 | + cleanup_cluster1_istioctl & |
| 82 | + cleanup_cluster2_istioctl & |
| 83 | + wait |
| 84 | + snip_delete_crds |
| 85 | +} |
| 86 | + |
| 87 | +# cleanup_cluster1_istioctl removes the istio-system and sample namespaces on CLUSTER1 with istioctl. |
| 88 | +function cleanup_cluster1_istioctl |
| 89 | +{ |
| 90 | + echo y | istioctl uninstall --revision=default --context="${CTX_CLUSTER1}" |
| 91 | + kubectl delete ns istio-system sample --context="${CTX_CLUSTER1}" --ignore-not-found |
| 92 | +} |
| 93 | + |
| 94 | +# cleanup_cluster2_istioctl removes the istio-system and sample namespaces on CLUSTER2 with istioctl. |
| 95 | +function cleanup_cluster2_istioctl |
| 96 | +{ |
| 97 | + echo y | istioctl uninstall --revision=default --context="${CTX_CLUSTER2}" |
| 98 | + kubectl delete ns istio-system sample --context="${CTX_CLUSTER2}" --ignore-not-found |
| 99 | +} |
| 100 | + |
| 101 | +# verify_load_balancing verifies that traffic is load balanced properly |
| 102 | +# between CLUSTER1 and CLUSTER2. |
| 103 | +function verify_load_balancing |
| 104 | +{ |
| 105 | + # Verify istiod is synced |
| 106 | + echo "Verifying istiod is synced to remote cluster." |
| 107 | + _verify_like snip_verify_multicluster_1 "$snip_verify_multicluster_1_out" |
| 108 | + |
| 109 | + # Deploy the HelloWorld service. |
| 110 | + snip_deploy_the_helloworld_service_1 |
| 111 | + snip_deploy_the_helloworld_service_2 |
| 112 | + snip_deploy_the_helloworld_service_3 |
| 113 | + |
| 114 | + # Deploy HelloWorld v1 and v2 |
| 115 | + snip_deploy_helloworld_v1_1 |
| 116 | + snip_deploy_helloworld_v2_1 |
| 117 | + |
| 118 | + # Deploy curl |
| 119 | + snip_deploy_curl_1 |
| 120 | + |
| 121 | + # Wait for all the deployments. |
| 122 | + _wait_for_deployment sample helloworld-v1 "${CTX_CLUSTER1}" |
| 123 | + _wait_for_deployment sample curl "${CTX_CLUSTER1}" |
| 124 | + _wait_for_deployment sample helloworld-v2 "${CTX_CLUSTER2}" |
| 125 | + _wait_for_deployment sample curl "${CTX_CLUSTER2}" |
| 126 | + |
| 127 | + # Expose the helloworld service in both clusters. |
| 128 | + echo "Exposing helloworld in cluster1" |
| 129 | + kubectl --context="${CTX_CLUSTER1}" label svc helloworld -n sample istio.io/global="true" |
| 130 | + echo "Exposing helloworld in cluster2" |
| 131 | + kubectl --context="${CTX_CLUSTER2}" label svc helloworld -n sample istio.io/global="true" |
| 132 | + |
| 133 | + # Verify everything is deployed as expected. |
| 134 | + VERIFY_TIMEOUT=0 # Don't retry. |
| 135 | + echo "Verifying helloworld v1 deployment" |
| 136 | + _verify_like snip_deploy_helloworld_v1_2 "$snip_deploy_helloworld_v1_2_out" |
| 137 | + echo "Verifying helloworld v2 deployment" |
| 138 | + _verify_like snip_deploy_helloworld_v2_2 "$snip_deploy_helloworld_v2_2_out" |
| 139 | + echo "Verifying curl deployment in ${CTX_CLUSTER1}" |
| 140 | + _verify_like snip_deploy_curl_2 "$snip_deploy_curl_2_out" |
| 141 | + echo "Verifying curl deployment in ${CTX_CLUSTER2}" |
| 142 | + _verify_like snip_deploy_curl_3 "$snip_deploy_curl_3_out" |
| 143 | + unset VERIFY_TIMEOUT # Restore default |
| 144 | + |
| 145 | + local EXPECTED_RESPONSE_FROM_CLUSTER1="Hello version: v1, instance:" |
| 146 | + local EXPECTED_RESPONSE_FROM_CLUSTER2="Hello version: v2, instance:" |
| 147 | + |
| 148 | + # Verify we hit both clusters from CLUSTER1 |
| 149 | + echo "Verifying load balancing from ${CTX_CLUSTER1}" |
| 150 | + _verify_contains snip_verifying_crosscluster_traffic_1 "$EXPECTED_RESPONSE_FROM_CLUSTER1" |
| 151 | + _verify_contains snip_verifying_crosscluster_traffic_1 "$EXPECTED_RESPONSE_FROM_CLUSTER2" |
| 152 | + |
| 153 | + # Verify we hit both clusters from CLUSTER2 |
| 154 | + echo "Verifying load balancing from ${CTX_CLUSTER2}" |
| 155 | + _verify_contains snip_verifying_crosscluster_traffic_3 "$EXPECTED_RESPONSE_FROM_CLUSTER1" |
| 156 | + _verify_contains snip_verifying_crosscluster_traffic_3 "$EXPECTED_RESPONSE_FROM_CLUSTER2" |
| 157 | +} |
| 158 | + |
| 159 | +# For Helm multi-cluster installation steps |
| 160 | + |
| 161 | +function create_istio_system_ns |
| 162 | +{ |
| 163 | + snip_create_istio_system_namespace_cluster_1 |
| 164 | + snip_create_istio_system_namespace_cluster_2 |
| 165 | +} |
| 166 | + |
| 167 | +function setup_helm_repo |
| 168 | +{ |
| 169 | + snip_setup_helm_repo_cluster_1 |
| 170 | + snip_setup_helm_repo_cluster_2 |
| 171 | +} |
| 172 | + |
| 173 | +snip_create_istio_system_namespace_cluster_1() { |
| 174 | +kubectl create namespace istio-system --context "${CTX_CLUSTER1}" |
| 175 | +} |
| 176 | + |
| 177 | +snip_create_istio_system_namespace_cluster_2() { |
| 178 | +kubectl create namespace istio-system --context "${CTX_CLUSTER2}" |
| 179 | +} |
| 180 | + |
| 181 | +snip_setup_helm_repo_cluster_1() { |
| 182 | +helm repo add istio https://istio-release.storage.googleapis.com/charts --kube-context "${CTX_CLUSTER1}" |
| 183 | +helm repo update --kube-context "${CTX_CLUSTER1}" |
| 184 | +} |
| 185 | + |
| 186 | +snip_setup_helm_repo_cluster_2() { |
| 187 | +helm repo add istio https://istio-release.storage.googleapis.com/charts --kube-context "${CTX_CLUSTER2}" |
| 188 | +helm repo update --kube-context "${CTX_CLUSTER2}" |
| 189 | +} |
| 190 | + |
| 191 | +snip_delete_sample_ns_cluster_1() { |
| 192 | +kubectl delete namespace sample --context "${CTX_CLUSTER1}" |
| 193 | +} |
| 194 | + |
| 195 | +snip_delete_sample_ns_cluster_2() { |
| 196 | +kubectl delete namespace sample --context "${CTX_CLUSTER2}" |
| 197 | +} |
0 commit comments