@@ -21,110 +21,110 @@ spacesController.clusterIdLookup = (req, res, next) => {
21
21
} )
22
22
}
23
23
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
+
24
48
spacesController . addNamespace = ( req , res , next ) => {
25
49
const { hostNamespace } = req . body ;
26
50
const { clusterId } = res . locals ;
27
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?
28
53
const query = 'INSERT INTO namespaces (name, cluster_id) VALUES ($1, $2)' ;
29
54
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
+ }
64
64
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
+ }
78
78
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
+ }
92
92
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
+ }
102
102
103
- spacesController . fetchSpaces = ( req , res , next ) => {
104
- const query =
105
- `
103
+ spacesController . fetchSpaces = ( req , res , next ) => {
104
+ const query =
105
+ `
106
106
SELECT * FROM namespaces;
107
107
`
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
+ }
115
115
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 = `
120
120
SELECT name FROM namespaces WHERE team_id = $1;
121
121
`
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
+ }
129
129
130
- module . exports = spacesController ;
130
+ module . exports = spacesController ;
0 commit comments