Skip to content

Instantly share code, notes, and snippets.

@tyzbit
Created September 15, 2024 21:28
Show Gist options
  • Save tyzbit/c66a3a6562d4496ca3c309746780c04e to your computer and use it in GitHub Desktop.
Save tyzbit/c66a3a6562d4496ca3c309746780c04e to your computer and use it in GitHub Desktop.
Find unused Flux HelmRepository objects
#!/bin/bash
# List all HelmRepository names
repositories=$(kubectl get helmrepositories -A -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}')
# List all HelmRelease sources (HelmRepository names they reference)
releases=$(kubectl get helmreleases -A -o jsonpath='{range .items[*]}{.spec.chart.spec.sourceRef.name}{"\n"}{end}')
# Find HelmRepositories not used by HelmReleases
for repo in $repositories; do
if ! echo "$releases" | grep -q "$repo"; then
echo "HelmRepository not associated with any HelmRelease: $repo"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment