1
1
import debug from 'debug' ;
2
2
import { Server } from "socket.io" ;
3
- import { IApp , IPipeline , IKubectlAppList , IKubectlPipelineList , IPodSize , IKuberoConfig } from './types' ;
3
+ import { IApp , IPipeline , IKubectlAppList , IKubectlPipelineList , IKubectlApp , IPodSize , IKuberoConfig } from './types' ;
4
4
import { App } from './modules/application' ;
5
5
import { GithubApi } from './github/api' ;
6
6
import { IAddon , IAddonMinimal } from './modules/addons' ;
@@ -68,18 +68,23 @@ export class Keroku {
68
68
public getContexts ( ) {
69
69
return this . kubectl . getContexts ( )
70
70
}
71
+ public getPipelineStateList ( ) {
72
+ return this . pipelineStateList ;
73
+ }
71
74
72
- public getContext ( pipelineName : string , phaseName : string ) : string | undefined {
75
+ public getContext ( pipelineName : string , phaseName : string ) : string {
76
+ let context : string = 'missing-' + pipelineName + '-' + phaseName ;
73
77
for ( const pipeline of this . pipelineStateList ) {
74
78
if ( pipeline . name == pipelineName ) {
75
79
for ( const phase of pipeline . phases ) {
76
80
if ( phase . name == phaseName ) {
77
81
//this.kubectl.setCurrentContext(phase.context);
78
- return phase . context ;
82
+ context = phase . context ;
79
83
}
80
84
}
81
85
}
82
86
}
87
+ return context
83
88
}
84
89
85
90
public async setContext ( pipelineName : string , phaseName : string ) : Promise < boolean > {
@@ -168,7 +173,7 @@ export class Keroku {
168
173
169
174
// create a new app in a specified pipeline and phase
170
175
public async newApp ( app : App ) {
171
- debug . debug ( 'create App: ' + app . name + ' in ' + app . pipeline + ' phase: ' + app . phase ) ;
176
+ debug . log ( 'create App: ' + app . name + ' in ' + app . pipeline + ' phase: ' + app . phase ) ;
172
177
const contextName = this . getContext ( app . pipeline , app . phase ) ;
173
178
if ( contextName ) {
174
179
await this . kubectl . createApp ( app , contextName ) ;
@@ -181,7 +186,7 @@ export class Keroku {
181
186
}
182
187
183
188
// update an app in a pipeline and phase
184
- public async updateApp ( app : App , envvars : { name : string ; value : string ; } [ ] , resourceVersion : string ) { //TODO remove env vars
189
+ public async updateApp ( app : App , resourceVersion : string ) {
185
190
debug . debug ( 'update App: ' + app . name + ' in ' + app . pipeline + ' phase: ' + app . phase ) ;
186
191
await this . setContext ( app . pipeline , app . phase ) ;
187
192
@@ -229,45 +234,32 @@ export class Keroku {
229
234
}
230
235
231
236
// list all apps in a pipeline
232
- public async listApps ( pipelineName : string ) {
237
+ public async getPipelineWithApps ( pipelineName : string ) {
233
238
debug . debug ( 'listApps in ' + pipelineName ) ;
234
239
await this . kubectl . setCurrentContext ( process . env . KUBERO_CONTEXT || 'default' ) ;
235
- let kpipeline = await this . kubectl . getPipeline ( pipelineName ) ;
236
-
240
+ const kpipeline = await this . kubectl . getPipeline ( pipelineName ) ;
237
241
let pipeline = kpipeline . spec
238
- //await pipeline.phases.forEach(async (phase, key) => { // does not work, wait for all iterations to finish
239
- await Promise . all ( pipeline . phases . map ( async ( phase , key ) => {
240
-
241
- console . log ( phase . name )
242
- const namespace = pipeline . name + '-' + phase . name ;
243
- let apps = await this . kubectl . getAppsList ( namespace , phase . context ) ;
244
-
245
- pipeline . phases [ key ] . apps = [ ] ;
246
- for ( const app of apps . items ) {
247
- pipeline . phases [ key ] . apps . push ( app . spec ) ;
248
- }
249
-
250
- } ) ) ;
251
- /*
252
- if (pipeline.reviewapps) {
253
-
254
- let review = {
255
- "enabled": true,
256
- "name": "review",
257
- "context": "", // Importand TODO: get the context from the pipeline
258
- "apps": Array()
259
- }
260
242
261
- let apps = await this.kubectl.getAppsList(pipelineName+"-review");
262
- for (const app of apps.items) {
263
- review.apps.push(app.spec);
243
+ if ( pipeline ) {
244
+ for ( const phase of pipeline . phases ) {
245
+ if ( phase . enabled == true ) {
246
+
247
+ const contextName = this . getContext ( pipelineName , phase . name ) ;
248
+ if ( contextName ) {
249
+ const namespace = pipelineName + '-' + phase . name ;
250
+ let apps = await this . kubectl . getAppsList ( namespace , contextName ) ;
251
+
252
+ let appslist = new Array ( ) ;
253
+ for ( const app of apps . items ) {
254
+ appslist . push ( app . spec ) ;
255
+ }
256
+ // @ts -expect-error ts(2532) FIXME: Object is possibly 'undefined'.
257
+ pipeline . phases . find ( p => p . name == phase . name ) . apps = appslist ;
258
+
259
+ }
260
+ }
264
261
}
265
-
266
- pipeline.phases.unshift(review);
267
-
268
262
}
269
- */
270
-
271
263
return pipeline ;
272
264
}
273
265
0 commit comments