Skip to content

Commit e2d331c

Browse files
committed
added team_id column in namespaces schema
1 parent 3722a64 commit e2d331c

File tree

2 files changed

+92
-91
lines changed

2 files changed

+92
-91
lines changed

KlustrSchema2.sql

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ CREATE TABLE "namespaces" (
1717
"_id" smallserial PRIMARY KEY,
1818
"name" varchar,
1919
"cluster_id" smallint
20+
"team_id" smallint
2021
);
2122

2223
CREATE TABLE "vclusters" (

server/controllers/spacesController.js

+91-91
Original file line numberDiff line numberDiff line change
@@ -21,110 +21,110 @@ spacesController.clusterIdLookup = (req, res, next) => {
2121
})
2222
}
2323

24+
// spacesController.addNamespace = (req, res, next) => {
25+
// const { hostNamespace } = req.body;
26+
// const { clusterId } = res.locals;
27+
// const params = [hostNamespace, clusterId];
28+
// const query = 'INSERT INTO namespaces (name, cluster_id) VALUES ($1, $2)';
29+
30+
spacesController.clusterIdLookup = (req, res, next) => {
31+
const { hostCluster } = req.body;
32+
const params = [hostCluster];
33+
const query = `SELECT _id FROM clusters WHERE name='$1'`;
34+
db.query(query, params)
35+
.then((data) => {
36+
console.log(data.rows[0]._id);
37+
res.locals.clusterId = data.rows[0]._id;
38+
return next();
39+
})
40+
.catch((err) => {
41+
return next({
42+
log: `Error in spacesController.clusterIdLookup: ${err}`,
43+
message: `Error looking up cluster id`
44+
})
45+
})
46+
}
47+
2448
spacesController.addNamespace = (req, res, next) => {
2549
const { hostNamespace } = req.body;
2650
const { clusterId } = res.locals;
2751
const params = [hostNamespace, clusterId];
52+
// if the team ID is a foreign key, do we need to add this in or is it automatic?
2853
const query = 'INSERT INTO namespaces (name, cluster_id) VALUES ($1, $2)';
2954

30-
spacesController.clusterIdLookup = (req, res, next) => {
31-
const { hostCluster } = req.body;
32-
const params = [hostCluster];
33-
const query = `SELECT _id FROM clusters WHERE name='$1'`;
34-
db.query(query, params)
35-
.then((data) => {
36-
console.log(data.rows[0]._id);
37-
res.locals.clusterId = data.rows[0]._id;
38-
return next();
39-
})
40-
.catch((err) => {
41-
return next({
42-
log: `Error in spacesController.clusterIdLookup: ${err}`,
43-
message: `Error looking up cluster id`
44-
})
45-
})
46-
}
47-
48-
spacesController.addNamespace = (req, res, next) => {
49-
const { hostNamespace } = req.body;
50-
const { clusterId } = res.locals;
51-
const params = [hostNamespace, clusterId];
52-
// if the team ID is a foreign key, do we need to add this in or is it automatic?
53-
const query = 'INSERT INTO namespaces (name, cluster_id) VALUES ($1, $2)';
54-
55-
db.query(query, params)
56-
.then((data) => {
57-
console.log(data)
58-
return next();
59-
})
60-
.catch((err) => {
61-
return next({ log: `Error in spacesController.addNamespace: ${err}` });
62-
})
63-
}
55+
db.query(query, params)
56+
.then((data) => {
57+
console.log(data)
58+
return next();
59+
})
60+
.catch((err) => {
61+
return next({ log: `Error in spacesController.addNamespace: ${err}` });
62+
})
63+
}
6464

65-
spacesController.createNamespace = (req, res, next) => {
66-
console.log(req.body)
67-
const { clusterName, hostNamespace } = req.body;
68-
runTerminalCommand(gcloud.getCredentials(clusterName))
69-
.then((data) => {
70-
console.log(data)
71-
runTerminalCommand(kubectl.createNamespace(hostNamespace))
72-
.then((data) => {
73-
console.log(data)
74-
return next();
75-
})
76-
})
77-
}
65+
spacesController.createNamespace = (req, res, next) => {
66+
console.log(req.body)
67+
const { clusterName, hostNamespace } = req.body;
68+
runTerminalCommand(gcloud.getCredentials(clusterName))
69+
.then((data) => {
70+
console.log(data)
71+
runTerminalCommand(kubectl.createNamespace(hostNamespace))
72+
.then((data) => {
73+
console.log(data)
74+
return next();
75+
})
76+
})
77+
}
7878

79-
spacesController.deploy = (req, res, next) => {
80-
const { deploymentName, hostNamespace, imageFile } = req.body;
81-
runTerminalCommand(kubectl.deployImage(deploymentName, hostNamespace, imageFile))
82-
.then(() => {
83-
runTerminalCommand(kubectl.expose(deploymentName, hostNamespace))
84-
.then(() => runTerminalCommand(`kubectl get services -n ${hostNamespace} ${deploymentName}`))
85-
.then((data) => {
86-
console.log(data);
87-
res.locals.jeff = data;
88-
return next();
89-
})
90-
})
91-
}
79+
spacesController.deploy = (req, res, next) => {
80+
const { deploymentName, hostNamespace, imageFile } = req.body;
81+
runTerminalCommand(kubectl.deployImage(deploymentName, hostNamespace, imageFile))
82+
.then(() => {
83+
runTerminalCommand(kubectl.expose(deploymentName, hostNamespace))
84+
.then(() => runTerminalCommand(`kubectl get services -n ${hostNamespace} ${deploymentName}`))
85+
.then((data) => {
86+
console.log(data);
87+
res.locals.jeff = data;
88+
return next();
89+
})
90+
})
91+
}
9292

93-
spacesController.getExternalIp = (req, res, next) => {
94-
const { deploymentName, hostNamespace } = req.body;
95-
console.log(deploymentName);
96-
runTerminalCommand(`kubectl get services -n ${hostNamespace} ${deploymentName}`)
97-
.then((data) => {
98-
res.locals.getServices = data;
99-
return next()
100-
})
101-
}
93+
spacesController.getExternalIp = (req, res, next) => {
94+
const { deploymentName, hostNamespace } = req.body;
95+
console.log(deploymentName);
96+
runTerminalCommand(`kubectl get services -n ${hostNamespace} ${deploymentName}`)
97+
.then((data) => {
98+
res.locals.getServices = data;
99+
return next()
100+
})
101+
}
102102

103-
spacesController.fetchSpaces = (req, res, next) => {
104-
const query =
105-
`
103+
spacesController.fetchSpaces = (req, res, next) => {
104+
const query =
105+
`
106106
SELECT * FROM namespaces;
107107
`
108-
db.query(query)
109-
.then((data) => {
110-
console.log('fetchspaces data', data)
111-
res.locals.spaces = data.rows
112-
return next();
113-
})
114-
}
108+
db.query(query)
109+
.then((data) => {
110+
console.log('fetchspaces data', data)
111+
res.locals.spaces = data.rows
112+
return next();
113+
})
114+
}
115115

116-
spacesController.fetchNamespaces = (req, res, next) => {
117-
const { teamId } = res.locals;
118-
const params = [teamId]
119-
const query = `
116+
spacesController.fetchNamespaces = (req, res, next) => {
117+
const { teamId } = res.locals;
118+
const params = [teamId]
119+
const query = `
120120
SELECT name FROM namespaces WHERE team_id = $1;
121121
`
122-
db.query(query, params)
123-
.then((data) => {
124-
console.log(data)
125-
res.locals.namespaces = data.rows
126-
return next();
127-
})
128-
}
122+
db.query(query, params)
123+
.then((data) => {
124+
console.log(data)
125+
res.locals.namespaces = data.rows
126+
return next();
127+
})
128+
}
129129

130-
module.exports = spacesController;
130+
module.exports = spacesController;

0 commit comments

Comments
 (0)