From c14c4c80d065727f1fc7c76a6ea37b1f8f343909 Mon Sep 17 00:00:00 2001 From: Bartek Grzybowski Date: Mon, 28 Jun 2021 15:06:58 +0200 Subject: [TOOLS] Use release's chart manifest to collect kubernetes object Since Helm v3 is no longer showing kubernetes objects associated with a release, charts manifest is used to get those. Ref.: https://github.com/helm/helm/issues/5952 Change-Id: Idf16124663186b8d5b8ce2b408bdf7d399b12b48 Issue-ID: OOM-2770 Signed-off-by: Bartek Grzybowski --- tools/helm-healer.sh | 39 +++++---------------------------------- 1 file changed, 5 insertions(+), 34 deletions(-) (limited to 'tools/helm-healer.sh') diff --git a/tools/helm-healer.sh b/tools/helm-healer.sh index a6870fe2..650c7d12 100755 --- a/tools/helm-healer.sh +++ b/tools/helm-healer.sh @@ -222,34 +222,7 @@ delete_job() #arg: get_resources_for_component() { - -helm -n ${NAMESPACE} status $1 | awk -f <(cat - <<-'EOD' -BEGIN { - work="no" - kind="" - a["dummy"]="" -} - -$1 ~ ":" { - if ( $1 == "RESOURCES:" ) { - work="yes" -} else { - work="no" -} - -} - -$1 == "==>" { - split($2, a, "[/(]") - kind=a[2] -} - -$1 != "NAME" && $1 != "==>" && work == "yes" && $1 !~ ":" && $1 != "" { - printf "%s/%s\n", kind, $1 -} - -EOD -) + helm -n ${NAMESPACE} get manifest $1 | kubectl -n ${NAMESPACE} get -f - | awk '{print $1}' | grep -v NAME | grep -v ^$ } # arg: @@ -259,8 +232,7 @@ delete_resource() local _kind="${_resource%/*}" local _name="${_resource#*/}" - - if kubectl get ${_resource} >/dev/null 2>&1; then + if kubectl -n ${NAMESPACE} get ${_resource} >/dev/null 2>&1; then msg "${_resource} has not been removed with helm undeploy, manual removal is required. Proceeding" kubectl delete ${_resource} -n ${NAMESPACE} \ --cascade=true \ @@ -378,19 +350,18 @@ undeploy_component() for resource in ${_component_resources[@]}; do case $resource in - CronJob/* | Job/* | Secret/* | ConfigMap/* | Pod/* | Service/* | Deployment/* | StatefulSet/*) + cronjob/* | job.batch/* | secret/* | configmap/* | service/* | deployment.apps/* | statefulset.apps/* | serviceaccount/* | rolebinding.rbac.authorization.k8s.io/* | role.rbac.authorization.k8s.io/* | poddisruptionbudget.policy/* | clusterrolebinding.rbac.authorization.k8s.io/*) _standard+=(${resource});; #Ignoring PVC, they will be handled along with PV as 'helm' status does not return them for some components - PersistentVolumeClaim/*) + persistentvolumeclaim/*) ;; - PersistentVolume/*) + persistentvolume/*) _persistent_volumes+=(${resource});; *) _unknown_kinds+=(${resource}) esac done - #Gathering physical location of directories for persistent volumes to delete them after undeploy declare -a _physical_locations for volume in ${_persistent_volumes[@]}; do -- cgit 1.2.3-korg