From 7f06c50342a8a2a15f2d25f4da9c20c92ce5abd6 Mon Sep 17 00:00:00 2001 From: Simon Beck Date: Tue, 10 Sep 2024 11:06:00 +0200 Subject: [PATCH] WIP --- Makefile | 4 ++++ hack/diff/compare.sh | 2 ++ .../functions/common/nonsla/non_sla_prom_rules.go | 6 ++++++ 3 files changed, 12 insertions(+) mode change 100644 => 100755 hack/diff/compare.sh diff --git a/Makefile b/Makefile index edcd3e36b4..1791e78992 100644 --- a/Makefile +++ b/Makefile @@ -213,3 +213,7 @@ bootstrap: api-bootstrap generate ## API bootstrapping, create a new claim/compo .PHONY: install-proxy 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 + hack/diff/compare.sh diff --git a/hack/diff/compare.sh b/hack/diff/compare.sh old mode 100644 new mode 100755 index 51a3f26688..a9baeb72dd --- a/hack/diff/compare.sh +++ b/hack/diff/compare.sh @@ -2,6 +2,8 @@ set -e +[ -z "${KUBECONFIG}" ] && echo "Please export KUBECONFIG" && exit 1 + # get the state and all objects from each composite function get_state() { type="$1" diff --git a/pkg/comp-functions/functions/common/nonsla/non_sla_prom_rules.go b/pkg/comp-functions/functions/common/nonsla/non_sla_prom_rules.go index b669a92b8a..f1dfa694bd 100644 --- a/pkg/comp-functions/functions/common/nonsla/non_sla_prom_rules.go +++ b/pkg/comp-functions/functions/common/nonsla/non_sla_prom_rules.go @@ -3,6 +3,7 @@ package nonsla import ( "context" "fmt" + "sort" fnproto "github.com/crossplane/function-sdk-go/proto/v1beta1" promV1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" @@ -38,6 +39,11 @@ func GenerateNonSLAPromRules[T client.Object](alerts Alerts) func(ctx context.Co } rules = append(rules, alerts.customRules...) + // Sort the alerts to avoid random diff changes + sort.Slice(rules, func(i, j int) bool { + return rules[i].Alert < rules[j].Alert + }) + err = generatePromeRules(elem.GetName(), elem.GetInstanceNamespace(), rules, svc) if err != nil { return runtime.NewWarningResult("can't create prometheus rules: " + err.Error())