diff --git a/apis/fluentbit/v1alpha2/clusteroutput_types_test.go b/apis/fluentbit/v1alpha2/clusteroutput_types_test.go index 55cf874e3..65e8071b9 100644 --- a/apis/fluentbit/v1alpha2/clusteroutput_types_test.go +++ b/apis/fluentbit/v1alpha2/clusteroutput_types_test.go @@ -523,3 +523,52 @@ func TestLokiOutputWithStructuredMetadata_LoadAsYaml(t *testing.T) { g.Expect(err).NotTo(HaveOccurred()) g.Expect(result).To(Equal(expected)) } + +func TestForwardOutput_RetainMetadataInForwardMode(t *testing.T) { + g := NewGomegaWithT(t) + sl := plugins.NewSecretLoader(nil, "testnamespace") + + // nil: field should be omitted + nilOut := ClusterOutputList{Items: []ClusterOutput{{ + ObjectMeta: metav1.ObjectMeta{Name: "fwd-nil"}, + Spec: OutputSpec{ + Match: "kube.*", + Forward: &output.Forward{Host: "fluentd.svc", Port: utils.ToPtr[int32](24224)}, + }, + }}} + resultNil, err := nilOut.Load(sl) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(resultNil).NotTo(ContainSubstring("Retain_Metadata_In_Forward_Mode")) + + // false: field should be rendered as false + falseOut := ClusterOutputList{Items: []ClusterOutput{{ + ObjectMeta: metav1.ObjectMeta{Name: "fwd-false"}, + Spec: OutputSpec{ + Match: "kube.*", + Forward: &output.Forward{ + Host: "fluentd.svc", + Port: utils.ToPtr[int32](24224), + RetainMetadataInForwardMode: utils.ToPtr(false), + }, + }, + }}} + resultFalse, err := falseOut.Load(sl) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(resultFalse).To(ContainSubstring("Retain_Metadata_In_Forward_Mode false")) + + // true: field should be rendered as true + trueOut := ClusterOutputList{Items: []ClusterOutput{{ + ObjectMeta: metav1.ObjectMeta{Name: "fwd-true"}, + Spec: OutputSpec{ + Match: "kube.*", + Forward: &output.Forward{ + Host: "fluentd.svc", + Port: utils.ToPtr[int32](24224), + RetainMetadataInForwardMode: utils.ToPtr(true), + }, + }, + }}} + resultTrue, err := trueOut.Load(sl) + g.Expect(err).NotTo(HaveOccurred()) + g.Expect(resultTrue).To(ContainSubstring("Retain_Metadata_In_Forward_Mode true")) +} diff --git a/apis/fluentbit/v1alpha2/plugins/output/forward_types.go b/apis/fluentbit/v1alpha2/plugins/output/forward_types.go index f4bf27460..53810f31d 100644 --- a/apis/fluentbit/v1alpha2/plugins/output/forward_types.go +++ b/apis/fluentbit/v1alpha2/plugins/output/forward_types.go @@ -38,7 +38,9 @@ type Forward struct { Password *plugins.Secret `json:"password,omitempty"` // Default value of the auto-generated certificate common name (CN). SelfHostname string `json:"selfHostname,omitempty"` - *plugins.TLS `json:"tls,omitempty"` + // Retain metadata when forwarding in forward mode. + RetainMetadataInForwardMode *bool `json:"retainMetadataInForwardMode,omitempty"` + *plugins.TLS `json:"tls,omitempty"` // Include fluentbit networking options for this output-plugin *plugins.Networking `json:"networking,omitempty"` } @@ -82,6 +84,7 @@ func (f *Forward) Params(sl plugins.SecretLoader) (*params.KVs, error) { plugins.InsertKVField(kvs, "Time_as_Integer", f.TimeAsInteger) plugins.InsertKVField(kvs, "Send_options", f.SendOptions) plugins.InsertKVField(kvs, "Require_ack_response", f.RequireAckResponse) + plugins.InsertKVField(kvs, "Retain_Metadata_In_Forward_Mode", f.RetainMetadataInForwardMode) return kvs, nil } diff --git a/apis/fluentbit/v1alpha2/plugins/output/zz_generated.deepcopy.go b/apis/fluentbit/v1alpha2/plugins/output/zz_generated.deepcopy.go index 44b27d0c6..1ee7a0927 100644 --- a/apis/fluentbit/v1alpha2/plugins/output/zz_generated.deepcopy.go +++ b/apis/fluentbit/v1alpha2/plugins/output/zz_generated.deepcopy.go @@ -347,6 +347,11 @@ func (in *Forward) DeepCopyInto(out *Forward) { *out = new(plugins.Secret) (*in).DeepCopyInto(*out) } + if in.RetainMetadataInForwardMode != nil { + in, out := &in.RetainMetadataInForwardMode, &out.RetainMetadataInForwardMode + *out = new(bool) + **out = **in + } if in.TLS != nil { in, out := &in.TLS, &out.TLS *out = new(plugins.TLS) diff --git a/charts/fluent-operator-fluent-bit-crds/templates/fluentbit.fluent.io_clusteroutputs.yaml b/charts/fluent-operator-fluent-bit-crds/templates/fluentbit.fluent.io_clusteroutputs.yaml index 12e1a37b3..38d97e179 100644 --- a/charts/fluent-operator-fluent-bit-crds/templates/fluentbit.fluent.io_clusteroutputs.yaml +++ b/charts/fluent-operator-fluent-bit-crds/templates/fluentbit.fluent.io_clusteroutputs.yaml @@ -1156,6 +1156,9 @@ spec: Enables at-least-once and receiving server can control rate of traffic. (Requires Fluentd v0.14.0+ server) type: boolean + retainMetadataInForwardMode: + description: Retain metadata when forwarding in forward mode. + type: boolean selfHostname: description: Default value of the auto-generated certificate common name (CN). diff --git a/charts/fluent-operator-fluent-bit-crds/templates/fluentbit.fluent.io_outputs.yaml b/charts/fluent-operator-fluent-bit-crds/templates/fluentbit.fluent.io_outputs.yaml index 1fbd2f371..db90f6cd7 100644 --- a/charts/fluent-operator-fluent-bit-crds/templates/fluentbit.fluent.io_outputs.yaml +++ b/charts/fluent-operator-fluent-bit-crds/templates/fluentbit.fluent.io_outputs.yaml @@ -1156,6 +1156,9 @@ spec: Enables at-least-once and receiving server can control rate of traffic. (Requires Fluentd v0.14.0+ server) type: boolean + retainMetadataInForwardMode: + description: Retain metadata when forwarding in forward mode. + type: boolean selfHostname: description: Default value of the auto-generated certificate common name (CN). diff --git a/charts/fluent-operator/crds/fluentbit.fluent.io_clusteroutputs.yaml b/charts/fluent-operator/crds/fluentbit.fluent.io_clusteroutputs.yaml index 59ec0e09a..bc82bb19b 100644 --- a/charts/fluent-operator/crds/fluentbit.fluent.io_clusteroutputs.yaml +++ b/charts/fluent-operator/crds/fluentbit.fluent.io_clusteroutputs.yaml @@ -1154,6 +1154,9 @@ spec: Enables at-least-once and receiving server can control rate of traffic. (Requires Fluentd v0.14.0+ server) type: boolean + retainMetadataInForwardMode: + description: Retain metadata when forwarding in forward mode. + type: boolean selfHostname: description: Default value of the auto-generated certificate common name (CN). diff --git a/charts/fluent-operator/crds/fluentbit.fluent.io_outputs.yaml b/charts/fluent-operator/crds/fluentbit.fluent.io_outputs.yaml index b8165b62d..01d1256f6 100644 --- a/charts/fluent-operator/crds/fluentbit.fluent.io_outputs.yaml +++ b/charts/fluent-operator/crds/fluentbit.fluent.io_outputs.yaml @@ -1154,6 +1154,9 @@ spec: Enables at-least-once and receiving server can control rate of traffic. (Requires Fluentd v0.14.0+ server) type: boolean + retainMetadataInForwardMode: + description: Retain metadata when forwarding in forward mode. + type: boolean selfHostname: description: Default value of the auto-generated certificate common name (CN). diff --git a/charts/fluent-operator/templates/fluentbit-output-forward.yaml b/charts/fluent-operator/templates/fluentbit-output-forward.yaml index bb18610c6..c0e209a5d 100644 --- a/charts/fluent-operator/templates/fluentbit-output-forward.yaml +++ b/charts/fluent-operator/templates/fluentbit-output-forward.yaml @@ -13,6 +13,9 @@ spec: forward: host: {{ printf "%s.%s.svc.cluster.local" .Values.fluentd.name .Release.Namespace | quote }} port: {{ .Values.fluentd.forward.port }} + {{- if not (kindIs "invalid" .Values.fluentd.forward.retainMetadataInForwardMode) }} + retainMetadataInForwardMode: {{ .Values.fluentd.forward.retainMetadataInForwardMode }} + {{- end }} {{- end }} {{- end }} {{- end }} diff --git a/charts/fluent-operator/values.yaml b/charts/fluent-operator/values.yaml index 30fa0837e..4ccbcd1f6 100644 --- a/charts/fluent-operator/values.yaml +++ b/charts/fluent-operator/values.yaml @@ -627,6 +627,9 @@ fluentd: forward: # -- Forward input port port: 24224 + # -- Retain metadata when forwarding in forward mode. + # Set to false for Fluentd compatibility with Fluent Bit v5.0.5+. + retainMetadataInForwardMode: ~ # -- Namespaces to watch for Fluentd resources watchedNamespaces: - kube-system diff --git a/config/crd/bases/fluentbit.fluent.io_clusteroutputs.yaml b/config/crd/bases/fluentbit.fluent.io_clusteroutputs.yaml index 1e0b0d206..789619883 100644 --- a/config/crd/bases/fluentbit.fluent.io_clusteroutputs.yaml +++ b/config/crd/bases/fluentbit.fluent.io_clusteroutputs.yaml @@ -1155,6 +1155,9 @@ spec: Enables at-least-once and receiving server can control rate of traffic. (Requires Fluentd v0.14.0+ server) type: boolean + retainMetadataInForwardMode: + description: Retain metadata when forwarding in forward mode. + type: boolean selfHostname: description: Default value of the auto-generated certificate common name (CN). diff --git a/config/crd/bases/fluentbit.fluent.io_outputs.yaml b/config/crd/bases/fluentbit.fluent.io_outputs.yaml index 8a6704564..b9e3f8d26 100644 --- a/config/crd/bases/fluentbit.fluent.io_outputs.yaml +++ b/config/crd/bases/fluentbit.fluent.io_outputs.yaml @@ -1155,6 +1155,9 @@ spec: Enables at-least-once and receiving server can control rate of traffic. (Requires Fluentd v0.14.0+ server) type: boolean + retainMetadataInForwardMode: + description: Retain metadata when forwarding in forward mode. + type: boolean selfHostname: description: Default value of the auto-generated certificate common name (CN). diff --git a/docs/plugins/fluentbit/output/forward.md b/docs/plugins/fluentbit/output/forward.md index f58e0d095..06e8edea0 100644 --- a/docs/plugins/fluentbit/output/forward.md +++ b/docs/plugins/fluentbit/output/forward.md @@ -16,5 +16,6 @@ Forward is the protocol used by Fluentd to route messages between peers.
| username | Specify the username to present to a Fluentd server that enables user_auth. | *[plugins.Secret](../secret.md) | | password | Specify the password corresponding to the username. | *[plugins.Secret](../secret.md) | | selfHostname | Default value of the auto-generated certificate common name (CN). | string | +| retainMetadataInForwardMode | Retain metadata when forwarding in forward mode. | *bool | | tls | | *[plugins.TLS](../tls.md) | | networking | Include fluentbit networking options for this output-plugin | *plugins.Networking | diff --git a/manifests/setup/setup.yaml b/manifests/setup/setup.yaml index 8df9b86f6..95092b43f 100644 --- a/manifests/setup/setup.yaml +++ b/manifests/setup/setup.yaml @@ -5355,6 +5355,9 @@ spec: Enables at-least-once and receiving server can control rate of traffic. (Requires Fluentd v0.14.0+ server) type: boolean + retainMetadataInForwardMode: + description: Retain metadata when forwarding in forward mode. + type: boolean selfHostname: description: Default value of the auto-generated certificate common name (CN). @@ -35442,6 +35445,9 @@ spec: Enables at-least-once and receiving server can control rate of traffic. (Requires Fluentd v0.14.0+ server) type: boolean + retainMetadataInForwardMode: + description: Retain metadata when forwarding in forward mode. + type: boolean selfHostname: description: Default value of the auto-generated certificate common name (CN).