From d676863284fcf1de140aa0aba71c5c927b50ac89 Mon Sep 17 00:00:00 2001 From: shubhamqweasd Date: Thu, 1 Jun 2017 12:36:47 +0530 Subject: [PATCH] stateful mongo config --- server.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/server.js b/server.js index fa723a05..50dcac4e 100644 --- a/server.js +++ b/server.js @@ -616,7 +616,7 @@ function setUpMongoDB() { console.log("Looking for a MongoDB Cluster..."); - if ((!global.config && !process.env["MONGO_1_PORT_27017_TCP_ADDR"] && !process.env["MONGO_SERVICE_HOST"]) || (!global.config && !process.env["MONGO_PORT_27017_TCP_ADDR"] && !process.env["MONGO_SERVICE_HOST"])) { + if ((!global.config && !process.env["MONGO_1_PORT_27017_TCP_ADDR"] && !process.env["KUBERNETES_STATEFUL_MONGO_URL"])) { console.error("INFO : Not running on Docker. Use docker-compose (recommended) from https://github.com/cloudboost/docker"); } @@ -652,19 +652,17 @@ function setUpMongoDB() { } global.config.mongo = []; - if (process.env["MONGO1_SERVICE_HOST"]) { + if (process.env["KUBERNETES_STATEFUL_MONGO_URL"]) { console.log("MongoDB is running on Kubernetes"); - var i = 1; - while (process.env["MONGO" + i + "_SERVICE_HOST"]) { - global.config.mongo.push({ - host: process.env["MONGO" + i + "_SERVICE_HOST"], - port: process.env["MONGO" + i + "_SERVICE_PORT"] - }); - mongoConnectionString += process.env["MONGO" + i + "_SERVICE_HOST"] + ":" + process.env["MONGO" + i + "_SERVICE_PORT"]; - mongoConnectionString += ","; - ++i; - } - + + global.config.mongo = process.env["KUBERNETES_STATEFUL_MONGO_URL"].split(',').map(function(x,i){ + return { + host:x.split(':')[0], + port:x.split(':')[1] + } + }) + + mongoConnectionString += process.env["KUBERNETES_STATEFUL_MONGO_URL"] isReplicaSet = true; } else {