Skip to content

Commit

Permalink
Fix panic when spec.fluentd is omitted from Logging manifest (#872)
Browse files Browse the repository at this point in the history
* Fix panic when spec.fluentd is omitted from Logging manifest

Signed-off-by: Rich Lander <lander2k2@protonmail.com>

* Use fluentd values for fluent-bit target host, port only when fluentd in use

Signed-off-by: Rich Lander <lander2k2@protonmail.com>

Co-authored-by: Ferenc HERNADI <ferenc.hernadi@gmail.com>
  • Loading branch information
lander2k2 and ahma authored Nov 26, 2021
1 parent abb834e commit 76b7d17
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 25 deletions.
18 changes: 16 additions & 2 deletions pkg/resources/fluentbit/configsecret.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
46 changes: 23 additions & 23 deletions pkg/sdk/api/v1beta1/logging_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 76b7d17

Please sign in to comment.