From 3b97deb63d08b2327eca903d86b5e227a0a314ef Mon Sep 17 00:00:00 2001 From: Timur Zununbekov Date: Wed, 15 Feb 2023 11:47:56 +0600 Subject: [PATCH] Handle nil filters in triggers (#252) * Handle nil filters in triggers --- docs/tmctl_create_broker.md | 2 +- pkg/triggermesh/components/components.go | 24 ++++++++++-------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/docs/tmctl_create_broker.md b/docs/tmctl_create_broker.md index 57be9e12..aa008ab3 100644 --- a/docs/tmctl_create_broker.md +++ b/docs/tmctl_create_broker.md @@ -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 diff --git a/pkg/triggermesh/components/components.go b/pkg/triggermesh/components/components.go index 40a996c5..1689eea0 100644 --- a/pkg/triggermesh/components/components.go +++ b/pkg/triggermesh/components/components.go @@ -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 }