Checking a Helm Chart Refactor with Manifest Diff
Source: Dev.to
Introduction
When refactoring Helm charts—whether moving logic, simplifying templates, merging files, or cleaning up loops and functions—the goal is to keep the final Kubernetes manifests unchanged. Rendering the manifests before and after the refactor and comparing them provides a simple verification method.
Prerequisites
- yq – used to sort Kubernetes manifests.
brew install yq - dyff – compares YAML files, highlighting real configuration changes while ignoring formatting differences.
brew install dyff
Steps
Step 1: Render manifests before changes
helm template my-release ./chart -f values.yaml > before.yamlStep 2: Refactor the Helm chart
(Make your desired changes to the chart files.)
Step 3: Render manifests again
helm template my-release ./chart -f values.yaml > after.yamlStep 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.yamlSorting prevents differences caused only by resource order changes.
Step 5: Compare manifests
dyff between before_sorted.yaml after_sorted.yamlIf no differences are reported, the refactor did not alter the resulting Kubernetes manifests, indicating that the refactor is safe.