Skip to content

Instantly share code, notes, and snippets.

@techmexdev
Last active October 15, 2022 20:54
Show Gist options
  • Save techmexdev/5183be77abb26679e3f5d7ff99171731 to your computer and use it in GitHub Desktop.
Save techmexdev/5183be77abb26679e3f5d7ff99171731 to your computer and use it in GitHub Desktop.
Deletes the leftover resources after purging a chart. Workaround for: https://github.com/helm/helm/issues/6646
#!/usr/bin/env bash
ENV=$1
APP=$2
NAMESPACE=$3
FILENAME=upgrade-error.txt
while true
do
function upgrade() {
helm upgrade $APP . \
--install --namespace $NAMESPACE \
-f values.yaml -f $ENV.values.yaml -f $ENV.secrets.yaml \
2>&1 | tee $FILENAME
}
upgrade
kind=$(cat $FILENAME | grep -oE 'kind:\ (\S[^,]*)' \
| sed 's/kind:\ //g' | awk '{print tolower($0)}')
name=$(cat $FILENAME | grep -oE 'name:\ (\S[^,]*)' \
| sed 's/name:\ //g')
echo "Delete kind: $kind with name: $name?
Only 'y' will be accepted to approve."
read -p "Enter a value: " shouldContinue
if [[ "$shouldContinue" != "y" ]]; then
echo "You have canceled the upgrade"
exit
fi
kubectl delete $kind $name
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment