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

Commit

Permalink
fix: watch without namespace path if watching all namespaces (#673)
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Maga <[email protected]>
  • Loading branch information
Flydiverny authored Mar 26, 2021
1 parent 1de2458 commit fa070ef
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
34 changes: 23 additions & 11 deletions lib/external-secret.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function createEventQueue () {

async function startWatcher ({
kubeClient,
namespace,
namespace = null,
customResourceManifest,
logger,
eventQueue,
Expand All @@ -35,10 +35,15 @@ async function startWatcher ({
while (true) {
logger.debug('Starting watch stream for namespace %s', loggedNamespaceName)

const stream = await kubeClient
let api = kubeClient
.apis[customResourceManifest.spec.group]
.v1.watch
.namespaces(namespace)[customResourceManifest.spec.names.plural]

if (namespace) {
api = api.namespaces(namespace)
}

const stream = await api[customResourceManifest.spec.names.plural]
.getObjectStream()

let timeout
Expand Down Expand Up @@ -101,21 +106,28 @@ function getExternalSecretEvents ({
return (async function * () {
const eventQueue = createEventQueue()

// If the watchedNamespaces is an empty array (i.e. no scoped access),
// add an empty element so all ExternalSecret resources in all namespaces will be watched.
const namespaceToWatch = watchedNamespaces.length ? watchedNamespaces : ['']

// Create watcher for each namespace
namespaceToWatch.forEach((namespace) => {
// If the watchedNamespaces is set create a watcher for each namespace, otherwise create a watcher for all namespaces.
if (watchedNamespaces.length) {
// Create watcher for each namespace
watchedNamespaces.forEach((namespace) => {
startWatcher({
namespace,
kubeClient,
customResourceManifest,
logger,
eventQueue,
watchTimeout
})
})
} else {
startWatcher({
namespace,
kubeClient,
customResourceManifest,
logger,
eventQueue,
watchTimeout
})
})
}

while (true) {
yield await eventQueue.take()
Expand Down
3 changes: 2 additions & 1 deletion lib/external-secret.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ describe('getExternalSecretEvents', () => {
return {
externalsecrets
}
}
},
externalsecrets
}
}
}
Expand Down

0 comments on commit fa070ef

Please sign in to comment.