From 2454702093d59ad8e3ee03094a4d33cc12602a72 Mon Sep 17 00:00:00 2001 From: juicer Date: Fri, 10 Nov 2023 23:32:00 -0800 Subject: [PATCH] sort CRs by metadata.name Signed-off-by: juicer --- apis/fluentd/v1alpha1/helper.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/apis/fluentd/v1alpha1/helper.go b/apis/fluentd/v1alpha1/helper.go index 7ab96daf4..b0244b8cb 100644 --- a/apis/fluentd/v1alpha1/helper.go +++ b/apis/fluentd/v1alpha1/helper.go @@ -4,6 +4,7 @@ import ( "bytes" "errors" "fmt" + "sort" "strings" "github.com/fluent/fluent-operator/v2/apis/fluentd/v1alpha1/plugins" @@ -120,7 +121,16 @@ func (pgr *PluginResources) PatchAndFilterClusterLevelResources( cfgResources := NewCfgResources() errs := make([]string, 0) - + // sort all the CRs by metadata.name + sort.SliceStable(clusterInputs[:], func(i, j int) bool { + return clusterInputs[i].Name < clusterInputs[j].Name + }) + sort.SliceStable(clusterfilters[:], func(i, j int) bool { + return clusterfilters[i].Name < clusterfilters[j].Name + }) + sort.SliceStable(clusteroutputs[:], func(i, j int) bool { + return clusteroutputs[i].Name < clusteroutputs[j].Name + }) // List all inputs matching the label selector. for _, i := range clusterInputs { // patch filterId