From 76b7d17117a9c38b15e9082ecb5a66ff085d6b7f Mon Sep 17 00:00:00 2001 From: Richard Lander Date: Fri, 26 Nov 2021 08:06:50 -0500 Subject: [PATCH] Fix panic when spec.fluentd is omitted from Logging manifest (#872) * Fix panic when spec.fluentd is omitted from Logging manifest Signed-off-by: Rich Lander * Use fluentd values for fluent-bit target host, port only when fluentd in use Signed-off-by: Rich Lander Co-authored-by: Ferenc HERNADI --- pkg/resources/fluentbit/configsecret.go | 18 ++++++++-- pkg/sdk/api/v1beta1/logging_types.go | 46 ++++++++++++------------- 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/pkg/resources/fluentbit/configsecret.go b/pkg/resources/fluentbit/configsecret.go index 6a63bbeca..951c4a48e 100644 --- a/pkg/resources/fluentbit/configsecret.go +++ b/pkg/resources/fluentbit/configsecret.go @@ -115,6 +115,20 @@ func (r *Reconciler) configSecret() (runtime.Object, reconciler.DesiredState, er } } + var fluentbitTargetHost string + if r.Logging.Spec.FluentdSpec != nil && r.Logging.Spec.FluentbitSpec.TargetHost == "" { + fluentbitTargetHost = fmt.Sprintf("%s.%s.svc", r.Logging.QualifiedName(fluentd.ServiceName), r.Logging.Spec.ControlNamespace) + } else { + fluentbitTargetHost = r.Logging.Spec.FluentbitSpec.TargetHost + } + + var fluentbitTargetPort int32 + if r.Logging.Spec.FluentdSpec != nil && r.Logging.Spec.FluentbitSpec.TargetPort == 0 { + fluentbitTargetPort = r.Logging.Spec.FluentdSpec.Port + } else { + fluentbitTargetPort = r.Logging.Spec.FluentbitSpec.TargetPort + } + mapper := types.NewStructToStringMapper(nil) // FluentBit input Values @@ -169,8 +183,8 @@ func (r *Reconciler) configSecret() (runtime.Object, reconciler.DesiredState, er SharedKey: r.Logging.Spec.FluentbitSpec.TLS.SharedKey, }, Monitor: monitor, - TargetHost: fmt.Sprintf("%s.%s.svc", r.Logging.QualifiedName(fluentd.ServiceName), r.Logging.Spec.ControlNamespace), - TargetPort: r.Logging.Spec.FluentdSpec.Port, + TargetHost: fluentbitTargetHost, + TargetPort: fluentbitTargetPort, Input: fluentbitInput, DisableKubernetesFilter: disableKubernetesFilter, KubernetesFilter: fluentbitKubernetesFilter, diff --git a/pkg/sdk/api/v1beta1/logging_types.go b/pkg/sdk/api/v1beta1/logging_types.go index 5efce8b55..10b8df0ba 100644 --- a/pkg/sdk/api/v1beta1/logging_types.go +++ b/pkg/sdk/api/v1beta1/logging_types.go @@ -302,32 +302,32 @@ func (l *Logging) SetDefaults() error { } } } - } - if l.Spec.FluentdSpec.ReadinessDefaultCheck.BufferFreeSpace { - if l.Spec.FluentdSpec.ReadinessDefaultCheck.BufferFreeSpaceThreshold == 0 { - l.Spec.FluentdSpec.ReadinessDefaultCheck.BufferFreeSpaceThreshold = 90 + if l.Spec.FluentdSpec.ReadinessDefaultCheck.BufferFreeSpace { + if l.Spec.FluentdSpec.ReadinessDefaultCheck.BufferFreeSpaceThreshold == 0 { + l.Spec.FluentdSpec.ReadinessDefaultCheck.BufferFreeSpaceThreshold = 90 + } } - } - if l.Spec.FluentdSpec.ReadinessDefaultCheck.BufferFileNumber { - if l.Spec.FluentdSpec.ReadinessDefaultCheck.BufferFileNumberMax == 0 { - l.Spec.FluentdSpec.ReadinessDefaultCheck.BufferFileNumberMax = 5000 + if l.Spec.FluentdSpec.ReadinessDefaultCheck.BufferFileNumber { + if l.Spec.FluentdSpec.ReadinessDefaultCheck.BufferFileNumberMax == 0 { + l.Spec.FluentdSpec.ReadinessDefaultCheck.BufferFileNumberMax = 5000 + } + } + if l.Spec.FluentdSpec.ReadinessDefaultCheck.InitialDelaySeconds == 0 { + l.Spec.FluentdSpec.ReadinessDefaultCheck.InitialDelaySeconds = 5 + } + if l.Spec.FluentdSpec.ReadinessDefaultCheck.TimeoutSeconds == 0 { + l.Spec.FluentdSpec.ReadinessDefaultCheck.TimeoutSeconds = 3 + } + if l.Spec.FluentdSpec.ReadinessDefaultCheck.PeriodSeconds == 0 { + l.Spec.FluentdSpec.ReadinessDefaultCheck.PeriodSeconds = 30 + } + if l.Spec.FluentdSpec.ReadinessDefaultCheck.SuccessThreshold == 0 { + l.Spec.FluentdSpec.ReadinessDefaultCheck.SuccessThreshold = 3 + } + if l.Spec.FluentdSpec.ReadinessDefaultCheck.FailureThreshold == 0 { + l.Spec.FluentdSpec.ReadinessDefaultCheck.FailureThreshold = 1 } - } - if l.Spec.FluentdSpec.ReadinessDefaultCheck.InitialDelaySeconds == 0 { - l.Spec.FluentdSpec.ReadinessDefaultCheck.InitialDelaySeconds = 5 - } - if l.Spec.FluentdSpec.ReadinessDefaultCheck.TimeoutSeconds == 0 { - l.Spec.FluentdSpec.ReadinessDefaultCheck.TimeoutSeconds = 3 - } - if l.Spec.FluentdSpec.ReadinessDefaultCheck.PeriodSeconds == 0 { - l.Spec.FluentdSpec.ReadinessDefaultCheck.PeriodSeconds = 30 - } - if l.Spec.FluentdSpec.ReadinessDefaultCheck.SuccessThreshold == 0 { - l.Spec.FluentdSpec.ReadinessDefaultCheck.SuccessThreshold = 3 - } - if l.Spec.FluentdSpec.ReadinessDefaultCheck.FailureThreshold == 0 { - l.Spec.FluentdSpec.ReadinessDefaultCheck.FailureThreshold = 1 } if l.Spec.FluentbitSpec != nil { // nolint:nestif