@@ -3,6 +3,8 @@ import stream = require('stream');
33
44import { KubeConfig } from './config' ;
55import { WebSocketHandler } from './web-socket-handler' ;
6+ import { connection } from 'websocket' ;
7+ import { resolve } from 'url' ;
68
79export class Attach {
810 public 'handler' : WebSocketHandler ;
@@ -13,7 +15,7 @@ export class Attach {
1315
1416 public attach ( namespace : string , podName : string , containerName : string ,
1517 stdout : stream . Writable | any , stderr : stream . Writable | any , stdin : stream . Readable | any ,
16- tty : boolean ) {
18+ tty : boolean ) : Promise < void > {
1719 const query = {
1820 container : containerName ,
1921 stderr : stderr != null ,
@@ -23,8 +25,12 @@ export class Attach {
2325 } ;
2426 const queryStr = querystring . stringify ( query ) ;
2527 const path = `/api/v1/namespaces/${ namespace } /pods/${ podName } /attach?${ queryStr } ` ;
26- this . handler . connect ( path , null , ( streamNum : number , buff : Buffer ) => {
28+ const promise = this . handler . connect ( path , null , ( streamNum : number , buff : Buffer ) => {
2729 WebSocketHandler . handleStandardStreams ( streamNum , buff , stdout , stderr ) ;
2830 } ) ;
31+ const result = new Promise < void > ( ( resolvePromise , reject ) => {
32+ promise . then ( ( ) => resolvePromise ( ) , ( err ) => reject ( err ) ) ;
33+ } ) ;
34+ return result ;
2935 }
3036}
0 commit comments