summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Lucas <jflucas@research.att.com>2018-05-09 22:44:31 +0000
committerJack Lucas <jflucas@research.att.com>2018-05-10 15:02:34 +0000
commite6d18573f4a45b144e0b56dd1e59715a1bdd2c58 (patch)
tree9fad26f021e06f14ba3b95a7851f3b4714dc97e1
parentcb9d614fdc78480584466b8e84f3535d946424a0 (diff)
Fix healthcheck to check specific deployments
Change-Id: Idc6a3eece4e3aaba83a0b2388f2ae6c2407471a5 Issue-ID: DCAEGEN2-493 Signed-off-by: Jack Lucas <jflucas@research.att.com>
-rw-r--r--healthcheck-container/get-status.js34
-rw-r--r--healthcheck-container/healthcheck.js65
-rw-r--r--healthcheck-container/package.json2
-rw-r--r--healthcheck-container/pom.xml2
4 files changed, 72 insertions, 31 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
diff --git a/healthcheck-container/healthcheck.js b/healthcheck-container/healthcheck.js
index 7555032..ca1df84 100644
--- a/healthcheck-container/healthcheck.js
+++ b/healthcheck-container/healthcheck.js
@@ -17,16 +17,45 @@ See the License for the specific language governing permissions and limitations
//Expect ONAP and DCAE namespaces and Helm "release" name to be passed via environment variables
//
const ONAP_NS = process.env.ONAP_NAMESPACE || 'default';
-const DCAE_NS = process.env.DCAE_NAMESPACE || 'default';
+const DCAE_NS = process.env.DCAE_NAMESPACE || process.env.ONAP_NAMESPACE || 'default';
const HELM_REL = process.env.HELM_RELEASE || '';
const HEALTHY = 200;
const UNHEALTHY = 500;
const UNKNOWN = 503;
+// List of deployments expected to be created via Helm
+const helmDeps =
+ [
+ 'dcae-cloudify-manager'
+ ];
+
+// List of deployments expected to be created via Cloudify Manager
+const dcaeDeps =
+ [
+ 'dep-config-binding-service',
+ 'dep-deployment-handler',
+ 'dep-inventory',
+ 'dep-service-change-handler',
+ 'dep-policy-handler',
+ 'dep-dcae-ves-collector',
+ 'dep-dcae-tca-analytics'
+ ];
+
const status = require('./get-status');
const http = require('http');
+// Helm deployments are always in the ONAP namespace and prefixed by Helm release name
+const helmList = helmDeps.map(function(name) {
+ return {namespace: ONAP_NS, deployment: HELM_REL.length > 0 ? HELM_REL + '-' + name : name};
+});
+
+// DCAE deployments via CM don't have a release prefix and are in the DCAE namespace,
+// which can be the same as the ONAP namespace
+const dcaeList = dcaeDeps.map(function(name) {
+ return {namespace: DCAE_NS, deployment: name};
+});
+
const isHealthy = function(summary) {
// Current healthiness criterion is simple--all deployments are ready
return summary.count && summary.ready && summary.count === summary.ready;
@@ -38,33 +67,13 @@ const checkHealth = function (callback) {
// If we get responses from k8s but don't find all deployments ready, health status is UNHEALTHY (503)
// If we get responses from k8s and all deployments are ready, health status is HEALTHY (200)
// This could be a lot more nuanced, but what's here should be sufficient for R2 OOM healthchecking
- status.getStatusNamespace(DCAE_NS, function(err, res, body) {
- let ret = {status : UNKNOWN, body: [body]};
- if (err) {
- callback(ret);
- }
- else if (body.type && body.type === 'summary') {
- if (isHealthy(body)) {
- // All the DCAE components report healthy -- check Cloudify Manager
- let cmDeployment = 'dcae-cloudify-manager';
- if (HELM_REL.length > 0) {
- cmDeployment = HELM_REL + '-' + cmDeployment;
- }
- status.getStatusSingle(ONAP_NS, cmDeployment, function (err, res, body){
- ret.body.push(body);
- if (err) {
- callback(ret);
- }
- if (body.type && body.type === 'summary') {
- ret.status = isHealthy(body) ? HEALTHY : UNHEALTHY;
- }
- callback(ret);
- });
- }
- else {
- callback(ret);
- }
- }
+
+ status.getStatusListPromise(helmList.concat(dcaeList))
+ .then(function(body) {
+ callback({status: isHealthy(body) ? HEALTHY : UNHEALTHY, body: body});
+ })
+ .catch(function(error){
+ callback({status: UNKNOWN, body: [error]})
});
};
diff --git a/healthcheck-container/package.json b/healthcheck-container/package.json
index 2a08bdd..c4b7560 100644
--- a/healthcheck-container/package.json
+++ b/healthcheck-container/package.json
@@ -1,7 +1,7 @@
{
"name": "k8s-healthcheck",
"description": "DCAE healthcheck server",
- "version": "1.0.0",
+ "version": "1.1.0",
"main": "healthcheck.js",
"dependencies": {
"request": "2.85.0"
diff --git a/healthcheck-container/pom.xml b/healthcheck-container/pom.xml
index dea3c48..415c1cb 100644
--- a/healthcheck-container/pom.xml
+++ b/healthcheck-container/pom.xml
@@ -27,7 +27,7 @@ limitations under the License.
<groupId>org.onap.dcaegen2.deployments</groupId>
<artifactId>healthcheck-container</artifactId>
<name>dcaegen2-deployments-healthcheck-container</name>
- <version>1.0.0</version>
+ <version>1.1.0</version>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>