Skip to content

Commit e76387b

Browse files
committedSep 14, 2023
feat: add trigger into template vars
1 parent e80a8e9 commit e76387b

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed
 

‎pkg/controller/controller.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,10 @@ func (c *notificationController) processResourceWithAPI(api api.API, resource v1
197197
}
198198

199199
for trigger, destinations := range destinations {
200-
res, err := api.RunTrigger(trigger, un.Object)
200+
vars := un.Object
201+
vars["trigger"] = trigger
202+
203+
res, err := api.RunTrigger(trigger, vars)
201204
if err != nil {
202205
logEntry.Debugf("Failed to execute condition of trigger %s: %v using the configuration in namespace %s", trigger, err, apiNamespace)
203206
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
224227
})
225228
} else {
226229
logEntry.Infof("Sending notification about condition '%s.%s' to '%v' using the configuration in namespace %s", trigger, cr.Key, to, apiNamespace)
227-
if err := api.Send(un.Object, cr.Templates, to); err != nil {
230+
if err := api.Send(vars, cr.Templates, to); err != nil {
228231
logEntry.Errorf("Failed to notify recipient %s defined in resource %s/%s: %v using the configuration in namespace %s",
229232
to, resource.GetNamespace(), resource.GetName(), err, apiNamespace)
230233
notificationsState.SetAlreadyNotified(trigger, cr, to, false)

‎pkg/controller/controller_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,10 @@ func TestWithEventCallback(t *testing.T) {
336336

337337
ctrl.processQueueItem()
338338

339+
if tc.apiErr == nil {
340+
app.Object["trigger"] = "my-trigger"
341+
}
342+
339343
assert.Equal(t, app, actualSequence.Resource)
340344

341345
assert.Equal(t, len(tc.expectedDeliveries), len(actualSequence.Delivered))

0 commit comments

Comments
 (0)
Please sign in to comment.