Sometimes you refactor Helm charts: move logic, simplify templates, merge files or clean up loops and functions.
The goal of refactoring is not to change the final Kubernetes manifests.
A simple way to verify this is to render the manifests before and after the change and compare them.
Basic workflow
Step 0: Install dependencies
brew install yq
brew install dyff
yq - will be used to sort Kubernetes manifests.
dyff - will be used to compare YAML files, highlights real configuration changes and ignores formatting differences.
Step 1: Render manifests before changes
helm template my-release ./chart -f values.yaml > before.yaml
Step 2: Refactor the Helm chart
Change templates, refactor logic, reorganize files.
Step 3: Render manifests again
helm template my-release ./chart -f values.yaml > after.yaml
Step 4: Sort manifests (to avoid noise from ordering)
yq -s 'sort_by(.kind, .metadata.name)' before.yaml > before_sorted.yaml
yq -s 'sort_by(.kind, .metadata.name)' after.yaml > after_sorted.yaml
Sorting prevents differences caused only by resource order changes.
Step 5: Compare manifests
dyff between before_sorted.yaml after_sorted.yaml
Result
If no differences are reported, your refactor did not change the resulting Kubernetes manifests, which means the refactor is safe.

Top comments (0)