@@ -3,6 +3,8 @@ import stream = require('stream');
3
3
4
4
import { KubeConfig } from './config' ;
5
5
import { WebSocketHandler } from './web-socket-handler' ;
6
+ import { connection } from 'websocket' ;
7
+ import { resolve } from 'url' ;
6
8
7
9
export class Attach {
8
10
public 'handler' : WebSocketHandler ;
@@ -13,7 +15,7 @@ export class Attach {
13
15
14
16
public attach ( namespace : string , podName : string , containerName : string ,
15
17
stdout : stream . Writable | any , stderr : stream . Writable | any , stdin : stream . Readable | any ,
16
- tty : boolean ) {
18
+ tty : boolean ) : Promise < void > {
17
19
const query = {
18
20
container : containerName ,
19
21
stderr : stderr != null ,
@@ -23,8 +25,12 @@ export class Attach {
23
25
} ;
24
26
const queryStr = querystring . stringify ( query ) ;
25
27
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 ) => {
27
29
WebSocketHandler . handleStandardStreams ( streamNum , buff , stdout , stderr ) ;
28
30
} ) ;
31
+ const result = new Promise < void > ( ( resolvePromise , reject ) => {
32
+ promise . then ( ( ) => resolvePromise ( ) , ( err ) => reject ( err ) ) ;
33
+ } ) ;
34
+ return result ;
29
35
}
30
36
}
0 commit comments