Created
September 15, 2024 21:28
-
-
Save tyzbit/c66a3a6562d4496ca3c309746780c04e to your computer and use it in GitHub Desktop.
Find unused Flux HelmRepository objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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