Skip to content

Commit

Permalink
fix: fixed includeLabelInRouter logic
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Gvizd <[email protected]>
  • Loading branch information
gvizdpeter committed Apr 15, 2023
1 parent b440e7e commit d6adc62
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/sdk/logging/model/types/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *SystemBuilder) RegisterFlow(f *Flow) error {
}
}
s.flows = append(s.flows, f)
if f.FlowLabel == "" || (f.IncludeLabelInRouter != nil && *f.IncludeLabelInRouter) {
if f.IncludeLabelInRouter {
s.router.AddRoute(f)
}
return nil
Expand Down
12 changes: 10 additions & 2 deletions pkg/sdk/logging/model/types/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type Flow struct {
FlowLabel string `json:"-"`

// Flag whether to include flow in label_router
IncludeLabelInRouter *bool
IncludeLabelInRouter bool
}

func (f *Flow) GetPluginMeta() *PluginMeta {
Expand Down Expand Up @@ -108,12 +108,20 @@ func (f *Flow) WithOutputs(output ...Output) *Flow {
}

func NewFlow(matches []FlowMatch, id, name, namespace, flowLabel string, includeLabelInRouter *bool) (*Flow, error) {
var tmpIncludeLabelInRouter bool = true
if flowLabel == "" {
var err error
flowLabel, err = calculateFlowLabel(matches, name, namespace)
if err != nil {
return nil, err
}
if includeLabelInRouter != nil && !*includeLabelInRouter {
tmpIncludeLabelInRouter = false
}
} else {
if includeLabelInRouter != nil && *includeLabelInRouter {
tmpIncludeLabelInRouter = true
}
}
return &Flow{
PluginMeta: PluginMeta{
Expand All @@ -123,7 +131,7 @@ func NewFlow(matches []FlowMatch, id, name, namespace, flowLabel string, include
FlowID: id,
FlowLabel: flowLabel,
Matches: matches,
IncludeLabelInRouter: includeLabelInRouter,
IncludeLabelInRouter: tmpIncludeLabelInRouter,
}, nil
}

Expand Down

0 comments on commit d6adc62

Please sign in to comment.