@@ -8,6 +8,7 @@ import * as AutoscalingV1 from "../autoscaling@v1/structs.ts";
8
8
import * as PolicyV1 from "../policy@v1/structs.ts" ;
9
9
import * as MetaV1 from "../meta@v1/structs.ts" ;
10
10
import * as CoreV1 from "./structs.ts" ;
11
+ import * as tunnels from "../../tunnels.ts" ;
11
12
12
13
export class CoreV1Api {
13
14
#client: c . RestClient ;
@@ -1332,50 +1333,31 @@ export class CoreV1NamespacedApi {
1332
1333
return CoreV1 . toPod ( resp ) ;
1333
1334
}
1334
1335
1335
- async connectGetPodAttach ( name : string , opts : {
1336
+ async tunnelPodAttach ( name : string , opts : {
1336
1337
container ?: string ;
1337
1338
stderr ?: boolean ;
1338
1339
stdin ?: boolean ;
1339
- stdout ? : boolean ;
1340
+ stdout : boolean ;
1340
1341
tty ?: boolean ;
1341
1342
abortSignal ?: AbortSignal ;
1342
- } = { } ) {
1343
+ } ) {
1343
1344
const query = new URLSearchParams ;
1344
1345
if ( opts [ "container" ] != null ) query . append ( "container" , opts [ "container" ] ) ;
1345
1346
if ( opts [ "stderr" ] != null ) query . append ( "stderr" , opts [ "stderr" ] ? '1' : '0' ) ;
1346
1347
if ( opts [ "stdin" ] != null ) query . append ( "stdin" , opts [ "stdin" ] ? '1' : '0' ) ;
1347
- if ( opts [ "stdout" ] != null ) query . append ( "stdout" , opts [ "stdout" ] ? '1' : '0' ) ;
1348
+ query . append ( "stdout" , opts [ "stdout" ] ? '1' : '0' ) ;
1348
1349
if ( opts [ "tty" ] != null ) query . append ( "tty" , opts [ "tty" ] ? '1' : '0' ) ;
1349
1350
const resp = await this . #client. performRequest ( {
1350
1351
method : "GET" ,
1351
1352
path : `${ this . #root} pods/${ name } /attach` ,
1352
- expectJson : true ,
1353
+ expectTunnel : tunnels . StdioTunnel . supportedProtocols ,
1353
1354
querystring : query ,
1354
1355
abortSignal : opts . abortSignal ,
1355
1356
} ) ;
1356
- }
1357
1357
1358
- async connectPostPodAttach ( name : string , opts : {
1359
- container ?: string ;
1360
- stderr ?: boolean ;
1361
- stdin ?: boolean ;
1362
- stdout ?: boolean ;
1363
- tty ?: boolean ;
1364
- abortSignal ?: AbortSignal ;
1365
- } = { } ) {
1366
- const query = new URLSearchParams ;
1367
- if ( opts [ "container" ] != null ) query . append ( "container" , opts [ "container" ] ) ;
1368
- if ( opts [ "stderr" ] != null ) query . append ( "stderr" , opts [ "stderr" ] ? '1' : '0' ) ;
1369
- if ( opts [ "stdin" ] != null ) query . append ( "stdin" , opts [ "stdin" ] ? '1' : '0' ) ;
1370
- if ( opts [ "stdout" ] != null ) query . append ( "stdout" , opts [ "stdout" ] ? '1' : '0' ) ;
1371
- if ( opts [ "tty" ] != null ) query . append ( "tty" , opts [ "tty" ] ? '1' : '0' ) ;
1372
- const resp = await this . #client. performRequest ( {
1373
- method : "POST" ,
1374
- path : `${ this . #root} pods/${ name } /attach` ,
1375
- expectJson : true ,
1376
- querystring : query ,
1377
- abortSignal : opts . abortSignal ,
1378
- } ) ;
1358
+ const tunnel = new tunnels . StdioTunnel ( resp , query ) ;
1359
+ await tunnel . ready ;
1360
+ return tunnel ;
1379
1361
}
1380
1362
1381
1363
async createPodBinding ( name : string , body : CoreV1 . Binding , opts : operations . PutOpts = { } ) {
@@ -1437,54 +1419,33 @@ export class CoreV1NamespacedApi {
1437
1419
return PolicyV1 . toEviction ( resp ) ;
1438
1420
}
1439
1421
1440
- async connectGetPodExec ( name : string , opts : {
1441
- command ?: string ;
1422
+ async tunnelPodExec ( name : string , opts : {
1423
+ command : Array < string > ;
1442
1424
container ?: string ;
1443
1425
stderr ?: boolean ;
1444
1426
stdin ?: boolean ;
1445
- stdout ? : boolean ;
1427
+ stdout : boolean ;
1446
1428
tty ?: boolean ;
1447
1429
abortSignal ?: AbortSignal ;
1448
- } = { } ) {
1430
+ } ) {
1449
1431
const query = new URLSearchParams ;
1450
- if ( opts [ "command" ] != null ) query . append ( "command" , opts [ "command" ] ) ;
1432
+ for ( const item of opts [ "command" ] ) query . append ( "command" , item ) ;
1451
1433
if ( opts [ "container" ] != null ) query . append ( "container" , opts [ "container" ] ) ;
1452
1434
if ( opts [ "stderr" ] != null ) query . append ( "stderr" , opts [ "stderr" ] ? '1' : '0' ) ;
1453
1435
if ( opts [ "stdin" ] != null ) query . append ( "stdin" , opts [ "stdin" ] ? '1' : '0' ) ;
1454
- if ( opts [ "stdout" ] != null ) query . append ( "stdout" , opts [ "stdout" ] ? '1' : '0' ) ;
1436
+ query . append ( "stdout" , opts [ "stdout" ] ? '1' : '0' ) ;
1455
1437
if ( opts [ "tty" ] != null ) query . append ( "tty" , opts [ "tty" ] ? '1' : '0' ) ;
1456
1438
const resp = await this . #client. performRequest ( {
1457
1439
method : "GET" ,
1458
1440
path : `${ this . #root} pods/${ name } /exec` ,
1459
- expectJson : true ,
1441
+ expectTunnel : tunnels . StdioTunnel . supportedProtocols ,
1460
1442
querystring : query ,
1461
1443
abortSignal : opts . abortSignal ,
1462
1444
} ) ;
1463
- }
1464
1445
1465
- async connectPostPodExec ( name : string , opts : {
1466
- command ?: string ;
1467
- container ?: string ;
1468
- stderr ?: boolean ;
1469
- stdin ?: boolean ;
1470
- stdout ?: boolean ;
1471
- tty ?: boolean ;
1472
- abortSignal ?: AbortSignal ;
1473
- } = { } ) {
1474
- const query = new URLSearchParams ;
1475
- if ( opts [ "command" ] != null ) query . append ( "command" , opts [ "command" ] ) ;
1476
- if ( opts [ "container" ] != null ) query . append ( "container" , opts [ "container" ] ) ;
1477
- if ( opts [ "stderr" ] != null ) query . append ( "stderr" , opts [ "stderr" ] ? '1' : '0' ) ;
1478
- if ( opts [ "stdin" ] != null ) query . append ( "stdin" , opts [ "stdin" ] ? '1' : '0' ) ;
1479
- if ( opts [ "stdout" ] != null ) query . append ( "stdout" , opts [ "stdout" ] ? '1' : '0' ) ;
1480
- if ( opts [ "tty" ] != null ) query . append ( "tty" , opts [ "tty" ] ? '1' : '0' ) ;
1481
- const resp = await this . #client. performRequest ( {
1482
- method : "POST" ,
1483
- path : `${ this . #root} pods/${ name } /exec` ,
1484
- expectJson : true ,
1485
- querystring : query ,
1486
- abortSignal : opts . abortSignal ,
1487
- } ) ;
1446
+ const tunnel = new tunnels . StdioTunnel ( resp , query ) ;
1447
+ await tunnel . ready ;
1448
+ return tunnel ;
1488
1449
}
1489
1450
1490
1451
async streamPodLog ( name : string , opts : {
@@ -1544,34 +1505,23 @@ export class CoreV1NamespacedApi {
1544
1505
return new TextDecoder ( 'utf-8' ) . decode ( resp ) ;
1545
1506
}
1546
1507
1547
- async connectGetPodPortforward ( name : string , opts : {
1548
- ports ?: number ;
1508
+ async tunnelPodPortforward ( name : string , opts : {
1509
+ ports ?: Array < number > ;
1549
1510
abortSignal ?: AbortSignal ;
1550
1511
} = { } ) {
1551
1512
const query = new URLSearchParams ;
1552
- if ( opts [ "ports" ] != null ) query . append ( "ports" , String ( opts [ "ports" ] ) ) ;
1513
+ for ( const item of opts [ "ports" ] ?? [ ] ) query . append ( "ports" , String ( item ) ) ;
1553
1514
const resp = await this . #client. performRequest ( {
1554
1515
method : "GET" ,
1555
1516
path : `${ this . #root} pods/${ name } /portforward` ,
1556
- expectJson : true ,
1517
+ expectTunnel : tunnels . PortforwardTunnel . supportedProtocols ,
1557
1518
querystring : query ,
1558
1519
abortSignal : opts . abortSignal ,
1559
1520
} ) ;
1560
- }
1561
1521
1562
- async connectPostPodPortforward ( name : string , opts : {
1563
- ports ?: number ;
1564
- abortSignal ?: AbortSignal ;
1565
- } = { } ) {
1566
- const query = new URLSearchParams ;
1567
- if ( opts [ "ports" ] != null ) query . append ( "ports" , String ( opts [ "ports" ] ) ) ;
1568
- const resp = await this . #client. performRequest ( {
1569
- method : "POST" ,
1570
- path : `${ this . #root} pods/${ name } /portforward` ,
1571
- expectJson : true ,
1572
- querystring : query ,
1573
- abortSignal : opts . abortSignal ,
1574
- } ) ;
1522
+ const tunnel = new tunnels . PortforwardTunnel ( resp , query ) ;
1523
+ await tunnel . ready ;
1524
+ return tunnel ;
1575
1525
}
1576
1526
1577
1527
proxyPodRequest ( podName : string , opts : c . ProxyOptions & { expectStream : true ; expectJson : true } ) : Promise < ReadableStream < c . JSONValue > > ;
0 commit comments