From 07ab5075f4b755d61d675cdae970e52517742940 Mon Sep 17 00:00:00 2001 From: zhangl Date: Fri, 6 Dec 2024 08:33:03 -0800 Subject: [PATCH] Issue open-horizon#4179 - Bug: agent-uninstall.sh doesn't doesn't just act on the OH agent for getting node id Signed-off-by: zhangl --- agent-install/agent-uninstall.sh | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) mode change 100644 => 100755 agent-install/agent-uninstall.sh diff --git a/agent-install/agent-uninstall.sh b/agent-install/agent-uninstall.sh old mode 100644 new mode 100755 index 4f353b9e3..5302d5f4c --- a/agent-install/agent-uninstall.sh +++ b/agent-install/agent-uninstall.sh @@ -19,10 +19,6 @@ SKIP_DELETE_AGENT_NAMESPACE=false USE_DELETE_FORCE=false DELETE_TIMEOUT=10 # Default delete timeout -function now() { - echo `date '+%Y-%m-%d %H:%M:%S'` -} - # Exit handling function quit(){ case $1 in @@ -216,7 +212,7 @@ function get_agent_pod_id() { fi if [ "$AGENT_POD_READY" == "true" ]; then - POD_ID=$($KUBECTL get pod -n ${AGENT_NAMESPACE} 2> /dev/null | grep "agent-" | cut -d " " -f1 2> /dev/null) + POD_ID=$($KUBECTL get pod -n ${AGENT_NAMESPACE} -l app=agent,type!=auto-upgrade-cronjob 2> /dev/null | grep "agent-" | cut -d " " -f1 2> /dev/null) if [ -n "${POD_ID}" ]; then log_info "get pod: ${POD_ID}" else @@ -288,8 +284,9 @@ function unregister() { log_debug "unregister() end" } +# escape: ;, $, &, |, (, ) function getEscapedExchangeUserAuth() { - local escaped_auth=$( echo "${HZN_EXCHANGE_USER_AUTH}" | sed 's/;/\\;/g;s/\$/\\$/g;s/\&/\\&/g;s/|/\\|/g' ) + local escaped_auth=$( echo "${HZN_EXCHANGE_USER_AUTH}" | sed 's/;/\\;/g;s/\$/\\$/g;s/\&/\\&/g;s/|/\\|/g;s/(/\\(/g;s/)/\\)/g' ) echo "${escaped_auth}" } @@ -380,26 +377,26 @@ function deleteAgentResources() { fi log_info "Deleting agent service..." - $KUBECTL delete svc $SERVICE_NAME -n $AGENT_NAMESPACE --ignore-not-found + $KUBECTL delete svc $SERVICE_NAME -n $AGENT_NAMESPACE log_info "Deleting configmap..." - $KUBECTL delete configmap $CONFIGMAP_NAME -n $AGENT_NAMESPACE --ignore-not-found - $KUBECTL delete configmap ${CONFIGMAP_NAME}-backup -n $AGENT_NAMESPACE --ignore-not-found + $KUBECTL delete configmap $CONFIGMAP_NAME -n $AGENT_NAMESPACE + $KUBECTL delete configmap ${CONFIGMAP_NAME}-backup -n $AGENT_NAMESPACE log_info "Deleting secret..." - $KUBECTL delete secret $SECRET_NAME -n $AGENT_NAMESPACE --ignore-not-found - $KUBECTL delete secret $IMAGE_REGISTRY_SECRET_NAME -n $AGENT_NAMESPACE --ignore-not-found - $KUBECTL delete secret $IMAGE_PULL_SECRET_NAME -n $AGENT_NAMESPACE --ignore-not-found - $KUBECTL delete secret ${SECRET_NAME}-backup -n $AGENT_NAMESPACE --ignore-not-found + $KUBECTL delete secret $SECRET_NAME -n $AGENT_NAMESPACE + $KUBECTL delete secret $IMAGE_REGISTRY_SECRET_NAME -n $AGENT_NAMESPACE + $KUBECTL delete secret $IMAGE_PULL_SECRET_NAME -n $AGENT_NAMESPACE + $KUBECTL delete secret ${SECRET_NAME}-backup -n $AGENT_NAMESPACE log_info "Deleting persistent volume..." - $KUBECTL delete pvc $PVC_NAME -n $AGENT_NAMESPACE --ignore-not-found + $KUBECTL delete pvc $PVC_NAME -n $AGENT_NAMESPACE log_info "Deleting clusterrolebinding..." - $KUBECTL delete clusterrolebinding ${AGENT_NAMESPACE}-${CLUSTER_ROLE_BINDING_NAME} --ignore-not-found + $KUBECTL delete clusterrolebinding ${AGENT_NAMESPACE}-${CLUSTER_ROLE_BINDING_NAME} log_info "Deleting serviceaccount..." - $KUBECTL delete serviceaccount $SERVICE_ACCOUNT_NAME -n $AGENT_NAMESPACE --ignore-not-found + $KUBECTL delete serviceaccount $SERVICE_ACCOUNT_NAME -n $AGENT_NAMESPACE if [[ "$SKIP_DELETE_AGENT_NAMESPACE" != "true" ]]; then log_info "Checking deployment and statefulset under namespace $AGENT_NAMESPACE" @@ -416,7 +413,7 @@ function deleteAgentResources() { fi log_info "Deleting cert file from /etc/default/cert ..." - rm -f /etc/default/cert/agent-install.crt + rm /etc/default/cert/agent-install.crt set -e log_debug "deleteAgentResources() end"