@@ -154,6 +154,18 @@ func NewControllerWithNamespaceSupport(
154
154
return ctrl
155
155
}
156
156
157
+ // NewControllerWithNamespaceSupport For self-service notification
158
+ func NewControllerWithFactorySupport (
159
+ client dynamic.NamespaceableResourceInterface ,
160
+ informer cache.SharedIndexInformer ,
161
+ apiFactory api.Factory ,
162
+ opts ... Opts ,
163
+ ) * notificationController {
164
+ ctrl := NewController (client , informer , apiFactory , opts ... )
165
+ ctrl .factorySupport = true
166
+ return ctrl
167
+ }
168
+
157
169
type notificationController struct {
158
170
client dynamic.NamespaceableResourceInterface
159
171
informer cache.SharedIndexInformer
@@ -165,6 +177,7 @@ type notificationController struct {
165
177
toUnstructured func (obj v1.Object ) (* unstructured.Unstructured , error )
166
178
eventCallback func (eventSequence NotificationEventSequence )
167
179
namespaceSupport bool
180
+ factorySupport bool
168
181
}
169
182
170
183
func (c * notificationController ) Run (threadiness int , stopCh <- chan struct {}) {
@@ -304,36 +317,35 @@ func (c *notificationController) processQueueItem() (processNext bool) {
304
317
}
305
318
}
306
319
307
- if ! c . namespaceSupport {
308
- api , err := c .apiFactory .GetAPI ( )
320
+ if c . factorySupport {
321
+ apisWithNamespace , err := c .apiFactory .GetAPIsFromFactory ( resource )
309
322
if err != nil {
310
- logEntry .Errorf ("Failed to get api: %v" , err )
323
+ logEntry .Errorf ("Failed to get api with namespace : %v" , err )
311
324
eventSequence .addError (err )
312
- return
313
325
}
314
- c .processResource (api , resource , logEntry , & eventSequence )
315
- } else {
316
- // this is for cluster support
317
- annotations := resource .GetAnnotations ()
318
- notificationNS := annotations ["notification-namespace" ]
319
- notificationCluster := annotations ["notification-cluster" ]
320
- log .Infof ("%s" , notificationNS )
321
- log .Infof ("%s" , notificationCluster )
322
-
323
- resourceNameSpace := resource .GetNamespace ()
324
- if notificationNS != "" && notificationCluster != "" {
325
- resourceNameSpace = notificationCluster + "#" + notificationNS
326
+ for _ , api := range apisWithNamespace {
327
+ c .processResource (api , resource , logEntry , & eventSequence )
326
328
}
327
329
328
- apisWithNamespace , err := c .apiFactory .GetAPIsFromNamespace (resourceNameSpace )
330
+ } else if c .namespaceSupport {
331
+ apisWithNamespace , err := c .apiFactory .GetAPIsFromNamespace (resource .GetNamespace ())
329
332
if err != nil {
330
333
logEntry .Errorf ("Failed to get api with namespace: %v" , err )
331
334
eventSequence .addError (err )
332
335
}
333
336
for _ , api := range apisWithNamespace {
334
337
c .processResource (api , resource , logEntry , & eventSequence )
335
338
}
339
+ } else {
340
+ api , err := c .apiFactory .GetAPI ()
341
+ if err != nil {
342
+ logEntry .Errorf ("Failed to get api: %v" , err )
343
+ eventSequence .addError (err )
344
+ return
345
+ }
346
+ c .processResource (api , resource , logEntry , & eventSequence )
336
347
}
348
+
337
349
logEntry .Info ("Processing completed" )
338
350
339
351
return
0 commit comments