From e76387b1f327ed41cb459cd381ede47acc06e720 Mon Sep 17 00:00:00 2001 From: ebuildy Date: Thu, 14 Sep 2023 14:32:33 -0400 Subject: [PATCH] feat: add trigger into template vars --- pkg/controller/controller.go | 7 +++++-- pkg/controller/controller_test.go | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index a492526f..c2838f6f 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -197,7 +197,10 @@ func (c *notificationController) processResourceWithAPI(api api.API, resource v1 } for trigger, destinations := range destinations { - res, err := api.RunTrigger(trigger, un.Object) + vars := un.Object + vars["trigger"] = trigger + + res, err := api.RunTrigger(trigger, vars) if err != nil { logEntry.Debugf("Failed to execute condition of trigger %s: %v using the configuration in namespace %s", trigger, err, apiNamespace) eventSequence.addWarning(fmt.Errorf("failed to execute condition of trigger %s: %v using the configuration in namespace %s", trigger, err, apiNamespace)) @@ -224,7 +227,7 @@ func (c *notificationController) processResourceWithAPI(api api.API, resource v1 }) } else { logEntry.Infof("Sending notification about condition '%s.%s' to '%v' using the configuration in namespace %s", trigger, cr.Key, to, apiNamespace) - if err := api.Send(un.Object, cr.Templates, to); err != nil { + if err := api.Send(vars, cr.Templates, to); err != nil { logEntry.Errorf("Failed to notify recipient %s defined in resource %s/%s: %v using the configuration in namespace %s", to, resource.GetNamespace(), resource.GetName(), err, apiNamespace) notificationsState.SetAlreadyNotified(trigger, cr, to, false) diff --git a/pkg/controller/controller_test.go b/pkg/controller/controller_test.go index 2f76a1c8..4f993e65 100644 --- a/pkg/controller/controller_test.go +++ b/pkg/controller/controller_test.go @@ -336,6 +336,10 @@ func TestWithEventCallback(t *testing.T) { ctrl.processQueueItem() + if tc.apiErr == nil { + app.Object["trigger"] = "my-trigger" + } + assert.Equal(t, app, actualSequence.Resource) assert.Equal(t, len(tc.expectedDeliveries), len(actualSequence.Delivered))