Skip to content

Instantly share code, notes, and snippets.

@mattmattox
Created August 7, 2024 11:06
Show Gist options
  • Save mattmattox/0633f7030da2d35cafe300d23d9b06bb to your computer and use it in GitHub Desktop.
Save mattmattox/0633f7030da2d35cafe300d23d9b06bb to your computer and use it in GitHub Desktop.
#!/bin/bash
# List all Helm releases in the cluster
helm list --all-namespaces --short | while read -r release; do
echo "Processing release: $release"
# Get revision history for the release
revisions=$(helm history "$release" --short | tail -n +2)
# Keep the latest revision
latest_revision=$(echo "$revisions" | head -n 1)
# Remove all revisions except the latest
echo "$revisions" | while read -r revision; do
if [[ "$revision" != "$latest_revision" ]]; then
echo "Deleting revision: $revision"
helm rollback "$release" "$revision"
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment