From 4d00ba3fa8b376dfed7620a5ba8dfaa118ebeecf Mon Sep 17 00:00:00 2001 From: Markus Freitag Date: Mon, 22 Apr 2024 12:00:28 +0200 Subject: [PATCH] let RewriteTag filter fullfill namespaceable interface Signed-off-by: Markus Freitag --- .../v1alpha2/plugins/filter/rewritetag_types.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/apis/fluentbit/v1alpha2/plugins/filter/rewritetag_types.go b/apis/fluentbit/v1alpha2/plugins/filter/rewritetag_types.go index fd724316d..2bd8154bd 100644 --- a/apis/fluentbit/v1alpha2/plugins/filter/rewritetag_types.go +++ b/apis/fluentbit/v1alpha2/plugins/filter/rewritetag_types.go @@ -1,6 +1,10 @@ package filter import ( + "crypto/md5" + "fmt" + "strings" + "github.com/fluent/fluent-operator/v2/apis/fluentbit/v1alpha2/plugins" "github.com/fluent/fluent-operator/v2/apis/fluentbit/v1alpha2/plugins/params" ) @@ -18,7 +22,7 @@ type RewriteTag struct { // When the filter emits a record under the new Tag, there is an internal emitter // plugin that takes care of the job. Since this emitter expose metrics as any other // component of the pipeline, you can use this property to configure an optional name for it. - EmitterName string `json:"emitterName,omitempty"` + EmitterName string `json:"emitterName,omitempty"` EmitterMemBufLimit string `json:"emitterMemBufLimit,omitempty"` EmitterStorageType string `json:"emitterStorageType,omitempty"` } @@ -47,3 +51,11 @@ func (r *RewriteTag) Params(_ plugins.SecretLoader) (*params.KVs, error) { } return kvs, nil } + +func (r *RewriteTag) MakeNamespaced(ns string) { + for idx, rule := range r.Rules { + parts := strings.Fields(rule) + parts[2] = fmt.Sprintf("%x.%s", md5.Sum([]byte(ns)), parts[2]) + r.Rules[idx] = strings.Join(parts, " ") + } +}