Skip to content

Commit

Permalink
feat: more ergonomic RPC URL setting (#4413)
Browse files Browse the repository at this point in the history
### Description

- Updates `scripts/secret-rpc-urls/set-rpc-urls.ts` to:
  - Interactively prompt for what RPC URLs to use
  - If desired, update K8s consumers (secrets & reset pods)

Usage:
```
yarn tsx ./scripts/secret-rpc-urls/set-rpc-urls.ts -e mainnet3 --chain lisk
```

or even
```
yarn tsx ./scripts/secret-rpc-urls/set-rpc-urls.ts -e mainnet3 --chains lisk zircuit
```

Removes `set-rpc-urls-from-registry` in favor of this new command, which
lets you do this as well.

Note that atm it doesn't consider warp monitors as dependent k8s
resources. This is because we haven't really defined infrastructure as
code for these -- the deployments that exist are kinda manually created
by passing in a config file. This should change but didn't feel
appropriate in this PR

The meatiest changes are in utils/rpcUrls.ts and utils/k8s.ts, the rest
were kinda drivebys to accommodate this

### Drive-by changes

- Various tweaks to labels used throughout k8s to be a bit more uniform
- Refactored a lot of helm related scripts to use `HelmManager` as a
superclass

### Related issues

<!--
- Fixes #[issue number here]
-->

### Backward compatibility

<!--
Are these changes backward compatible? Are there any infrastructure
implications, e.g. changes that would prohibit deploying older commits
using this infra tooling?

Yes/No
-->

### Testing

<!--
What kind of testing have these changes undergone?

None/Manual/Unit Tests
-->
  • Loading branch information
tkporter authored Sep 4, 2024
1 parent 88589eb commit b1d8bb8
Show file tree
Hide file tree
Showing 22 changed files with 1,005 additions and 409 deletions.
2 changes: 2 additions & 0 deletions typescript/infra/helm/helloworld-kathy/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Common labels
{{- define "hyperlane.labels" -}}
helm.sh/chart: {{ include "hyperlane.chart" . }}
hyperlane/deployment: {{ .Values.hyperlane.runEnv | quote }}
hyperlane/context: {{ .Values.hyperlane.context | quote }}
app.kubernetes.io/component: kathy
{{ include "hyperlane.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ kind: Pod
metadata:
name: {{ include "hyperlane.fullname" . }}-cycle-once-{{ (randAlphaNum 4 | nospace | lower) }}
labels: &metadata_labels
hyperlane/deployment: {{ .Values.hyperlane.runEnv | quote }}
hyperlane/context: {{ .Values.hyperlane.context | quote }}
app.kubernetes.io/component: kathy
{{- include "hyperlane.labels" . | nindent 4 }}
spec:
restartPolicy: Never
containers:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ kind: StatefulSet
metadata:
name: {{ include "hyperlane.fullname" . }}
labels: &metadata_labels
hyperlane/deployment: {{ .Values.hyperlane.runEnv | quote }}
hyperlane/context: {{ .Values.hyperlane.context | quote }}
app.kubernetes.io/component: kathy
{{- include "hyperlane.labels" . | nindent 4 }}
spec:
selector:
matchLabels: *metadata_labels
Expand Down
3 changes: 3 additions & 0 deletions typescript/infra/helm/key-funder/templates/cron-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ spec:
backoffLimit: 0
activeDeadlineSeconds: 14400 # 60 * 60 * 4 seconds = 4 hours
template:
metadata:
labels:
{{- include "hyperlane.labels" . | nindent 12 }}
spec:
restartPolicy: Never
containers:
Expand Down
2 changes: 2 additions & 0 deletions typescript/infra/helm/warp-routes/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Common labels
{{- define "hyperlane.labels" -}}
helm.sh/chart: {{ include "hyperlane.chart" . }}
hyperlane/deployment: {{ .Values.hyperlane.runEnv | quote }}
hyperlane/context: {{ .Values.hyperlane.context | quote }}
app.kubernetes.io/component: warp-routes
{{ include "hyperlane.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ kind: StatefulSet
metadata:
name: {{ include "hyperlane.fullname" . }}
labels: &metadata_labels
hyperlane/deployment: {{ .Values.hyperlane.runEnv | quote }}
hyperlane/context: {{ .Values.hyperlane.context | quote }}
app.kubernetes.io/component: warp-routes
{{- include "hyperlane.labels" . | nindent 4 }}
spec:
selector:
matchLabels: *metadata_labels
Expand Down
1 change: 1 addition & 0 deletions typescript/infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@hyperlane-xyz/registry": "2.5.0",
"@hyperlane-xyz/sdk": "5.1.0",
"@hyperlane-xyz/utils": "5.1.0",
"@inquirer/prompts": "^5.3.8",
"@nomiclabs/hardhat-etherscan": "^3.0.3",
"@safe-global/api-kit": "1.3.0",
"@safe-global/protocol-kit": "1.3.0",
Expand Down
4 changes: 4 additions & 0 deletions typescript/infra/scripts/agent-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ export function withChains<T>(args: Argv<T>) {
);
}

export function withChainsRequired<T>(args: Argv<T>) {
return withChains(args).demandOption('chains');
}

export function withWarpRouteId<T>(args: Argv<T>) {
return args.describe('warpRouteId', 'warp route id').string('warpRouteId');
}
Expand Down
17 changes: 5 additions & 12 deletions typescript/infra/scripts/funding/deploy-key-funder.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
import { Contexts } from '../../config/contexts.js';
import {
getKeyFunderConfig,
runKeyFunderHelmCommand,
} from '../../src/funding/key-funder.js';
import { environment } from '../../config/environments/mainnet3/chains.js';
import { KeyFunderHelmManager } from '../../src/funding/key-funder.js';
import { HelmCommand } from '../../src/utils/helm.js';
import { assertCorrectKubeContext } from '../agent-utils.js';
import { getConfigsBasedOnArgs } from '../core-utils.js';

async function main() {
const { agentConfig, envConfig } = await getConfigsBasedOnArgs();
const { agentConfig, envConfig, context } = await getConfigsBasedOnArgs();
if (agentConfig.context != Contexts.Hyperlane)
throw new Error(
`Invalid context ${agentConfig.context}, must be ${Contexts.Hyperlane}`,
);

await assertCorrectKubeContext(envConfig);

const keyFunderConfig = getKeyFunderConfig(envConfig);

await runKeyFunderHelmCommand(
HelmCommand.InstallOrUpgrade,
agentConfig,
keyFunderConfig,
);
const manager = KeyFunderHelmManager.forEnvironment(environment);
await manager.runHelmCommand(HelmCommand.InstallOrUpgrade);
}

main()
Expand Down
14 changes: 4 additions & 10 deletions typescript/infra/scripts/helloworld/deploy-kathy.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
import { runHelloworldKathyHelmCommand } from '../../src/helloworld/kathy.js';
import { KathyHelmManager } from '../../src/helloworld/kathy.js';
import { HelmCommand } from '../../src/utils/helm.js';
import { assertCorrectKubeContext } from '../agent-utils.js';
import { getConfigsBasedOnArgs } from '../core-utils.js';

import { getHelloWorldConfig } from './utils.js';

async function main() {
const { agentConfig, envConfig, context } = await getConfigsBasedOnArgs();
const { envConfig, environment, context } = await getConfigsBasedOnArgs();
await assertCorrectKubeContext(envConfig);
const kathyConfig = getHelloWorldConfig(envConfig, context).kathy;

await runHelloworldKathyHelmCommand(
HelmCommand.InstallOrUpgrade,
agentConfig,
kathyConfig,
);
const manager = KathyHelmManager.forEnvironment(environment, context);
await manager.runHelmCommand(HelmCommand.InstallOrUpgrade);
}

main()
Expand Down

This file was deleted.

30 changes: 18 additions & 12 deletions typescript/infra/scripts/secret-rpc-urls/set-rpc-urls.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
import { setAndVerifyRpcUrls } from '../../src/utils/rpcUrls.js';
import { getArgs, withChainRequired, withRpcUrls } from '../agent-utils.js';
import { setRpcUrlsInteractive } from '../../src/utils/rpcUrls.js';
import {
assertCorrectKubeContext,
getArgs,
withChainsRequired,
} from '../agent-utils.js';
import { getEnvironmentConfig } from '../core-utils.js';

async function main() {
const { environment, chain, rpcUrls } = await withRpcUrls(
withChainRequired(getArgs()),
).argv;
const { environment, chains } = await withChainsRequired(getArgs())
// For ease of use and backward compatibility, we allow the `chain` argument to be
// singular or plural.
.alias('chain', 'chains').argv;

const rpcUrlsArray = rpcUrls
.split(/,\s*/)
.filter(Boolean) // filter out empty strings
.map((url) => url.trim());
await assertCorrectKubeContext(getEnvironmentConfig(environment));

if (!rpcUrlsArray.length) {
console.error('No rpc urls provided, Exiting.');
if (!chains || chains.length === 0) {
console.error('No chains provided, Exiting.');
process.exit(1);
}

await setAndVerifyRpcUrls(environment, chain, rpcUrlsArray);
for (const chain of chains) {
console.log(`Setting RPC URLs for chain: ${chain}`);
await setRpcUrlsInteractive(environment, chain);
}
}

main()
Expand Down
14 changes: 7 additions & 7 deletions typescript/infra/scripts/warp-routes/deploy-warp-monitor.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import yargs from 'yargs';

import { HelmCommand } from '../../src/utils/helm.js';

import { runWarpRouteHelmCommand } from './helm.js';
import { WarpRouteMonitorHelmManager } from '../../src/warp/helm.js';
import { assertCorrectKubeContext } from '../agent-utils.js';
import { getEnvironmentConfig } from '../core-utils.js';

async function main() {
const { filePath } = await yargs(process.argv.slice(2))
Expand All @@ -15,11 +16,10 @@ async function main() {
.string('filePath')
.parse();

await runWarpRouteHelmCommand(
HelmCommand.InstallOrUpgrade,
'mainnet3',
filePath,
);
await assertCorrectKubeContext(getEnvironmentConfig('mainnet3'));

const helmManager = new WarpRouteMonitorHelmManager(filePath, 'mainnet3');
await helmManager.runHelmCommand(HelmCommand.InstallOrUpgrade);
}

main()
Expand Down
44 changes: 0 additions & 44 deletions typescript/infra/scripts/warp-routes/helm.ts

This file was deleted.

Loading

0 comments on commit b1d8bb8

Please sign in to comment.