Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Kidswiss committed Sep 10, 2024
1 parent 2d37da1 commit a0086a1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ __debug_bin*

# Ignore crossplane packages
*.xpkg

hack/res
hack/tmp
50 changes: 37 additions & 13 deletions hack/diff/compare.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/bin/bash

set -e

# get the state and all objects from each composite
function get_state() {
type="$1"
name="$2"
dir_name="tmp/$type-$name"
dir_name="hack/tmp/$type-$name"

mkdir -p "$dir_name"

Expand All @@ -19,7 +21,7 @@ function get_state() {
function get_claim_namespace() {
type="$1"
name="$2"
dir_name="tmp/$type-$name"
dir_name="hack/tmp/$type-$name"

ns=$(kubectl get "$type" "$name" -oyaml | yq -r '.metadata.labels["crossplane.io/claim-namespace"]')
kubectl get ns "$ns" -oyaml > "$dir_name/namespace.yaml"
Expand All @@ -38,24 +40,24 @@ function stop_func() {
function run_single_diff() {
type="$1"
name="$2"
dir_name="tmp/$type-$name"
res_dir_name="res/$type/$name"
dir_name="hack/tmp/$type-$name"
res_dir_name="hack/res/$type/$name"

mkdir -p "$res_dir_name"

kubectl get "$type" "$name" -oyaml > xr.yaml
kubectl get "$type" "$name" -oyaml > hack/tmp/xr.yaml
comp=$(kubectl get "$type" "$name" -oyaml | yq -r '.spec.compositionRef.name')
echo "composition: $comp"
kubectl get compositions.apiextensions.crossplane.io "$comp" -oyaml > composition.yaml
go run github.com/crossplane/crossplane/cmd/[email protected] render hack/diff/xr.yaml hack/diff/composition.yaml hack/diff/function.yaml -o "$dir_name" > "$res_dir_name/$3.yaml"
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"
}

function get_running_func_version() {
version=$(kubectl get function function-appcat -oyaml | yq -r '.spec.package' | cut -d ":" -f2)
echo "${version%"-func"}"
}
function diff() {
function diff_func() {
run_func "$1"
trap stop_func EXIT
Expand All @@ -65,20 +67,42 @@ function diff() {
get_claim_namespace "$type" "$name"
run_single_diff "$type" "$name" "$2"
done <<< "$(kubectl get composite --no-headers | sed 's/\// /g' )"
stop_func
}
# do the diff
function first_diff() {
diff "$(get_running_func_version)" "first"
diff_func "$(get_running_func_version)" "first"
}
function second_diff() {
diff "$(git rev-parse --abbrev-ref HEAD | sed 's/\//_/g')" "second"
diff_func "$(git rev-parse --abbrev-ref HEAD | sed 's/\//_/g')" "second"
}
function compare() {
for f in hack/res/*/*;
do
go run github.com/homeport/dyff/cmd/[email protected] between --omit-header "$f/first.yaml" "$f/second.yaml"
# diff "$f/first.yaml" "$f/second.yaml"
done
}
function clean() {
rm -rf hack/tmp
rm -rf hack/res
}
stop_func
rm -rf tmp
rm -rf res
clean
echo "Render live manifests"
first_diff
seconf_diff
echo "Render against branch"
second_diff
echo "Comparing"
compare
clean

0 comments on commit a0086a1

Please sign in to comment.