Skip to content

Commit

Permalink
Update: be more selective on allowed error codes (#148)
Browse files Browse the repository at this point in the history
* Update: be more selective on allowed error codes

during polling, be more selective on which error codes should be allowed to pass unnoticed.

* Update: Re-order ifs for readability

* Upgrade: fixes lodash vuln
  • Loading branch information
alewitt2 authored Jul 14, 2020
1 parent eef101e commit 63333d4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 22 deletions.
36 changes: 18 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 27 additions & 4 deletions src/controllers/Poll.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ async function handleSelector(metaResources, razeedashSender, selector, formatte
if (o.length > 0) {
razeedashSender.send(o);
}
} else if (r.statusCode === 403 || r.statusCode === 404 || r.statusCode === 405) {
// 403 Forbidden, 404 NotFound, 405 MethodNotAllowed
// These statusCodes are expected. Processing should continue.
log.debug(`Could not get resource '${r['resource-metadata'].uri()}' : ${JSON.stringify(r.error)}`);
} else { // Unexpected status code. Error out of this flow.
util.error(`Could not get resource '${r['resource-metadata'].uri()}'`, r.error);
success = false;
}
});
} while (next);
Expand Down Expand Up @@ -124,6 +131,13 @@ async function handleNonNamespaced(metaResources, razeedashSender, selector, for
if (o.length > 0) {
razeedashSender.send(o);
}
} else if (r.statusCode === 403 || r.statusCode === 404 || r.statusCode === 405) {
// 403 Forbidden, 404 NotFound, 405 MethodNotAllowed
// These statusCodes are expected. Processing should continue.
log.debug(`Could not get resource '${r['resource-metadata'].uri()}' : ${JSON.stringify(r.error)}`);
} else { // Unexpected status code. Error out of this flow.
util.error(`Could not get resource '${r['resource-metadata'].uri()}'`, r.error);
success = false;
}
});
} while (next);
Expand Down Expand Up @@ -215,6 +229,7 @@ async function selectiveListTrim(metaResources) {
// doesnt have any resources on the system. This takes a while up front, but
// should save time for the rest of the calls
async function trimMetaResources(metaResources) {
log.debug('- Trimming metaResources starting -');
metaResources = await selectiveListTrim(metaResources);

// eslint-disable-next-line require-atomic-updates
Expand All @@ -224,13 +239,21 @@ async function trimMetaResources(metaResources) {
for (var i = 0; i < metaResources.length; i++) {
if (!metaResources[i].name.endsWith('/status')) { // call to /status returns same data as call to plain endpoint. so no need to make call
let resource = await kc.getResource(metaResources[i], selector);

let cont = objectPath.get(resource, 'object.metadata.continue');
if (resource.statusCode === 200 && (objectPath.get(resource, 'object.items', []).length > 0 || (cont !== undefined && cont !== ''))) {
result.push(metaResources[i]);
if (resource.statusCode === 200) {
if (objectPath.get(resource, 'object.items', []).length > 0 || (cont !== undefined && cont !== '')) {
result.push(metaResources[i]);
}
} else if (resource.statusCode === 403 || resource.statusCode === 404 || resource.statusCode === 405) {
// 403 Forbidden, 404 NotFound, 405 MethodNotAllowed
// These statusCodes are expected. Processing should continue.
log.debug(`Could not get resource '${resource['resource-metadata'].uri()}' : ${JSON.stringify(resource.error)}`);
} else { // Unexpected status code. Error out of this flow.
throw `Could not get resource '${resource['resource-metadata'].uri()}' : ${JSON.stringify(resource.error)}`;
}
}
}
log.debug('- Trimming metaResources complete -');
return result;
}

Expand All @@ -252,7 +275,7 @@ async function poll() {
return success;
}
} catch (e) {
util.error(`Error querying Kubernetes resources supporting 'get' verb. ${e}`);
util.error('Error querying Kubernetes resources supporting \'get\' verb.', e);
success = false;
return success;
}
Expand Down

0 comments on commit 63333d4

Please sign in to comment.