Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Commit

Permalink
Handle nil filters in triggers (#252)
Browse files Browse the repository at this point in the history
* Handle nil filters in triggers
  • Loading branch information
tzununbekov authored Feb 15, 2023
1 parent b518c2f commit 3b97deb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/tmctl_create_broker.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tmctl create broker foo

```
-h, --help help for broker
--version string TriggerMesh broker version. (default "v1.1.0")
--version string TriggerMesh broker version. (default "v1.1.1")
```

### SEE ALSO
Expand Down
24 changes: 10 additions & 14 deletions pkg/triggermesh/components/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,24 +163,20 @@ func decodeSecrets(secrets []triggermesh.Component) (map[string]string, error) {
}

func parseTriggerSpec(spec map[string]interface{}) (string, *eventingbroker.Filter, error) {
filter, err := yaml.Marshal(spec["filters"])
triggerSpec, err := yaml.Marshal(spec)
if err != nil {
return "", nil, err
}
var f []eventingbroker.Filter
if err := yaml.Unmarshal(filter, &f); err != nil {
t := struct {
Filters []eventingbroker.Filter `yaml:"filters,omitempty"`
Target duckv1.Destination `yaml:"target"`
}{}
if err := yaml.Unmarshal(triggerSpec, &t); err != nil {
return "", nil, err
}
if l := len(f); l != 1 {
return "", nil, fmt.Errorf("expected 1 filter condition, got %d", l)
var filter *eventingbroker.Filter
if len(t.Filters) == 1 {
filter = &t.Filters[0]
}
target, err := yaml.Marshal(spec["target"])
if err != nil {
return "", nil, err
}
var t duckv1.Destination
if err := yaml.Unmarshal(target, &t); err != nil {
return "", nil, err
}
return t.Ref.Name, &f[0], nil
return t.Target.Ref.Name, filter, nil
}

0 comments on commit 3b97deb

Please sign in to comment.