1#!/usr/bin/env bash
2# Copyright 2021 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 -eo pipefail
17
18display_usage() {
19  cat <<EOF >/dev/stderr
20Performs full TD and K8S resource cleanup
21
22USAGE: $0 [--nosecure] [arguments]
23   --nosecure: Skip cleanup for the resources specific for PSM Security
24   arguments ...: additional arguments passed to ./run.sh
25
26ENVIRONMENT:
27   XDS_K8S_CONFIG: file path to the config flagfile, relative to
28                   driver root folder. Default: config/local-dev.cfg
29                   Will be appended as --flagfile="config_absolute_path" argument
30   XDS_K8S_DRIVER_VENV_DIR: the path to python virtual environment directory
31                            Default: $XDS_K8S_DRIVER_DIR/venv
32EXAMPLES:
33$0
34$0 --secure
35XDS_K8S_CONFIG=./path-to-flagfile.cfg $0 --resource_suffix=override-suffix
36EOF
37  exit 1
38}
39
40if [[ "$1" == "-h" || "$1" == "--help" ]]; then
41  display_usage
42fi
43
44SCRIPT_DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
45readonly SCRIPT_DIR
46readonly XDS_K8S_DRIVER_DIR="${SCRIPT_DIR}/.."
47
48cd "${XDS_K8S_DRIVER_DIR}"
49
50if [[ "$1" == "--nosecure" ]]; then
51  shift
52  ./run.sh bin/run_td_setup.py --cmd=cleanup "$@" && \
53  ./run.sh bin/run_test_client.py --cmd=cleanup --cleanup_namespace "$@" && \
54  ./run.sh bin/run_test_server.py --cmd=cleanup --cleanup_namespace "$@"
55else
56  ./run.sh bin/run_td_setup.py --cmd=cleanup --security=mtls "$@" && \
57  ./run.sh bin/run_test_client.py --cmd=cleanup --cleanup_namespace --secure "$@" && \
58  ./run.sh bin/run_test_server.py --cmd=cleanup --cleanup_namespace --secure "$@"
59fi
60