From d76ad66633759d022f1cd013c6e2a1de276901bb Mon Sep 17 00:00:00 2001 From: Simon Beck Date: Tue, 24 Sep 2024 09:37:02 +0200 Subject: [PATCH] Optimize execution time for CI/CD --- Makefile | 6 +++++- hack/diff/compare.sh | 24 ++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 34a6cefd90..d0bbc85875 100644 --- a/Makefile +++ b/Makefile @@ -216,5 +216,9 @@ install-proxy: kubectl apply -f hack/functionproxy .PHONY: render-diff -render-diff: docker-build-branchtag ## Render diff between the cluter in KUBECONF and the local branch +render-diff: export IMG_TAG=$(shell git rev-parse --abbrev-ref HEAD | sed 's/\//_/g') +render-diff: ## Render diff between the cluster in KUBECONF and the local branch + # We check if the image is pullable, if so we pull it, otherwise we build the image + # this will speed up the compare in CI/CD environments. + if ! docker pull $(IMG); then $(MAKE) docker-build-branchtag; fi hack/diff/compare.sh diff --git a/hack/diff/compare.sh b/hack/diff/compare.sh index 37ce59f8c4..9142b7df6b 100755 --- a/hack/diff/compare.sh +++ b/hack/diff/compare.sh @@ -44,7 +44,15 @@ function run_single_diff() { comp=$(kubectl get "$type" "$name" -oyaml | yq -r '.spec.compositionRef.name') echo "composition: $comp $type/$name" kubectl get compositions.apiextensions.crossplane.io "$comp" -oyaml > hack/tmp/composition.yaml - go run github.com/crossplane/crossplane/cmd/crank@v1.17.0 render hack/tmp/xr.yaml hack/tmp/composition.yaml hack/diff/function.yaml -o "$dir_name" > "$res_dir_name/$3.yaml" + crank_func render hack/tmp/xr.yaml hack/tmp/composition.yaml hack/diff/function.yaml -o "$dir_name" > "$res_dir_name/$3.yaml" +} + +function crank_func() { + mkdir -p .work/bin + [ ! -f .work/bin/crank ] && curl -s https://releases.crossplane.io/stable/v1.17.0/bin/linux_amd64/crank -o .work/bin/crank + chmod +x .work/bin/crank + if .work/bin/crank -h > /dev/null 2>&1; then .work/bin/crank "$@"; + else go run github.com/crossplane/crossplane/cmd/crank@v1.17.0 "$@"; fi } function get_running_func_version() { @@ -89,11 +97,14 @@ function second_diff() { function compare() { for f in hack/res/*/*; do + echo "comparing $f" + # enable color # ignore changed array order # exclude nested managedFields in kube objects # exclude nested resourceVersion # don't print the huge dyff header - go run github.com/homeport/dyff/cmd/dyff@v1.9.0 between \ + dyff between \ + --color=on \ -i \ --exclude-regexp "spec.forProvider.manifest.metadata.managedFields.*" \ --exclude "spec.forProvider.manifest.metadata.resourceVersion" \ @@ -103,6 +114,15 @@ function compare() { done } +function dyff() { + mkdir -p .work/bin + [ ! -f .work/bin/dyff ] && curl -sL https://github.com/homeport/dyff/releases/download/v1.9.1/dyff_1.9.1_linux_amd64.tar.gz -o .work/bin/dyff.tar.gz && \ + tar xvfz .work/bin/dyff.tar.gz -C .work/bin > /dev/null 2>&1 + chmod +x .work/bin/dyff + if .work/bin/dyff version > /dev/null 2>&1 ; then .work/bin/dyff "$@"; + else go run github.com/homeport/dyff/cmd/dyff@v1.9.1 "$@"; fi +} + function clean() { rm -rf hack/tmp rm -rf hack/res