Skip to content

Commit

Permalink
Optimize execution time for CI/CD
Browse files Browse the repository at this point in the history
  • Loading branch information
Kidswiss committed Sep 24, 2024
1 parent 17388f9 commit d76ad66
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 22 additions & 2 deletions hack/diff/compare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected] 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/[email protected] "$@"; fi
}

function get_running_func_version() {
Expand Down Expand Up @@ -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/[email protected] between \
dyff between \
--color=on \
-i \
--exclude-regexp "spec.forProvider.manifest.metadata.managedFields.*" \
--exclude "spec.forProvider.manifest.metadata.resourceVersion" \
Expand All @@ -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/[email protected] "$@"; fi
}
function clean() {
rm -rf hack/tmp
rm -rf hack/res
Expand Down

0 comments on commit d76ad66

Please sign in to comment.