From 0e867b10496af1d0e06c68003fb3a2fd268519de Mon Sep 17 00:00:00 2001 From: karan k Date: Mon, 31 Jul 2023 15:24:40 +0530 Subject: [PATCH] Remove duplicate cluster parser Signed-off-by: karan k --- apis/fluentbit/v1alpha2/clusterfluentbitconfig_types.go | 6 +++--- apis/fluentbit/v1alpha2/clusterparser_types.go | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/apis/fluentbit/v1alpha2/clusterfluentbitconfig_types.go b/apis/fluentbit/v1alpha2/clusterfluentbitconfig_types.go index 7cb30d32e..dc4183438 100644 --- a/apis/fluentbit/v1alpha2/clusterfluentbitconfig_types.go +++ b/apis/fluentbit/v1alpha2/clusterfluentbitconfig_types.go @@ -280,8 +280,8 @@ func (cfg ClusterFluentBitConfig) RenderMainConfig(sl plugins.SecretLoader, inpu func (cfg ClusterFluentBitConfig) RenderParserConfig(sl plugins.SecretLoader, parsers ClusterParserList, nsParserLists []ParserList, nsClusterParserLists []ClusterParserList) (string, error) { var buf bytes.Buffer - - parserSections, err := parsers.Load(sl) + existingParsers := make(map[string]bool) + parserSections, err := parsers.Load(sl, existingParsers) if err != nil { return "", err } @@ -304,7 +304,7 @@ func (cfg ClusterFluentBitConfig) RenderParserConfig(sl plugins.SecretLoader, pa } for _, item := range nsClusterParserLists { - nsClusterParserSections, err := item.Load(sl) + nsClusterParserSections, err := item.Load(sl, existingParsers) if err != nil { return "", err } diff --git a/apis/fluentbit/v1alpha2/clusterparser_types.go b/apis/fluentbit/v1alpha2/clusterparser_types.go index ef4e9c590..3b4d22731 100644 --- a/apis/fluentbit/v1alpha2/clusterparser_types.go +++ b/apis/fluentbit/v1alpha2/clusterparser_types.go @@ -88,12 +88,14 @@ func (a ParserByName) Len() int { return len(a) } func (a ParserByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a ParserByName) Less(i, j int) bool { return a[i].Name < a[j].Name } -func (list ClusterParserList) Load(sl plugins.SecretLoader) (string, error) { +func (list ClusterParserList) Load(sl plugins.SecretLoader, existingParsers map[string]bool) (string, error) { var buf bytes.Buffer sort.Sort(ParserByName(list.Items)) - for _, item := range list.Items { + if existingParsers[item.Name] { + continue + } merge := func(p plugins.Plugin) error { if p == nil || reflect.ValueOf(p).IsNil() { return nil @@ -117,6 +119,7 @@ func (list ClusterParserList) Load(sl plugins.SecretLoader) (string, error) { buf.WriteString(fmt.Sprintf(" Decode_Field_As %s\n", decorder.DecodeFieldAs)) } } + existingParsers[item.Name] = true return nil }