summaryrefslogtreecommitdiffstats
path: root/healthcheck-container/get-status.js
diff options
context:
space:
mode:
authorJack Lucas <jflucas@research.att.com>2018-12-13 17:24:29 -0500
committerJack Lucas <jflucas@research.att.com>2018-12-13 17:26:36 -0500
commit1d746685f1d61f36182d67ff7f24f0f0a18a4c66 (patch)
tree446ec4500108d9b415d9bc5026d8a8788f7c2c0b /healthcheck-container/get-status.js
parentf3f9d04cfd325ac427d7a6a6f1596bc2d5c40970 (diff)
Restore list of expected CM deployments
Remove unneeded npm install from Dockerfile Add README Change-Id: I671217e7e30c041759effbe173a9b28a8f4a8f29 Issue-ID: DCAEGEN2-988 Signed-off-by: Jack Lucas <jflucas@research.att.com>
Diffstat (limited to 'healthcheck-container/get-status.js')
-rw-r--r--healthcheck-container/get-status.js228
1 files changed, 114 insertions, 114 deletions
diff --git a/healthcheck-container/get-status.js b/healthcheck-container/get-status.js
index 9c4a723..565c1e0 100644
--- a/healthcheck-container/get-status.js
+++ b/healthcheck-container/get-status.js
@@ -33,141 +33,141 @@ const ca = fs.readFileSync(K8S_CREDS + '/ca.crt');
const token = fs.readFileSync(K8S_CREDS + '/token');
const summarizeDeploymentList = function(list) {
- // list is a DeploymentList object returned by k8s
- // Individual deployments are in the array 'items'
-
- let ret =
- {
- type: "summary",
- count: 0,
- ready: 0,
- items: []
- };
-
- // Extract readiness information
- for (let deployment of list.items) {
- ret.items.push(
- {
- name: deployment.metadata.name,
- ready: deployment.status.readyReplicas || 0,
- unavailable: deployment.status.unavailableReplicas || 0
- }
- );
- ret.count ++;
- ret.ready = ret.ready + (deployment.status.readyReplicas || 0);
- }
-
- return ret;
+ // list is a DeploymentList object returned by k8s
+ // Individual deployments are in the array 'items'
+
+ let ret =
+ {
+ type: "summary",
+ count: 0,
+ ready: 0,
+ items: []
+ };
+
+ // Extract readiness information
+ for (let deployment of list.items) {
+ ret.items.push(
+ {
+ name: deployment.metadata.name,
+ ready: deployment.status.readyReplicas || 0,
+ unavailable: deployment.status.unavailableReplicas || 0
+ }
+ );
+ ret.count ++;
+ ret.ready = ret.ready + (deployment.status.readyReplicas || 0);
+ }
+
+ return ret;
};
const summarizeDeployment = function(deployment) {
- // deployment is a Deployment object returned by k8s
- // we make it look enough like a DeploymentList object to
- // satisfy summarizeDeploymentList
- return summarizeDeploymentList({items: [deployment]});
+ // deployment is a Deployment object returned by k8s
+ // we make it look enough like a DeploymentList object to
+ // satisfy summarizeDeploymentList
+ return summarizeDeploymentList({items: [deployment]});
};
const queryKubernetes = function(path, callback) {
- // Make GET request to Kubernetes API
- const options = {
- host: K8S_HOST,
- path: "/" + path,
- ca : ca,
- headers: {
- Authorization: 'bearer ' + token
- }
- };
- console.log ("request url: " + options.host + options.path);
- const req = https.get(options, function(resp) {
- let rawBody = "";
- resp.on("data", function(data) {
- rawBody += data;
- });
- resp.on("error", function (error) {
- console.error("error: " + error);
- callback(error, null, null)
- });
- resp.on("end", function() {
- console.log ("status: " + resp.statusCode ? resp.statusCode: "NONE")
- callback(null, resp, JSON.parse(rawBody));
- });
- });
- req.end();
+ // Make GET request to Kubernetes API
+ const options = {
+ host: K8S_HOST,
+ path: "/" + path,
+ ca : ca,
+ headers: {
+ Authorization: 'bearer ' + token
+ }
+ };
+ console.log ("request url: " + options.host + options.path);
+ const req = https.get(options, function(resp) {
+ let rawBody = "";
+ resp.on("data", function(data) {
+ rawBody += data;
+ });
+ resp.on("error", function (error) {
+ console.error("error: " + error);
+ callback(error, null, null)
+ });
+ resp.on("end", function() {
+ console.log ("status: " + resp.statusCode ? resp.statusCode: "NONE")
+ callback(null, resp, JSON.parse(rawBody));
+ });
+ });
+ req.end();
};
const getStatus = function(path, extract, callback) {
- // Get info from k8s and extract readiness info
- queryKubernetes(path, function(error, res, body) {
- let ret = body;
- if (!error && res && res.statusCode === 200) {
- ret = extract(body);
- }
- callback (error, res, ret);
- });
+ // Get info from k8s and extract readiness info
+ queryKubernetes(path, function(error, res, body) {
+ let ret = body;
+ if (!error && res && res.statusCode === 200) {
+ ret = extract(body);
+ }
+ callback (error, res, ret);
+ });
};
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);
- }
- });
- });
+ // 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';
- getStatus(path, summarizeDeploymentList, callback);
+ // Get readiness information for all deployments in namespace
+ const path = K8S_PATH + namespace + '/deployments';
+ getStatus(path, summarizeDeploymentList, callback);
};
exports.getStatusSingle = function (namespace, deployment, callback) {
- // Get readiness information for a single deployment
- const path = K8S_PATH + namespace + '/deployments/' + deployment;
- getStatus(path, summarizeDeployment, callback);
+ // Get readiness information for a single deployment
+ const path = K8S_PATH + namespace + '/deployments/' + deployment;
+ getStatus(path, summarizeDeployment, callback);
};
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});
- });
+ // 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});
+ });
}
exports.getDCAEDeploymentsPromise = function (namespace) {
- // Return list of the form [{namespace: "namespace"}, deployment: "deployment_name"].
- // List contains all k8s deployments in the specified namespace that were deployed
- // by Cloudify, based on Cloudify's use of a "marker" label on each k8s deployment that
- // the k8s plugin created.
-
- return new Promise(function(resolve, reject) {
- const path = K8S_PATH + namespace + '/deployments?labelSelector=' + CFY_LABEL + '&limit=' + MAX_DEPS
- queryKubernetes(path, function(error, res, body){
- if (error) {
- reject(error);
- }
- else if (res.statusCode !== 200) {
- reject(body);
- }
- else {
- resolve(body.items.map(function(i) {return {namespace : namespace, deployment: i.metadata.name};}));
- }
- });
- });
+ // Return list of the form [{namespace: "namespace"}, deployment: "deployment_name"].
+ // List contains all k8s deployments in the specified namespace that were deployed
+ // by Cloudify, based on Cloudify's use of a "marker" label on each k8s deployment that
+ // the k8s plugin created.
+
+ return new Promise(function(resolve, reject) {
+ const path = K8S_PATH + namespace + '/deployments?labelSelector=' + CFY_LABEL + '&limit=' + MAX_DEPS
+ queryKubernetes(path, function(error, res, body){
+ if (error) {
+ reject(error);
+ }
+ else if (res.statusCode !== 200) {
+ reject(body);
+ }
+ else {
+ resolve(body.items.map(function(i) {return {namespace : namespace, deployment: i.metadata.name};}));
+ }
+ });
+ });
};