Skip to content

Commit

Permalink
Update: change naming to be more descriptive (#138)
Browse files Browse the repository at this point in the history
* Update: change naming to be more descriptive

* Docs: remove newline

* Docs: add s
  • Loading branch information
alewitt2 authored Jun 23, 2020
1 parent e03c598 commit 3da7c36
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 36 deletions.
38 changes: 20 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<level>`. This will collect and report all data within the
labeled namespace at the desired `<level>`. 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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'`.

Expand All @@ -158,7 +160,7 @@ metadata:
namespace: <watch-keeper ns>
data:
# Type of list (must be 'true')
whitelist: 'true'
include: 'true'
# Resources affected (must be 'true')
v1_node: 'true'
Expand Down
36 changes: 19 additions & 17 deletions src/controllers/Poll.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
}

Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion test/Poll-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ describe('Poll', () => {
var revertPoll = Poll.__set__({
'util': util,
'kc': mockKubeClass,
'readWBList': mockReadWBList
'readIEList': mockReadWBList
});
// Test
let given = [{
Expand Down

0 comments on commit 3da7c36

Please sign in to comment.