From 6ced43e83c0da95ae5c0249e50b876739b5f89b8 Mon Sep 17 00:00:00 2001 From: Anmol Date: Fri, 14 Jun 2024 15:23:24 +0530 Subject: [PATCH] add relayer port-forwarding (#481) --- clients/js/packages/client/src/client.ts | 36 ++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/clients/js/packages/client/src/client.ts b/clients/js/packages/client/src/client.ts index 2acf79e28..dd06319f6 100644 --- a/clients/js/packages/client/src/client.ts +++ b/clients/js/packages/client/src/client.ts @@ -7,7 +7,7 @@ import * as os from 'os'; import { dirname, resolve } from 'path'; import * as shell from 'shelljs'; -import { Chain, Script, StarshipConfig } from './config'; +import {Chain, Relayer, Script, StarshipConfig} from './config'; import { Ports } from './config'; import { dependencies as defaultDependencies, Dependency } from "./deps"; import { readAndParsePackageJson } from './package'; @@ -39,7 +39,11 @@ export interface PodPorts { chains?: { defaultPorts?: Ports, [chainName: string]: Ports - } + }, + relayers?: { + defaultPorts?: Ports, + [relayerName: string]: Ports + }, } // TODO talk to Anmol about moving these into yaml, if not already possible? @@ -60,6 +64,12 @@ const defaultPorts: PodPorts = { faucet: 8000, cometmock: 22331, } + }, + relayers: { + defaultPorts: { + rest: 3000, + exposer: 8081, + } } }; export interface StarshipClientI { @@ -433,6 +443,20 @@ export class StarshipClient implements StarshipClientI { } } + private forwardPortRelayer(relayer: Relayer, localPort: number, externalPort: number): void { + if (localPort !== undefined && externalPort !== undefined) { + this.exec([ + "kubectl", "port-forward", + `pods/${relayer.name}-0`, + `${localPort}:${externalPort}`, + ...this.getArgs(), + ">", "/dev/null", + "2>&1", "&" + ]); + this.log(chalk.yellow(`Forwarded ${relayer.name}: local ${localPort} -> target (host) ${externalPort}`)); + } + } + private forwardPortService(serviceName: string, localPort: number, externalPort: number): void { if (localPort !== undefined && externalPort !== undefined) { this.exec([ @@ -455,7 +479,7 @@ export class StarshipClient implements StarshipClientI { this.stopPortForward(); this.log("Starting new port forwarding..."); - this.config.chains.forEach(chain => { + this.config.chains?.forEach(chain => { const chainPodPorts = this.podPorts.chains[chain.name] || this.podPorts.chains.defaultPorts; if (chain.cometmock?.enabled) { @@ -469,6 +493,12 @@ export class StarshipClient implements StarshipClientI { if (chain.ports?.faucet) this.forwardPort(chain, chain.ports.faucet, chainPodPorts.faucet); }); + this.config.relayers?.forEach(relayer => { + const relayerPodPorts = this.podPorts.relayers[relayer.name] || this.podPorts.relayers.defaultPorts; + if (relayer.ports?.rest) this.forwardPortRelayer(relayer, relayer.ports.rest, relayerPodPorts.rest); + if (relayer.ports?.exposer) this.forwardPortRelayer(relayer, relayer.ports.exposer, relayerPodPorts.exposer); + }); + if (this.config.registry?.enabled) { this.forwardPortService("registry", this.config.registry.ports.rest, this.podPorts.registry.rest); this.forwardPortService("registry", this.config.registry.ports.grpc, this.podPorts.registry.grpc);