istio.io/istio@v0.0.0-20240520182934-d79c90f27776/prow/integ-suite-kind.sh (about)

     1  #!/bin/bash
     2  
     3  # Copyright 2019 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  
    18  # Usage: ./integ-suite-kind.sh TARGET
    19  # Example: ./integ-suite-kind.sh test.integration.pilot.kube.presubmit
    20  
    21  WD=$(dirname "$0")
    22  WD=$(cd "$WD"; pwd)
    23  ROOT=$(dirname "$WD")
    24  
    25  # Exit immediately for non zero status
    26  set -e
    27  # Check unset variables
    28  set -u
    29  # Print commands
    30  set -x
    31  
    32  # shellcheck source=prow/lib.sh
    33  source "${ROOT}/prow/lib.sh"
    34  setup_and_export_git_sha
    35  
    36  # shellcheck source=common/scripts/kind_provisioner.sh
    37  source "${ROOT}/common/scripts/kind_provisioner.sh"
    38  
    39  TOPOLOGY=SINGLE_CLUSTER
    40  NODE_IMAGE="gcr.io/istio-testing/kind-node:v1.30.0"
    41  KIND_CONFIG=""
    42  CLUSTER_TOPOLOGY_CONFIG_FILE="${ROOT}/prow/config/topology/multicluster.json"
    43  
    44  export FAST_VM_BUILDS=true
    45  export ISTIO_DOCKER_BUILDER="${ISTIO_DOCKER_BUILDER:-crane}"
    46  
    47  PARAMS=()
    48  
    49  while (( "$#" )); do
    50    case "$1" in
    51      # Node images can be found at https://github.com/kubernetes-sigs/kind/releases
    52      # For example, kindest/node:v1.14.0
    53      --node-image)
    54        NODE_IMAGE=$2
    55        shift 2
    56      ;;
    57      # Config for enabling different Kubernetes features in KinD (see prow/config{endpointslice.yaml,trustworthy-jwt.yaml}).
    58      --kind-config)
    59      KIND_CONFIG=$2
    60      shift 2
    61      ;;
    62      --skip-setup)
    63        SKIP_SETUP=true
    64        shift
    65      ;;
    66      --skip-cleanup)
    67        SKIP_CLEANUP=true
    68        shift
    69      ;;
    70      --skip-build)
    71        SKIP_BUILD=true
    72        shift
    73      ;;
    74      --manual)
    75        MANUAL=true
    76        shift
    77      ;;
    78      --topology)
    79        case $2 in
    80          # TODO(landow) get rid of MULTICLUSTER_SINGLE_NETWORK after updating Prow job
    81          SINGLE_CLUSTER | MULTICLUSTER_SINGLE_NETWORK | MULTICLUSTER )
    82            TOPOLOGY=$2
    83            echo "Running with topology ${TOPOLOGY}"
    84            ;;
    85          *)
    86            echo "Error: Unsupported topology ${TOPOLOGY}" >&2
    87            exit 1
    88            ;;
    89        esac
    90        shift 2
    91      ;;
    92      --topology-config)
    93        CLUSTER_TOPOLOGY_CONFIG_FILE="${ROOT}/${2}"
    94        shift 2
    95      ;;
    96      -*)
    97        echo "Error: Unsupported flag $1" >&2
    98        exit 1
    99        ;;
   100      *) # preserve positional arguments
   101        PARAMS+=("$1")
   102        shift
   103        ;;
   104    esac
   105  done
   106  
   107  if [ -f /proc/cpuinfo ]; then
   108    echo "Checking CPU..."
   109    grep 'model' /proc/cpuinfo || true
   110  fi
   111  
   112  # Default IP family of the cluster is IPv4
   113  export IP_FAMILY="${IP_FAMILY:-ipv4}"
   114  
   115  # LoadBalancer in Kind is supported using metallb
   116  export TEST_ENV=kind-metallb
   117  
   118  # See https://kind.sigs.k8s.io/docs/user/quick-start/#loading-an-image-into-your-cluster
   119  export PULL_POLICY=IfNotPresent
   120  
   121  # We run a local-registry in a docker container that KinD nodes pull from
   122  # These values are must match what is in config/trustworthy-jwt.yaml
   123  export KIND_REGISTRY_NAME="kind-registry"
   124  export KIND_REGISTRY_PORT="5000"
   125  export KIND_REGISTRY="localhost:${KIND_REGISTRY_PORT}"
   126  
   127  export HUB=${HUB:-"istio-testing"}
   128  export TAG="${TAG:-"istio-testing"}"
   129  export VARIANT
   130  
   131  # If we're not intending to pull from an actual remote registry, use the local kind registry
   132  if [[ -z "${SKIP_BUILD:-}" ]]; then
   133    HUB="${KIND_REGISTRY}"
   134    export HUB
   135  fi
   136  
   137  # Setup junit report and verbose logging
   138  export T="${T:-"-v -count=1"}"
   139  export CI="true"
   140  
   141  export ARTIFACTS="${ARTIFACTS:-$(mktemp -d)}"
   142  trace "init" make init
   143  
   144  if [[ -z "${SKIP_SETUP:-}" ]]; then
   145    export DEFAULT_CLUSTER_YAML="./prow/config/default.yaml"
   146    export METRICS_SERVER_CONFIG_DIR='./prow/config/metrics'
   147  
   148    if [[ "${TOPOLOGY}" == "SINGLE_CLUSTER" ]]; then
   149      trace "setup kind cluster" setup_kind_cluster_retry "istio-testing" "${NODE_IMAGE}" "${KIND_CONFIG}"
   150    else
   151      trace "load cluster topology" load_cluster_topology "${CLUSTER_TOPOLOGY_CONFIG_FILE}"
   152      trace "setup kind clusters" setup_kind_clusters "${NODE_IMAGE}" "${IP_FAMILY}"
   153  
   154      TOPOLOGY_JSON=$(cat "${CLUSTER_TOPOLOGY_CONFIG_FILE}")
   155      for i in $(seq 0 $((${#CLUSTER_NAMES[@]} - 1))); do
   156        CLUSTER="${CLUSTER_NAMES[i]}"
   157        KCONFIG="${KUBECONFIGS[i]}"
   158        TOPOLOGY_JSON=$(set_topology_value "${TOPOLOGY_JSON}" "${CLUSTER}" "meta.kubeconfig" "${KCONFIG}")
   159      done
   160      RUNTIME_TOPOLOGY_CONFIG_FILE="${ARTIFACTS}/topology-config.json"
   161      echo "${TOPOLOGY_JSON}" > "${RUNTIME_TOPOLOGY_CONFIG_FILE}"
   162  
   163      export INTEGRATION_TEST_TOPOLOGY_FILE
   164      INTEGRATION_TEST_TOPOLOGY_FILE="${RUNTIME_TOPOLOGY_CONFIG_FILE}"
   165  
   166      export INTEGRATION_TEST_KUBECONFIG
   167      INTEGRATION_TEST_KUBECONFIG=NONE
   168    fi
   169  fi
   170  
   171  if [[ -z "${SKIP_BUILD:-}" ]]; then
   172    trace "setup kind registry" setup_kind_registry
   173    trace "build images" build_images "${PARAMS[*]}"
   174  fi
   175  
   176  # Run the test target if provided.
   177  if [[ -n "${PARAMS:-}" ]]; then
   178    trace "test" make "${PARAMS[*]}"
   179  fi
   180  
   181  # Check if the user is running the clusters in manual mode.
   182  if [[ -n "${MANUAL:-}" ]]; then
   183    echo "Running cluster(s) in manual mode. Press any key to shutdown and exit..."
   184    read -rsn1
   185    exit 0
   186  fi