istio.io/istio@v0.0.0-20240520182934-d79c90f27776/samples/multicluster/gen-eastwest-gateway.sh (about)

     1  #!/bin/bash
     2  #
     3  # Copyright Istio Authors
     4  #
     5  #   Licensed under the Apache License, Version 2.0 (the "License");
     6  #   you may not use this file except in compliance with the License.
     7  #   You may obtain a copy of the License at
     8  #
     9  #       http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  #   Unless required by applicable law or agreed to in writing, software
    12  #   distributed under the License is distributed on an "AS IS" BASIS,
    13  #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  #   See the License for the specific language governing permissions and
    15  #   limitations under the License.
    16  
    17  set -euo pipefail
    18  
    19  SINGLE_CLUSTER=0
    20  REVISION=""
    21  while (( "$#" )); do
    22    case "$1" in
    23      --single-cluster)
    24        SINGLE_CLUSTER=1
    25        shift
    26      ;;
    27      --cluster)
    28        # No longer does anything, but keep it around to avoid breaking users
    29        shift 2
    30      ;;
    31      --network)
    32        NETWORK=$2
    33        shift 2
    34      ;;
    35      --mesh)
    36        # No longer does anything, but keep it around to avoid breaking users
    37        shift 2
    38      ;;
    39      --revision)
    40        REVISION=$2
    41        shift 2
    42      ;;
    43      -*)
    44        echo "Error: Unsupported flag $1" >&2
    45        exit 1
    46        ;;
    47    esac
    48  done
    49  
    50  
    51  # single-cluster installations may need this gateway to allow VMs to get discovery
    52  # for non-single cluster, we add additional topology information
    53  SINGLE_CLUSTER="${SINGLE_CLUSTER:-0}"
    54  if [[ "${SINGLE_CLUSTER}" -eq 0 ]]; then
    55    if [[ -z "${NETWORK:-}" ]]; then
    56      echo "Must specify either --single-cluster or --network."
    57      exit 1
    58    fi
    59  fi
    60  
    61  # base
    62  IOP=$(cat <<EOF
    63  apiVersion: install.istio.io/v1alpha1
    64  kind: IstioOperator
    65  metadata:
    66    name: eastwest
    67  spec:
    68    revision: "${REVISION}"
    69    profile: empty
    70    components:
    71      ingressGateways:
    72        - name: istio-eastwestgateway
    73          label:
    74            istio: eastwestgateway
    75            app: istio-eastwestgateway
    76  EOF
    77  )
    78  
    79  # mark this as a multi-network gateway
    80  if [[ "${SINGLE_CLUSTER}" -eq 0 ]]; then
    81    IOP=$(cat <<EOF
    82  $IOP
    83            topology.istio.io/network: $NETWORK
    84  EOF
    85  )
    86  fi
    87  
    88  # env
    89  IOP=$(cat <<EOF
    90  $IOP
    91          enabled: true
    92          k8s:
    93  EOF
    94  )
    95  if [[ "${SINGLE_CLUSTER}" -eq 0 ]]; then
    96    IOP=$(cat <<EOF
    97  $IOP
    98            env:
    99              # traffic through this gateway should be routed inside the network
   100              - name: ISTIO_META_REQUESTED_NETWORK_VIEW
   101                value: ${NETWORK}
   102  EOF
   103  )
   104  fi
   105  
   106  # Ports
   107  IOP=$(cat <<EOF
   108  $IOP
   109            service:
   110              ports:
   111                - name: status-port
   112                  port: 15021
   113                  targetPort: 15021
   114                - name: tls
   115                  port: 15443
   116                  targetPort: 15443
   117                - name: tls-istiod
   118                  port: 15012
   119                  targetPort: 15012
   120                - name: tls-webhook
   121                  port: 15017
   122                  targetPort: 15017
   123  EOF
   124  )
   125  
   126  # Gateway injection template
   127  IOP=$(cat <<EOF
   128  $IOP
   129    values:
   130      gateways:
   131        istio-ingressgateway:
   132          injectionTemplate: gateway
   133  EOF
   134  )
   135  
   136  # additional multicluster/multinetwork meta
   137  if [[ "${SINGLE_CLUSTER}" -eq 0 ]]; then
   138    IOP=$(cat <<EOF
   139  $IOP
   140      global:
   141        network: ${NETWORK}
   142  EOF
   143  )
   144  fi
   145  
   146  echo "$IOP"