Skip to content

Commit

Permalink
add relayer port-forwarding (#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
Anmol1696 authored Jun 14, 2024
1 parent ffd17ea commit 6ced43e
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions clients/js/packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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?
Expand All @@ -60,6 +64,12 @@ const defaultPorts: PodPorts = {
faucet: 8000,
cometmock: 22331,
}
},
relayers: {
defaultPorts: {
rest: 3000,
exposer: 8081,
}
}
};
export interface StarshipClientI {
Expand Down Expand Up @@ -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([
Expand All @@ -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) {
Expand All @@ -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);
Expand Down

0 comments on commit 6ced43e

Please sign in to comment.