Skip to content
This repository was archived by the owner on Jul 26, 2022. It is now read-only.

Commit fa070ef

Browse files
authored
fix: watch without namespace path if watching all namespaces (#673)
Signed-off-by: Markus Maga <[email protected]>
1 parent 1de2458 commit fa070ef

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

lib/external-secret.js

+23-11
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function createEventQueue () {
2222

2323
async function startWatcher ({
2424
kubeClient,
25-
namespace,
25+
namespace = null,
2626
customResourceManifest,
2727
logger,
2828
eventQueue,
@@ -35,10 +35,15 @@ async function startWatcher ({
3535
while (true) {
3636
logger.debug('Starting watch stream for namespace %s', loggedNamespaceName)
3737

38-
const stream = await kubeClient
38+
let api = kubeClient
3939
.apis[customResourceManifest.spec.group]
4040
.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]
4247
.getObjectStream()
4348

4449
let timeout
@@ -101,21 +106,28 @@ function getExternalSecretEvents ({
101106
return (async function * () {
102107
const eventQueue = createEventQueue()
103108

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 {
110123
startWatcher({
111-
namespace,
112124
kubeClient,
113125
customResourceManifest,
114126
logger,
115127
eventQueue,
116128
watchTimeout
117129
})
118-
})
130+
}
119131

120132
while (true) {
121133
yield await eventQueue.take()

lib/external-secret.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ describe('getExternalSecretEvents', () => {
3737
return {
3838
externalsecrets
3939
}
40-
}
40+
},
41+
externalsecrets
4142
}
4243
}
4344
}

0 commit comments

Comments
 (0)