#!/bin/bash # Copyright Istio Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. function setup_gcloud_credentials() { if [[ $(command -v gcloud) ]]; then gcloud auth configure-docker -q elif [[ $(command -v docker-credential-gcr) ]]; then docker-credential-gcr configure-docker else echo "No credential helpers found, push to docker may not function properly" fi } function setup_and_export_git_sha() { if [[ -n "${CI:-}" ]]; then if [ -z "${PULL_PULL_SHA:-}" ]; then if [ -z "${PULL_BASE_SHA:-}" ]; then GIT_SHA="$(git rev-parse --verify HEAD)" export GIT_SHA else export GIT_SHA="${PULL_BASE_SHA}" fi else export GIT_SHA="${PULL_PULL_SHA}" fi else # Use the current commit. GIT_SHA="$(git rev-parse --verify HEAD)" export GIT_SHA export ARTIFACTS="${ARTIFACTS:-$(mktemp -d)}" fi GIT_BRANCH="$(git rev-parse --abbrev-ref HEAD)" export GIT_BRANCH setup_gcloud_credentials } function cleanup_kind_cluster() { NAME="${1}" echo "Test exited with exit code $?." kind export logs --name "${NAME}" "${ARTIFACTS}/kind" -v9 || true if [[ -z "${SKIP_CLEANUP:-}" ]]; then echo "Cleaning up kind cluster" kind delete cluster --name "${NAME}" -v9 || true fi } function setup_kind_cluster() { IMAGE="${1:-kindest/node:v1.18.2}" NAME="${2:-istio-testing}" CONFIG="${3:-}" # Delete previous e2e KinD cluster echo "Deleting previous KinD cluster with name=${NAME}" if ! (kind delete cluster --name="${NAME}" -v9) > /dev/null; then echo "No existing kind cluster with name ${NAME}. Continue..." fi # explicitly disable shellcheck since we actually want $NAME to expand now # shellcheck disable=SC2064 trap "cleanup_kind_cluster ${NAME}" EXIT # If config not explicitly set, then use defaults if [[ -z "${CONFIG}" ]]; then # Kubernetes 1.15+ CONFIG=./prow/config/default.yaml fi # Create KinD cluster if ! (kind create cluster --name="${NAME}" --config "${CONFIG}" -v9 --retain --image "${IMAGE}" --wait=60s); then echo "Could not setup KinD environment. Something wrong with KinD setup. Exporting logs." exit 1 fi }