Skip to content

Commit

Permalink
Add nil-check for loki.enable (#385)
Browse files Browse the repository at this point in the history
* Add nil-check for loki.enable

* Loki/console enable nil must be seen as true
  • Loading branch information
jotak committed Jun 29, 2023
1 parent e2d77a1 commit 57a6951
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion controllers/flowlogspipeline/flp_common_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ func (b *builder) addTransformStages(stage *config.PipelineBuilderStage) (*corev
})

// loki stage (write) configuration
if *b.desired.Loki.Enable {
if helper.UseLoki(b.desired) {
lokiWrite := api.WriteLoki{
Labels: indexFields,
BatchSize: int(b.desired.Loki.BatchSize),
Expand Down
9 changes: 8 additions & 1 deletion pkg/helper/flowcollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,15 @@ func UseSASL(cfg *flowslatest.SASLConfig) bool {
return cfg.Type == flowslatest.SASLPlain || cfg.Type == flowslatest.SASLScramSHA512
}

func UseLoki(spec *flowslatest.FlowCollectorSpec) bool {
// nil should fallback to default value, which is "true"
return spec.Loki.Enable == nil || *spec.Loki.Enable
}

func UseConsolePlugin(spec *flowslatest.FlowCollectorSpec) bool {
return PtrBool(spec.Loki.Enable) && PtrBool(spec.ConsolePlugin.Enable)
return UseLoki(spec) &&
// nil should fallback to default value, which is "true"
(spec.ConsolePlugin.Enable == nil || *spec.ConsolePlugin.Enable)
}

func PtrBool(b *bool) bool {
Expand Down

0 comments on commit 57a6951

Please sign in to comment.