uninstall_milvus.sh 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/bash
  2. # Copyright (C) 2019-2020 Zilliz. All rights reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
  5. # with the License. You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software distributed under the License
  10. # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  11. # or implied. See the License for the specific language governing permissions and limitations under the License.
  12. # Exit immediately for non zero status
  13. set -e
  14. # Print commands
  15. # set -x
  16. while (( "$#" )); do
  17. case "$1" in
  18. --release-name)
  19. RELEASE_NAME=$2
  20. shift 2
  21. ;;
  22. -h|--help)
  23. { set +x; } 2>/dev/null
  24. HELP="
  25. Usage:
  26. $0 [flags] [Arguments]
  27. --release-name Milvus helm release name
  28. -h or --help Print help information
  29. Use \"$0 --help\" for more information about a given command.
  30. "
  31. echo -e "${HELP}" ; exit 0
  32. ;;
  33. -*)
  34. echo "Error: Unsupported flag $1" >&2
  35. exit 1
  36. ;;
  37. *) # preserve positional arguments
  38. PARAMS+=("$1")
  39. shift
  40. ;;
  41. esac
  42. done
  43. MILVUS_HELM_RELEASE_NAME="${MILVUS_HELM_RELEASE_NAME:-milvus-testing}"
  44. MILVUS_HELM_NAMESPACE="${MILVUS_HELM_NAMESPACE:-default}"
  45. if [[ -n "${RELEASE_NAME:-}" ]]; then
  46. MILVUS_HELM_RELEASE_NAME="${RELEASE_NAME}"
  47. # List pod list before uninstall
  48. kubectl get pods -n ${MILVUS_HELM_NAMESPACE} -o wide | grep "${MILVUS_HELM_RELEASE_NAME}-"
  49. # Show restart pods last terminated reason
  50. restart_pods=$(kubectl get pods -n ${MILVUS_HELM_NAMESPACE} | grep "${MILVUS_HELM_RELEASE_NAME}-" | grep 'ago)' | awk '{print $1}')
  51. for restart_pod in ${restart_pods}
  52. do
  53. reason=$(kubectl get pod ${restart_pod} -n ${MILVUS_HELM_NAMESPACE} -o json | jq .status.containerStatuses[0].lastState.terminated.reason )
  54. restart_count=$(kubectl get pod ${restart_pod} -n${MILVUS_HELM_NAMESPACE} -o json | jq .status.containerStatuses[0].restartCount )
  55. echo "${restart_pod} restarts ${restart_count}, last terminateed reason is ${reason}"
  56. done
  57. echo "----------------Pod Events --------------------------------------------"
  58. for pod in $(kubectl get pods -n ${MILVUS_HELM_NAMESPACE} -o wide | grep "${MILVUS_HELM_RELEASE_NAME}-" | awk '{print $1}')
  59. do
  60. echo "--------------------------------${pod}-----------------------------"
  61. kubectl describe pod ${pod} -n ${MILVUS_HELM_NAMESPACE}
  62. done
  63. fi
  64. # Uninstall Milvus Helm Release
  65. # Do not exit with error when release not found so that the script can also be used to clean up related pvc even helm release has been uninstalled already
  66. helm uninstall -n "${MILVUS_HELM_NAMESPACE}" "${MILVUS_HELM_RELEASE_NAME}" || true
  67. MILVUS_LABELS1="app.kubernetes.io/instance=${MILVUS_HELM_RELEASE_NAME}"
  68. MILVUS_LABELS2="release=${MILVUS_HELM_RELEASE_NAME}"
  69. # Clean up pvc
  70. kubectl delete pvc --wait -n "${MILVUS_HELM_NAMESPACE}" $(kubectl get pvc -n "${MILVUS_HELM_NAMESPACE}" -l "${MILVUS_LABELS1}" -o jsonpath='{range.items[*]}{.metadata.name} ') || true
  71. kubectl delete pvc --wait -n "${MILVUS_HELM_NAMESPACE}" $(kubectl get pvc -n "${MILVUS_HELM_NAMESPACE}" -l "${MILVUS_LABELS2}" -o jsonpath='{range.items[*]}{.metadata.name} ') || true