diff options
Diffstat (limited to 'healthcheck-container/get-status.js')
-rw-r--r-- | healthcheck-container/get-status.js | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/healthcheck-container/get-status.js b/healthcheck-container/get-status.js index 2ed1d3d..034ff9d 100644 --- a/healthcheck-container/get-status.js +++ b/healthcheck-container/get-status.js @@ -96,6 +96,30 @@ const getStatus = function(path, extract, callback) { }); }; +const getStatusSinglePromise = function (item) { + // Expect item to be of the form {namespace: "namespace", deployment: "deployment_name"} + return new Promise(function(resolve, reject){ + const path = K8S_PATH + item.namespace + '/deployments/' + item.deployment; + queryKubernetes(path, function(error, res, body){ + if (error) { + reject(error); + } + else if (res.statusCode === 404) { + // Treat absent deployment as if it's an unhealthy deployment + resolve ({ + metadata: {name: item.deployment}, + status: {unavailableReplicas: 1} + }); + } + else if (res.statusCode != 200) { + reject(body); + } + else { + resolve(body); + } + }); + }); +} exports.getStatusNamespace = function (namespace, callback) { // Get readiness information for all deployments in namespace const path = K8S_PATH + namespace + '/deployments'; @@ -106,4 +130,12 @@ exports.getStatusSingle = function (namespace, deployment, callback) { // Get readiness information for a single deployment const path = K8S_PATH + namespace + '/deployments/' + deployment; getStatus(path, summarizeDeployment, callback); -};
\ No newline at end of file +}; + +exports.getStatusListPromise = function (list) { + // List is of the form [{namespace: "namespace", deployment: "deployment_name"}, ... ] + const p = Promise.all(list.map(getStatusSinglePromise)) + return p.then(function(results) { + return summarizeDeploymentList({items: results}); + }); +}
\ No newline at end of file |