@@ -37,7 +37,7 @@ export class Kubero {
3737 private podLogStreams : string [ ] = [ ]
3838 public config : IKuberoConfig ;
3939 private audit : Audit ;
40- private execStreams : { [ key : string ] : { websocket : WebSocket , stream : Stream } } = { } ;
40+ private execStreams : { [ key : string ] : { websocket : WebSocket , stream : any } } = { } ;
4141
4242 constructor ( io : Server , audit : Audit ) {
4343 this . config = this . loadConfig ( process . env . KUBERO_CONFIG_PATH as string || './config.yaml' ) ;
@@ -52,6 +52,22 @@ export class Kubero {
5252 debug . debug ( 'Kubero Config: ' + JSON . stringify ( this . config ) ) ;
5353
5454 this . audit = audit ;
55+
56+
57+ this . _io . on ( 'connection' , client => {
58+ client . on ( 'terminal' , ( data : any ) => {
59+ //console.log('terminal input', data.data);
60+ //console.log('ws.OPEN', ws.readyState == ws.OPEN);
61+ //console.log(ws.url);
62+ //console.log(ws.eventNames());
63+ //execStream.write(data.data);
64+ if ( this . execStreams [ data . room ] ) {
65+ this . execStreams [ data . room ] . stream . write ( data . data ) ;
66+ }
67+ //this.execStreams[data.room].stream.write(data.data);
68+ }
69+ ) }
70+ ) ;
5571 }
5672
5773 public getKubernetesVersion ( ) {
@@ -981,7 +997,7 @@ export class Kubero {
981997 public async execInContainer ( pipelineName : string , phaseName : string , appName : string , podName : string , containerName : string , command : string , user : User ) {
982998 const contextName = this . getContext ( pipelineName , phaseName ) ;
983999 if ( contextName ) {
984- const streamname = `${ pipelineName } -${ phaseName } -${ appName } -${ podName } -${ containerName } ` ;
1000+ const streamname = `${ pipelineName } -${ phaseName } -${ appName } -${ podName } -${ containerName } -terminal ` ;
9851001
9861002 if ( process . env . KUBERO_READONLY == 'true' ) {
9871003 console . log ( 'KUBERO_READONLY is set to true, not deleting app' ) ;
@@ -993,8 +1009,12 @@ export class Kubero {
9931009 console . log ( 'execInContainer: execStream already running' ) ;
9941010 return ;
9951011 } else {
996- console . log ( 'execInContainer: execStream already running but not open, deleting' ) ;
1012+ console . log ( 'CLOSED' , this . execStreams [ streamname ] . websocket . CLOSED )
1013+ console . log ( 'execInContainer: execStream already running but not open, deleting :' , this . execStreams [ streamname ] . websocket . readyState ) ;
9971014 delete this . execStreams [ streamname ] ;
1015+
1016+ // wait a bit to make sure the stream is closed
1017+ await new Promise ( resolve => setTimeout ( resolve , 3000 ) ) ;
9981018 }
9991019 }
10001020
@@ -1014,29 +1034,14 @@ export class Kubero {
10141034
10151035 let stream = {
10161036 websocket : ws as unknown as WebSocket ,
1017- stream : execStream as Stream
1037+ stream : execStream
10181038 } ;
10191039 this . execStreams [ streamname ] = stream ;
10201040
10211041 // sending the terminal output to the client
10221042 ws . on ( 'message' , ( data : Buffer ) => {
1023- const roomname = `${ pipelineName } -${ phaseName } -${ appName } -${ podName } -${ containerName } -terminal` ;
1024- //console.log('execInContainer message', roomname, data.toString());
1025- this . _io . to ( roomname ) . emit ( 'consoleresponse' , data . toString ( ) )
1043+ this . _io . to ( streamname ) . emit ( 'consoleresponse' , data . toString ( ) )
10261044 } ) ;
1027-
1028- // Sending the terminal input to the container
1029- this . _io . on ( 'connection' , client => {
1030- //console.log('connection');
1031- client . on ( 'terminal' , ( data : any ) => {
1032- //console.log('terminal input', data.data);
1033- //console.log('ws.OPEN', ws.readyState == ws.OPEN);
1034- //console.log(ws.url);
1035- //console.log(ws.eventNames());
1036- execStream . write ( data . data ) ;
1037- }
1038- ) }
1039- ) ;
10401045 }
10411046 }
10421047
@@ -1497,7 +1502,7 @@ export class Kubero {
14971502 }
14981503 }
14991504
1500- public async getPods ( pipelineName : string , phaseName : string ) : Promise < Workload [ ] > {
1505+ public async getPods ( pipelineName : string , phaseName : string , appName : string ) : Promise < Workload [ ] > {
15011506 const contextName = this . getContext ( pipelineName , phaseName ) ;
15021507 const namespace = pipelineName + '-' + phaseName ;
15031508
@@ -1508,6 +1513,11 @@ export class Kubero {
15081513 const workload = await this . kubectl . getPods ( namespace , contextName ) ;
15091514 //return workload
15101515 for ( const pod of workload ) {
1516+ // check if app label name starts with appName
1517+ if ( ! pod . metadata ?. generateName ?. startsWith ( appName + '-kuberoapp' ) ) {
1518+ continue ;
1519+ }
1520+
15111521 let workload = {
15121522 name : pod . metadata ?. name ,
15131523 namespace : pod . metadata ?. namespace ,
0 commit comments