@@ -22,7 +22,7 @@ function createEventQueue () {
22
22
23
23
async function startWatcher ( {
24
24
kubeClient,
25
- namespace,
25
+ namespace = null ,
26
26
customResourceManifest,
27
27
logger,
28
28
eventQueue,
@@ -35,10 +35,15 @@ async function startWatcher ({
35
35
while ( true ) {
36
36
logger . debug ( 'Starting watch stream for namespace %s' , loggedNamespaceName )
37
37
38
- const stream = await kubeClient
38
+ let api = kubeClient
39
39
. apis [ customResourceManifest . spec . group ]
40
40
. v1 . watch
41
- . namespaces ( namespace ) [ customResourceManifest . spec . names . plural ]
41
+
42
+ if ( namespace ) {
43
+ api = api . namespaces ( namespace )
44
+ }
45
+
46
+ const stream = await api [ customResourceManifest . spec . names . plural ]
42
47
. getObjectStream ( )
43
48
44
49
let timeout
@@ -101,21 +106,28 @@ function getExternalSecretEvents ({
101
106
return ( async function * ( ) {
102
107
const eventQueue = createEventQueue ( )
103
108
104
- // If the watchedNamespaces is an empty array (i.e. no scoped access),
105
- // add an empty element so all ExternalSecret resources in all namespaces will be watched.
106
- const namespaceToWatch = watchedNamespaces . length ? watchedNamespaces : [ '' ]
107
-
108
- // Create watcher for each namespace
109
- namespaceToWatch . forEach ( ( namespace ) => {
109
+ // If the watchedNamespaces is set create a watcher for each namespace, otherwise create a watcher for all namespaces.
110
+ if ( watchedNamespaces . length ) {
111
+ // Create watcher for each namespace
112
+ watchedNamespaces . forEach ( ( namespace ) => {
113
+ startWatcher ( {
114
+ namespace,
115
+ kubeClient,
116
+ customResourceManifest,
117
+ logger,
118
+ eventQueue,
119
+ watchTimeout
120
+ } )
121
+ } )
122
+ } else {
110
123
startWatcher ( {
111
- namespace,
112
124
kubeClient,
113
125
customResourceManifest,
114
126
logger,
115
127
eventQueue,
116
128
watchTimeout
117
129
} )
118
- } )
130
+ }
119
131
120
132
while ( true ) {
121
133
yield await eventQueue . take ( )
0 commit comments