From 3da7c36b1a9132eab7978040003a1cb0eee65fb1 Mon Sep 17 00:00:00 2001 From: Alex Lewitt <48691328+alewitt2@users.noreply.github.com> Date: Tue, 23 Jun 2020 12:34:09 -0400 Subject: [PATCH] Update: change naming to be more descriptive (#138) * Update: change naming to be more descriptive * Docs: remove newline * Docs: add s --- README.md | 38 ++++++++++++++++++++------------------ src/controllers/Poll.js | 36 +++++++++++++++++++----------------- test/Poll-test.js | 2 +- 3 files changed, 40 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 1ab0995..b4a300a 100644 --- a/README.md +++ b/README.md @@ -40,10 +40,10 @@ This is useful for resources that are not watchable. 1. Namespaces: you can gather info from a cluster by labeling a namespace with `razee/watch-resource=`. This will collect and report all data within the labeled namespace at the desired ``. Info is only gathered on the polling -cycle. See [white/black lists](#whiteblack-lists) to limit what is collected. +cycle. See [include/exclude lists](#includeexclude-lists) to limit what is collected. 1. Non-Namespaced Resources: you can gather info about resources that are not bound to a namespace by adding the key `poll` to the `watch-keeper-non-namespaced` ConfigMap. -Info is only gathered on the polling cycle. See [white/black lists](#whiteblack-lists) +Info is only gathered on the polling cycle. See [include/exclude lists](#includeexclude-lists) to limit what is collected. See [Non-Namespaced Resources](#non-namespaced-resources) for more info. 1. Watch by Resource: this allows you to watch and see immediate updates on any @@ -74,7 +74,8 @@ can gather much more data than anticipated resulting in delays in data reporting ### Watch By Resource In order to avoid having to label each individual resource, we allow watching by -resource kind. Note: [white/black lists](#whiteblack-lists) do not affect watching. +resource kind. Note: [include/exclude lists](#includeexclude-lists) do not affect +watching. To watch a resource kind, add it to the `watch-keeper-non-namespaced` ConfigMap in the form `apiVersion_kind` (where any `/` is replaced with an `_`), with the @@ -110,16 +111,16 @@ data: ### Non-Namespaced Resources In order to avoid having to label each individual non-namespaced resource (eg. nodes, -namespaces, customresourcedefinitions), we allow polling of all non-namespaced resource. +namespaces, customresourcedefinitions), we allow polling of all non-namespaced resources. This mechanism is similar to how our namespace resource collection works, where you can label a namespace and we collect all the resources within that namespace for you; you can think of this like you are labeling the `non-namespaced-resources` namespace. Also similar to how you can label a namespace, there may be resources that you do -not want to collect (eg. storageclass), so you should use [white/black lists](#whiteblack-lists) -to limit what is collected. Note: using the white/black list will affect all resources -polled, namespaced and non-namespace. +not want to collect (eg. storageclass), so you should use [include/exclude lists](#includeexclude-lists) +to limit what is collected. Note: using the include/exclude list will affect all +resources polled, namespaced and non-namespace. ```yaml apiVersion: v1 @@ -131,22 +132,23 @@ data: poll: lite ``` -### White/Black Lists +### Include/Exclude Lists -You can white or black list resources by modifying the ConfigMap named +You can include or exclude resources by modifying the ConfigMap named `watch-keeper-limit-poll`, in the namespace your Watch-Keeper is running. -- If both a whitelist and blacklist are specified, only the whitelist will be used. -- The white/black list is employed during the **Polling**, **Namespace** and **Non-Namespaced** -[collection methods](#Collection-Methods). Any individual resource specifically -labeled to be watched will still be watched, regardless of the white/black list. +- If both an `include` and `exclude` key are specified, only `include` will be used. +- The include/exclude list is employed during the **Polling**, **Namespace** and +**Non-Namespaced** [collection methods](#Collection-Methods). Any individual resource +specifically labeled to be watched will still be watched, regardless of the include/exclude +list. -#### Creating a White/Black List +#### Creating a Include/Exclude List -- To create your white/black list, the ConfigMap will specify the kind of list -you want as the first key, and the rest of the ConfigMap entries become the white/black +- To create your include/exclude list, the ConfigMap will specify the kind of list +you want as the first key, and the rest of the ConfigMap entries become the include/exclude list. -- The white/black list itself is created from the ConfigMap keys: +- The include/exclude list itself is created from the ConfigMap keys: - The keys will be `apiVersion_kind` (where any `/` is replaced with an `_`). - The value must be `'true'`. @@ -158,7 +160,7 @@ metadata: namespace: data: # Type of list (must be 'true') - whitelist: 'true' + include: 'true' # Resources affected (must be 'true') v1_node: 'true' diff --git a/src/controllers/Poll.js b/src/controllers/Poll.js index 9849f8c..20b69cf 100644 --- a/src/controllers/Poll.js +++ b/src/controllers/Poll.js @@ -140,31 +140,33 @@ function resourceFormatter(o, level) { return res; } -async function readWBList() { +// include/exclude list +async function readIEList() { let configNs = process.env.CONFIG_NAMESPACE || process.env.NAMESPACE || 'kube-system'; let limitPollConfigMap = await Util.getConfigMap('watch-keeper-limit-poll', configNs); - if (objectPath.has(limitPollConfigMap, 'data.whitelist') && objectPath.get(limitPollConfigMap, 'data.whitelist') === 'true') { - let wlist = await Util.walkConfigMap('watch-keeper-limit-poll', ['whitelist.json', 'whitelist', 'blacklist.json', 'blacklist']); - return { whitelist: wlist }; + if ((objectPath.has(limitPollConfigMap, 'data.include') && objectPath.get(limitPollConfigMap, 'data.include') === 'true') || + (objectPath.has(limitPollConfigMap, 'data.whitelist') && objectPath.get(limitPollConfigMap, 'data.whitelist') === 'true')) { + let includeList = await Util.walkConfigMap('watch-keeper-limit-poll', ['include', 'whitelist.json', 'whitelist', 'exclude', 'blacklist.json', 'blacklist']); + return { include: includeList }; - } else if (objectPath.has(limitPollConfigMap, 'data.blacklist') && objectPath.get(limitPollConfigMap, 'data.blacklist') === 'true') { - let blist = await Util.walkConfigMap('watch-keeper-limit-poll', ['whitelist.json', 'whitelist', 'blacklist.json', 'blacklist']); - return { blacklist: blist }; + } else if ((objectPath.has(limitPollConfigMap, 'data.exclude') && objectPath.get(limitPollConfigMap, 'data.exclude') === 'true') || + (objectPath.has(limitPollConfigMap, 'data.blacklist') && objectPath.get(limitPollConfigMap, 'data.blacklist') === 'true')) { + let excludeList = await Util.walkConfigMap('watch-keeper-limit-poll', ['include', 'whitelist.json', 'whitelist', 'exclude', 'blacklist.json', 'blacklist']); + return { exclude: excludeList }; } else if (objectPath.has(limitPollConfigMap, ['data', 'whitelist.json'])) { try { let wlistJson = JSON.parse(objectPath.get(limitPollConfigMap, ['data', 'whitelist.json'], '{}')); let flattenedList = flattenJsonListObj(wlistJson); - return { whitelist: flattenedList }; + return { include: flattenedList }; } catch (e) { log.error(e); } - } else if (objectPath.has(limitPollConfigMap, ['data', 'blacklist.json'])) { try { let blistJson = JSON.parse(objectPath.get(limitPollConfigMap, ['data', 'blacklist.json'], '{}')); let flattenedList = flattenJsonListObj(blistJson); - return { blacklist: flattenedList }; + return { exclude: flattenedList }; } catch (e) { log.error(e); } @@ -183,8 +185,8 @@ function flattenJsonListObj(jsonObj) { } async function selectiveListTrim(metaResources) { - let { whitelist, blacklist } = await readWBList(); - if (!whitelist && !blacklist) { + let { include, exclude } = await readIEList(); + if (!include && !exclude) { return metaResources; } @@ -195,12 +197,12 @@ async function selectiveListTrim(metaResources) { let name = krm.name.replace(/\//g, '_'); if (!krm.name.endsWith('/status')) { - if (whitelist) { - if (Util.objIncludes(whitelist, `${apiVersion}_${kind}`, `${apiVersion}_${name}`).value === 'true') { + if (include) { + if (Util.objIncludes(include, `${apiVersion}_${kind}`, `${apiVersion}_${name}`).value === 'true') { result.push(krm); } - } else if (blacklist) { - if (!(Util.objIncludes(blacklist, `${apiVersion}_${kind}`, `${apiVersion}_${name}`).value === 'true')) { + } else if (exclude) { + if (!(Util.objIncludes(exclude, `${apiVersion}_${kind}`, `${apiVersion}_${name}`).value === 'true')) { result.push(krm); } } @@ -245,7 +247,7 @@ async function poll() { metaResources = await trimMetaResources(metaResources); log.debug(`Polling against resources: ${JSON.stringify(metaResources.map(mr => mr.uri()))}`); if (metaResources.length < 1) { - log.info('No resources found to poll (either due to no resources being labeled or white/black list configuration)'); + log.info('No resources found to poll (either due to no resources being labeled or include/exclude list configuration)'); log.info('Finished Polling Resources ============'); return success; } diff --git a/test/Poll-test.js b/test/Poll-test.js index 436e667..d289224 100644 --- a/test/Poll-test.js +++ b/test/Poll-test.js @@ -370,7 +370,7 @@ describe('Poll', () => { var revertPoll = Poll.__set__({ 'util': util, 'kc': mockKubeClass, - 'readWBList': mockReadWBList + 'readIEList': mockReadWBList }); // Test let given = [{