Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion helm-chart/templates/_helper.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ https://{{ .Values.ROOT_URL }}
{{- if eq .Values.NODE_ENV "production" -}}
webapp-production-001.vyqym8.0001.aps1.cache.amazonaws.com
{{- else -}}
redis.{{ template "server.namespace" . }}.svc.cluster.local
redis-master.{{ template "server.namespace" . }}.svc.cluster.local
{{- end -}}
{{- end -}}

Expand Down
2 changes: 1 addition & 1 deletion imports/modules/bull/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ bullSystem.initBull = function() {
bullSystem.startBullWorkers(bullSystem);
};

//bullSystem.initBull();
bullSystem.initBull();

export default bullSystem;
48 changes: 25 additions & 23 deletions imports/modules/bull/workers/repull-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,39 @@ import { Networks } from '../../../collections/networks/networks';
import Config from '../../config/server';


const IMAGE_REPULL_CONCURRENCY = 3;
const IMAGE_REPULL_CONCURRENCY = 2;

module.exports = function(bullSystem) {

const processFunction = Meteor.bindEnvironment(function(job) {
console.log("Pulling image", job.data);
const network = Networks.find({
instanceId: job.data.instanceId
}).fetch()[0];
if(!network){
throw new Error("Network has been deleted before pulling image ", job.instanceId);
}
const locationCode = network.locationCode;
HTTP.get(`${Config.kubeRestApiHost(locationCode)}/api/v1/namespaces/${Config.namespace}/pods?labelSelector=app%3Ddynamo-node-${network.instanceId}`, (err, res) => {
if(err){
throw new Error(`Repull image failed for ${job.instanceId} - ${JSON.stringify(err)}`);
return new Promise(resolve => {
console.log("Pulling image", job.data);
const network = Networks.find({
instanceId: job.data.instanceId
}).fetch()[0];
if(!network){
throw new Error("Network has been deleted before pulling image ", job.instanceId);
}
const podList = JSON.parse(res.content);
podList.items.forEach(pod => {
const name = pod.metadata.name;
HTTP.call("DELETE", `${Config.kubeRestApiHost(locationCode)}/api/v1/namespaces/${Config.namespace}/pods/${name}`, function(error, response) {
if(error) {
throw new Error(`Error deleting pod ${pod.name} - ${JSON.stringify(error)}`);

// wait 10 seconds. We don't want to overload the kube api server
setTimeout(() => done(), 10 * 1000);
}
const locationCode = network.locationCode;
HTTP.get(`${Config.kubeRestApiHost(locationCode)}/api/v1/namespaces/${Config.namespace}/pods?labelSelector=app%3Ddynamo-node-${network.instanceId}`, (err, res) => {
if(err){
throw new Error(`Repull image failed for ${job.instanceId} - ${JSON.stringify(err)}`);
}
const podList = JSON.parse(res.content);
podList.items.forEach(pod => {
const name = pod.metadata.name;
HTTP.call("DELETE", `${Config.kubeRestApiHost(locationCode)}/api/v1/namespaces/${Config.namespace}/pods/${name}`, function(error, response) {
if(error) {
throw new Error(`Error deleting pod ${pod.name} - ${JSON.stringify(error)}`);
}
console.log("Deleted pod ", name);
// wait 60 seconds. We don't want to overload the kube api server
setTimeout(() => !console.log("Finshed job") && resolve(), 60 * 1000);
});
});
});
});
});

bullSystem.bullJobs.process('repull-image', 3, processFunction);
bullSystem.bullJobs.process('repull-image', IMAGE_REPULL_CONCURRENCY, processFunction);
}
30 changes: 17 additions & 13 deletions imports/modules/bull/workers/start-repull-image.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import { Networks } from "../../../collections/networks/networks";

module.exports = function(bullSystem) {
const processFunction = Meteor.bindEnvironment(function(job, done) {
console.log("Starting image pull", job.data);
const networks = Networks.find({
active: true,
deletedAt: null
}).fetch();
console.log("Netwoks to restart ", networks.map(i => i.instanceId));
networks.forEach(network => {
bullSystem.addJob("repull-image", {
instanceId: network.instanceId,
newImageTag: job.data.imageTag,
container: job.data.container
const processFunction = Meteor.bindEnvironment(function(job) {
return new Promise(resolve => {
console.log("Starting image pull", job.data);
const networks = Networks.find({
active: true,
deletedAt: null
}).fetch();
console.log("Netwoks to restart ", networks.map(i => i.instanceId));
networks.forEach(network => {
bullSystem.addJob("repull-image", {
instanceId: network.instanceId,
locationCode: network.locationCode,
newImageTag: job.data.imageTag,
container: job.data.container
});
});
resolve();
});
});
bullSystem.bullJobs.process("start-repull-images", 1, processFunction);
bullSystem.bullJobs.process("start-repull-images", 1, processFunction);
};
6 changes: 3 additions & 3 deletions imports/modules/config/kube-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"dev": {
"us-west-2": {
"masterApiHost": "https://k8s-dev-us-west-2-api.blockcluster.io",
"workerNodeIP": "18.237.94.215",
"workerNodeIP": "35.161.9.16",
"locationCode": "us-west-2",
"locationName": "US West (Oregon)",
"auth": {
Expand All @@ -13,7 +13,7 @@
},
"ap-south-1": {
"masterApiHost": "https://k8s-dev-ap-south-1-api.blockcluster.io",
"workerNodeIP": "13.126.10.140",
"workerNodeIP": "13.232.213.158",
"locationCode": "ap-south-1",
"locationName": "Asia Pacific South (Mumbai)",
"auth": {
Expand All @@ -25,7 +25,7 @@
"staging": {
"us-west-2": {
"masterApiHost": "https://k8s-dev-us-west-2-api.blockcluster.io",
"workerNodeIP": "18.237.94.215",
"workerNodeIP": "35.161.9.16",
"locationCode": "us-west-2",
"locationName": "US West (Oregon)",
"auth": {
Expand Down
2 changes: 1 addition & 1 deletion imports/modules/config/local.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
apiHost: "localhost:3000",
kubeRestApiHost: "https://k8s-dev-us-west-2-api.blockcluster.io",
firewallPort: "31988",
workerNodeIP: "18.237.94.215",
workerNodeIP: "35.161.9.16",
namespace: "dev",
razorpay: {
id: 'rzp_test_RfYYCpLXMKzUmF',
Expand Down
2 changes: 1 addition & 1 deletion imports/ui/pages/admin/networks/Details.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class NetworkList extends Component {
if (!config) {
return null;
}
return `${config.cpu >= 100 ? config.cpu / 100 : config.cpu} vCPU | ${config.ram} GB | ${config.disk} GB`;
return `${config.cpu >= 100 ? config.cpu / 1000 : config.cpu} vCPU | ${config.ram} GB | ${config.disk} GB`;
};

getNetworkTypeName = config => {
Expand Down
12 changes: 6 additions & 6 deletions server/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,17 @@ function getNodeConfig(networkConfig, userId) {
return nodeConfig;
}

function getContainerResourceLimits({cpu, ram }){
function getContainerResourceLimits({cpu, ram, isJoining }){
const CpuPercentage = {
mongo: 0.15,
impulse: 0.20,
dynamo: 0.65
impulse: isJoining ? 0 : 0.20,
dynamo: isJoining ? 0.85 : 0.65
}

const RamPercentage = {
mongo: 0.05,
impulse: 0.15,
dynamo: 0.8
impulse: isJoining? 0 : 0.15,
dynamo: isJoining ? 0.95 : 0.8
}

const config = {
Expand Down Expand Up @@ -772,7 +772,7 @@ Meteor.methods({
throw new Meteor.Error("Invalid Network Configuration");
}

const resourceConfig = getContainerResourceLimits({cpu: nodeConfig.cpu, ram: nodeConfig.ram});
const resourceConfig = getContainerResourceLimits({cpu: nodeConfig.cpu, ram: nodeConfig.ram, isJoining: true});

Networks.insert({
"instanceId": instanceId,
Expand Down