Skip to content
This repository was archived by the owner on Oct 19, 2024. It is now read-only.

Commit 356bb04

Browse files
author
Alexander Matyushentsev
authored
refactor: upgrade notifications-engine and switch to WithAlterDestinations (#278)
Signed-off-by: Alexander Matyushentsev <[email protected]>
1 parent 2099c72 commit 356bb04

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

controller/controller.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,21 @@ func NewController(
6363
return !isAppSyncStatusRefreshed(app, log.WithField("app", obj.GetName())), "sync status out of date"
6464
}),
6565
controller.WithMetricsRegistry(registry),
66-
controller.WithAdditionalDestinations(res.getAdditionalDestinations))
66+
controller.WithAlterDestinations(res.alterDestinations))
6767
return res
6868
}
6969

70-
func (c *notificationController) getAdditionalDestinations(obj v1.Object, cfg api.Config) services.Destinations {
71-
res := services.Destinations{}
72-
70+
func (c *notificationController) alterDestinations(obj v1.Object, destinations services.Destinations, cfg api.Config) services.Destinations {
7371
app, ok := (obj).(*unstructured.Unstructured)
7472
if !ok {
75-
return res
73+
return destinations
7674
}
7775

7876
if proj := getAppProj(app, c.appProjInformer); proj != nil {
79-
res.Merge(subscriptions.Annotations(proj.GetAnnotations()).GetDestinations(cfg.DefaultTriggers, cfg.ServiceDefaultTriggers))
80-
res.Merge(settings.GetLegacyDestinations(proj.GetAnnotations(), cfg.DefaultTriggers, cfg.ServiceDefaultTriggers))
77+
destinations.Merge(subscriptions.Annotations(proj.GetAnnotations()).GetDestinations(cfg.DefaultTriggers, cfg.ServiceDefaultTriggers))
78+
destinations.Merge(settings.GetLegacyDestinations(proj.GetAnnotations(), cfg.DefaultTriggers, cfg.ServiceDefaultTriggers))
8179
}
82-
return res
80+
return destinations
8381
}
8482

8583
func newInformer(resClient dynamic.ResourceInterface, selector string) cache.SharedIndexInformer {

controller/controller_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"context"
55
"testing"
66

7+
"github.com/argoproj/notifications-engine/pkg/services"
8+
79
. "github.com/argoproj-labs/argocd-notifications/testing"
810

911
"github.com/argoproj/notifications-engine/pkg/api"
@@ -51,7 +53,7 @@ func TestSendsNotificationIfProjectTriggered(t *testing.T) {
5153
ctrl, _, err := newController(t, ctx, NewFakeClient(app, appProj))
5254
assert.NoError(t, err)
5355

54-
dests := ctrl.getAdditionalDestinations(app, api.Config{})
56+
dests := ctrl.alterDestinations(app, services.Destinations{}, api.Config{})
5557

5658
assert.NoError(t, err)
5759
assert.NotEmpty(t, dests)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.16
44

55
require (
66
github.com/argoproj/argo-cd/v2 v2.0.0-rc3
7-
github.com/argoproj/notifications-engine v0.1.1-0.20210503221649-02b903bd1840
7+
github.com/argoproj/notifications-engine v0.1.1-0.20210504060655-93bff0a78a1e
88
github.com/evanphx/json-patch v4.9.0+incompatible
99
github.com/ghodss/yaml v1.0.0
1010
github.com/golang/mock v1.4.4

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ github.com/argoproj/argo-cd/v2 v2.0.0-rc3 h1:jBuz8qqLL0gG6Nb892x3+eP+v/wjQpkdSOl
9393
github.com/argoproj/argo-cd/v2 v2.0.0-rc3/go.mod h1:Rw7fuyae0v8b3KMJoZp8jf5A2tBP2dQ8uWj9HTRZITo=
9494
github.com/argoproj/gitops-engine v0.3.1 h1:wM4RUzH54sWdchD7Ws8UdAIsjk08BmjN9bLuW79xKWk=
9595
github.com/argoproj/gitops-engine v0.3.1/go.mod h1:IBHhAkqlC+3r/wBWUitWSidQhPzlLoSTWp2htq3dyQk=
96-
github.com/argoproj/notifications-engine v0.1.1-0.20210503221649-02b903bd1840 h1:eZ6eZ2e9K1YH5mbwneHcP6CFPHWaQ7vv86BBatgIybs=
97-
github.com/argoproj/notifications-engine v0.1.1-0.20210503221649-02b903bd1840/go.mod h1:rKhm9LtebGKgLA/UtPtBeRUrrS/CT0U5az1jSfUiipw=
96+
github.com/argoproj/notifications-engine v0.1.1-0.20210504060655-93bff0a78a1e h1:48/K05DfH4Et57sg3XVyuxeG2EHumn67AtAa+0l3/Zo=
97+
github.com/argoproj/notifications-engine v0.1.1-0.20210504060655-93bff0a78a1e/go.mod h1:rKhm9LtebGKgLA/UtPtBeRUrrS/CT0U5az1jSfUiipw=
9898
github.com/argoproj/pkg v0.2.0 h1:ETgC600kr8WcAi3MEVY5sA1H7H/u1/IysYOobwsZ8No=
9999
github.com/argoproj/pkg v0.2.0/go.mod h1:F4TZgInLUEjzsWFB/BTJBsewoEy0ucnKSq6vmQiD/yc=
100100
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=

0 commit comments

Comments
 (0)