7
7
"time"
8
8
9
9
"github.com/argoproj-labs/argocd-notifications/shared/argocd"
10
- "k8s.io/client-go/kubernetes"
11
-
12
10
"github.com/argoproj-labs/argocd-notifications/shared/k8s"
13
11
"github.com/argoproj-labs/argocd-notifications/shared/settings"
14
12
@@ -22,6 +20,7 @@ import (
22
20
"k8s.io/apimachinery/pkg/runtime"
23
21
"k8s.io/apimachinery/pkg/watch"
24
22
"k8s.io/client-go/dynamic"
23
+ "k8s.io/client-go/kubernetes"
25
24
"k8s.io/client-go/tools/cache"
26
25
)
27
26
@@ -42,7 +41,7 @@ func NewController(
42
41
appLabelSelector string ,
43
42
registry * controller.MetricsRegistry ,
44
43
) * notificationController {
45
- appClient := k8s . NewAppClient ( client , namespace )
44
+ appClient := client . Resource ( k8s . Applications )
46
45
appInformer := newInformer (appClient , appLabelSelector )
47
46
appProjInformer := newInformer (k8s .NewAppProjClient (client , namespace ), "" )
48
47
secretInformer := k8s .NewSecretInformer (k8sClient , namespace )
@@ -56,17 +55,27 @@ func NewController(
56
55
appProjInformer : appProjInformer ,
57
56
apiFactory : apiFactory }
58
57
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"
61
64
}),
62
65
controller .WithMetricsRegistry (registry ),
63
66
controller .WithAdditionalDestinations (res .getAdditionalDestinations ))
64
67
return res
65
68
}
66
69
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 {
68
71
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 {
70
79
res .Merge (subscriptions .Annotations (proj .GetAnnotations ()).GetDestinations (cfg .DefaultTriggers , cfg .ServiceDefaultTriggers ))
71
80
res .Merge (settings .GetLegacyDestinations (proj .GetAnnotations (), cfg .DefaultTriggers , cfg .ServiceDefaultTriggers ))
72
81
}
@@ -114,7 +123,7 @@ func (c *notificationController) Init(ctx context.Context) error {
114
123
}
115
124
116
125
func (c * notificationController ) Run (ctx context.Context , processors int ) {
117
- c .ctrl .Run (ctx , processors )
126
+ c .ctrl .Run (processors , ctx . Done () )
118
127
}
119
128
120
129
func getAppProj (app * unstructured.Unstructured , appProjInformer cache.SharedIndexInformer ) * unstructured.Unstructured {
0 commit comments