grpc_xds_resource_cleanup.sh 3.2 KB

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