Skip to content

Commit 4684693

Browse files
committed
adding helm-diff target
Signed-off-by: hjoshi123 <mail@hjoshi.me>
1 parent d226527 commit 4684693

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

modules/helm/helm.mk

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ helm_chart_sources := $(shell find $(helm_chart_source_dir) -maxdepth 1 -type f)
4444
helm_chart_archive := $(bin_dir)/scratch/helm/$(helm_chart_name)-$(helm_chart_version).tgz
4545
helm_digest_path := $(bin_dir)/scratch/helm/$(helm_chart_name)-$(helm_chart_version).digests
4646
helm_digest = $(shell head -1 $(helm_digest_path) 2> /dev/null)
47+
HELM_IGNORE_FIELDS ?= 'app.kubernetes.io/version\|helm.sh/chart\|chart:\|appVersion:\|managed-by:\|meta.helm.sh/release-namespace'
48+
helm_chart_old_version ?=
49+
helm_chart_oci_name ?= cert-manager
4750

4851
$(bin_dir)/scratch/helm:
4952
@mkdir -p $@
@@ -187,3 +190,19 @@ verify-helm-kubeconform: $(helm_chart_archive) | $(NEEDS_KUBECONFORM)
187190
-strict
188191

189192
shared_verify_targets_dirty += verify-helm-kubeconform
193+
194+
.PHONY: helm-diff
195+
helm-diff: $(helm_chart_archive) | $(NEEDS_HELM)
196+
@if [ -z "$(helm_chart_old_version)" ] then; \
197+
echo "Usage: make helm-diff helm_chart_old_version=<version>"; \
198+
exit 1; \
199+
fi
200+
201+
@TMP_OLD=$$(mktemp -d);
202+
@TMP_NEW=$$(mktemp -d);
203+
@OUTPUT_DIR=$$(mktemp -d);
204+
205+
$(HELM) template $(helm_chart_oci_name) --repo "oci://$(helm_chart_image_registry)" --version "$(helm_chart_old_version)" > $${TMP_OLD}/old.yaml;
206+
$(HELM) template $(helm_chart_archive) > $${TMP_NEW}/new.yaml;
207+
208+
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;

0 commit comments

Comments
 (0)