Skip to content

Commit

Permalink
stateful mongo config
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamqweasd committed Jun 1, 2017
1 parent 230d9c0 commit d676863
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit d676863

Please sign in to comment.