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

Commit 2099c72

Browse files
author
Alexander Matyushentsev
authored
refactor: upgrade notifications-engine version (#277)
Signed-off-by: Alexander Matyushentsev <[email protected]>
1 parent b2994cc commit 2099c72

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

controller/controller.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import (
77
"time"
88

99
"github.com/argoproj-labs/argocd-notifications/shared/argocd"
10-
"k8s.io/client-go/kubernetes"
11-
1210
"github.com/argoproj-labs/argocd-notifications/shared/k8s"
1311
"github.com/argoproj-labs/argocd-notifications/shared/settings"
1412

@@ -22,6 +20,7 @@ import (
2220
"k8s.io/apimachinery/pkg/runtime"
2321
"k8s.io/apimachinery/pkg/watch"
2422
"k8s.io/client-go/dynamic"
23+
"k8s.io/client-go/kubernetes"
2524
"k8s.io/client-go/tools/cache"
2625
)
2726

@@ -42,7 +41,7 @@ func NewController(
4241
appLabelSelector string,
4342
registry *controller.MetricsRegistry,
4443
) *notificationController {
45-
appClient := k8s.NewAppClient(client, namespace)
44+
appClient := client.Resource(k8s.Applications)
4645
appInformer := newInformer(appClient, appLabelSelector)
4746
appProjInformer := newInformer(k8s.NewAppProjClient(client, namespace), "")
4847
secretInformer := k8s.NewSecretInformer(k8sClient, namespace)
@@ -56,17 +55,27 @@ func NewController(
5655
appProjInformer: appProjInformer,
5756
apiFactory: apiFactory}
5857
res.ctrl = controller.NewController(appClient, appInformer, apiFactory,
59-
controller.WithSkipProcessing(func(obj *unstructured.Unstructured) (bool, string) {
60-
return !isAppSyncStatusRefreshed(obj, log.WithField("app", obj.GetName())), "sync status out of date"
58+
controller.WithSkipProcessing(func(obj v1.Object) (bool, string) {
59+
app, ok := (obj).(*unstructured.Unstructured)
60+
if !ok {
61+
return false, ""
62+
}
63+
return !isAppSyncStatusRefreshed(app, log.WithField("app", obj.GetName())), "sync status out of date"
6164
}),
6265
controller.WithMetricsRegistry(registry),
6366
controller.WithAdditionalDestinations(res.getAdditionalDestinations))
6467
return res
6568
}
6669

67-
func (c *notificationController) getAdditionalDestinations(obj *unstructured.Unstructured, cfg api.Config) services.Destinations {
70+
func (c *notificationController) getAdditionalDestinations(obj v1.Object, cfg api.Config) services.Destinations {
6871
res := services.Destinations{}
69-
if proj := getAppProj(obj, c.appProjInformer); proj != nil {
72+
73+
app, ok := (obj).(*unstructured.Unstructured)
74+
if !ok {
75+
return res
76+
}
77+
78+
if proj := getAppProj(app, c.appProjInformer); proj != nil {
7079
res.Merge(subscriptions.Annotations(proj.GetAnnotations()).GetDestinations(cfg.DefaultTriggers, cfg.ServiceDefaultTriggers))
7180
res.Merge(settings.GetLegacyDestinations(proj.GetAnnotations(), cfg.DefaultTriggers, cfg.ServiceDefaultTriggers))
7281
}
@@ -114,7 +123,7 @@ func (c *notificationController) Init(ctx context.Context) error {
114123
}
115124

116125
func (c *notificationController) Run(ctx context.Context, processors int) {
117-
c.ctrl.Run(ctx, processors)
126+
c.ctrl.Run(processors, ctx.Done())
118127
}
119128

120129
func getAppProj(app *unstructured.Unstructured, appProjInformer cache.SharedIndexInformer) *unstructured.Unstructured {

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.20210503203905-e8ac53e2f18e
7+
github.com/argoproj/notifications-engine v0.1.1-0.20210503221649-02b903bd1840
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.20210503203905-e8ac53e2f18e h1:XxM9ghkKMVHy92za2Q0dMHgROZnawgJy3btp21tk33E=
97-
github.com/argoproj/notifications-engine v0.1.1-0.20210503203905-e8ac53e2f18e/go.mod h1:rKhm9LtebGKgLA/UtPtBeRUrrS/CT0U5az1jSfUiipw=
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=
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)