1#!/usr/bin/env bash 2# Copyright 2021 The gRPC 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 16set -ex 17 18# consts 19readonly GITHUB_REPOSITORY_NAME="grpc" 20readonly TEST_DRIVER_INSTALL_SCRIPT_URL="https://raw.githubusercontent.com/${TEST_DRIVER_REPO_OWNER:-grpc}/grpc/${TEST_DRIVER_BRANCH:-master}/tools/internal_ci/linux/grpc_xds_k8s_install_test_driver.sh" 21 22cd "$(dirname "$0")/../../.." 23 24# Source the test driver from the master branch. 25echo "Sourcing test driver install script from: ${TEST_DRIVER_INSTALL_SCRIPT_URL}" 26source /dev/stdin <<< "$(curl -s "${TEST_DRIVER_INSTALL_SCRIPT_URL}")" 27activate_gke_cluster GKE_CLUSTER_PSM_SECURITY 28kokoro_setup_test_driver "${GITHUB_REPOSITORY_NAME}" 29 30cd "${TEST_DRIVER_FULL_DIR}" 31 32# flag resource_prefix is required by the gke test framework, but doesn't 33# matter for the cleanup script. 34python3 -m bin.cleanup.cleanup \ 35 --project=grpc-testing \ 36 --network=default-vpc \ 37 --kube_context="${KUBE_CONTEXT}" \ 38 --gcp_service_account=xds-k8s-interop-tests@grpc-testing.iam.gserviceaccount.com \ 39 --resource_prefix='required-but-does-not-matter' \ 40 --td_bootstrap_image='required-but-does-not-matter' --server_image='required-but-does-not-matter' --client_image='required-but-does-not-matter' 41 42# The BASIC cluster is used by url-map tests. Only cleaning the GKE client 43# namespaces, which won't provide much value in debugging. The keep hours is 44# reduced to 6. 45activate_gke_cluster GKE_CLUSTER_PSM_BASIC 46# Invoking the get-crednetials directly, because the 47# gcloud_get_cluster_credentials re-sets readonly Bash variables, which is nice 48# safety mechanism to keep. 49gcloud container clusters get-credentials "${GKE_CLUSTER_NAME}" --zone "${GKE_CLUSTER_ZONE}" 50TARGET_KUBE_CONTEXT="$(kubectl config current-context)" 51python3 -m bin.cleanup.namespace \ 52 --project=grpc-testing \ 53 --network=default-vpc \ 54 --keep_hours=6 \ 55 --kube_context="${TARGET_KUBE_CONTEXT}" \ 56 --gcp_service_account=xds-k8s-interop-tests@grpc-testing.iam.gserviceaccount.com \ 57 --resource_prefix='required-but-does-not-matter' \ 58 --td_bootstrap_image='required-but-does-not-matter' --server_image='required-but-does-not-matter' --client_image='required-but-does-not-matter' 59 60# The PSM_LB cluster is used by k8s_lb tests. Only cleaning the GKE client 61# namespaces, which won't provide much value in debugging. The keep hours is 62# reduced to 6. 63activate_gke_cluster GKE_CLUSTER_PSM_LB 64gcloud container clusters get-credentials "${GKE_CLUSTER_NAME}" --zone "${GKE_CLUSTER_ZONE}" 65TARGET_KUBE_CONTEXT="$(kubectl config current-context)" 66python3 -m bin.cleanup.namespace \ 67 --project=grpc-testing \ 68 --network=default-vpc \ 69 --keep_hours=6 \ 70 --kube_context="${TARGET_KUBE_CONTEXT}" \ 71 --gcp_service_account=xds-k8s-interop-tests@grpc-testing.iam.gserviceaccount.com \ 72 --resource_prefix='required-but-does-not-matter' \ 73 --td_bootstrap_image='required-but-does-not-matter' --server_image='required-but-does-not-matter' --client_image='required-but-does-not-matter' 74