Skip to content

Instantly share code, notes, and snippets.

@chr0n1x
Last active August 27, 2025 19:27
Show Gist options
  • Save chr0n1x/3d953debcc7d0518a86b1f61c194bbb9 to your computer and use it in GitHub Desktop.
Save chr0n1x/3d953debcc7d0518a86b1f61c194bbb9 to your computer and use it in GitHub Desktop.
generate a pretty diff between what a helm chart will generate, vs what's live in a namespace
#!/bin/bash
# Designed to be run INSIDE of a helm chart directory
# and that you have already run `helm dep up`
#
# Requires delta for diffs (cause it's pwetty :3)
# https://dandavison.github.io/delta/
#
# this also already assumes that you have properly set up KUBECONFIG, kubectx, and kubens
# so that we can fetch resources that are live via kubectl
echo "generating chart manifest ..."
# note that this assumes only one values file, edit this if there are more
helm template . -f values.yaml > generated.helm.yaml
echo "done"
kinds=$(yq '.kind' generated.helm.yaml | grep -v '-' | grep -v 'null' | sort | uniq | xargs | sed 's/ /,/g')
echo "fetching k8s kinds $kinds from current ns ..."
kubectl get $kinds -o=yaml > live.raw.yaml
echo "done"
echo "sorting live manifests"
yq '.items | sort_by(.kind, .metadata.name) | .[] | split_doc' live.raw.yaml > live.split-doc.yaml
yq e '(... | select(type == "!!map")) |= sort_by(key | downcase)' live.split-doc.yaml > live.final.yaml
echo "done"
echo "sorting helm generated manifests"
yq ea '[.] | sort_by(.kind, .metadata.name) | .[] | split_doc' generated.helm.yaml > generated.sorted.yaml
yq e '(... | select(type == "!!map")) |= sort_by(key | downcase)' generated.sorted.yaml > generated.final.yaml
echo "done"
DELTA_FEATURES="+side-by-side" delta generated.final.yaml live.final.yaml
echo "cleaning up"
rm generated.helm.yaml generated.sorted.yaml generated.final.yaml \
live.raw.yaml live.split-doc.yaml live.final.yaml
echo "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment