diff --git a/modules/helm/helm.mk b/modules/helm/helm.mk index 6c84d1f7..8f387197 100644 --- a/modules/helm/helm.mk +++ b/modules/helm/helm.mk @@ -44,6 +44,9 @@ helm_chart_sources := $(shell find $(helm_chart_source_dir) -maxdepth 1 -type f) helm_chart_archive := $(bin_dir)/scratch/helm/$(helm_chart_name)-$(helm_chart_version).tgz helm_digest_path := $(bin_dir)/scratch/helm/$(helm_chart_name)-$(helm_chart_version).digests helm_digest = $(shell head -1 $(helm_digest_path) 2> /dev/null) +HELM_IGNORE_FIELDS ?= 'app.kubernetes.io/version\|helm.sh/chart\|chart:\|appVersion:\|managed-by:\|meta.helm.sh/release-namespace' +helm_chart_old_version ?= +helm_chart_oci_name ?= cert-manager $(bin_dir)/scratch/helm: @mkdir -p $@ @@ -187,3 +190,19 @@ verify-helm-kubeconform: $(helm_chart_archive) | $(NEEDS_KUBECONFORM) -strict shared_verify_targets_dirty += verify-helm-kubeconform + +.PHONY: helm-diff +helm-diff: $(helm_chart_archive) | $(NEEDS_HELM) + @if [ -z "$(helm_chart_old_version)" ]; then \ + echo "Usage: make helm-diff helm_chart_old_version="; \ + exit 1; \ + fi + + $(eval export TMP_OLD=$$(mktemp -d)) + $(eval export TMP_NEW=$$(mktemp -d)) + $(eval export OUTPUT_DIR=$$(mktemp -d)) + + $(HELM) template $(helm_chart_oci_name) --repo "oci://$(helm_chart_image_registry)" --version "$(helm_chart_old_version)" > $${TMP_OLD}/old.yaml; + $(HELM) template $(helm_chart_archive) > $${TMP_NEW}/new.yaml; + + diff -u <(grep -vE $(HELM_IGNORE_FIELDS) $${TMP_OLD}/old.yaml) <(grep -vE $(HELM_IGNORE_FIELDS) $${TMP_NEW}/new.yaml) | tee "$(OUTPUT_DIR)/diff.txt" || true;