@aztec/end-to-end 0.0.1-commit.c7c42ec → 0.0.1-commit.c80b6263
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/bench/client_flows/benchmark.d.ts +3 -2
- package/dest/bench/client_flows/benchmark.d.ts.map +1 -1
- package/dest/bench/client_flows/benchmark.js +21 -1
- package/dest/bench/client_flows/client_flows_benchmark.d.ts +12 -13
- package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
- package/dest/bench/client_flows/client_flows_benchmark.js +118 -133
- package/dest/bench/client_flows/data_extractor.js +3 -1
- package/dest/bench/utils.d.ts +9 -8
- package/dest/bench/utils.d.ts.map +1 -1
- package/dest/bench/utils.js +17 -12
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts +6 -7
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.d.ts.map +1 -1
- package/dest/e2e_blacklist_token_contract/blacklist_token_contract_test.js +96 -112
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts +15 -10
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.d.ts.map +1 -1
- package/dest/e2e_cross_chain_messaging/cross_chain_messaging_test.js +89 -70
- package/dest/e2e_deploy_contract/deploy_test.d.ts +4 -3
- package/dest/e2e_deploy_contract/deploy_test.d.ts.map +1 -1
- package/dest/e2e_deploy_contract/deploy_test.js +18 -13
- package/dest/e2e_epochs/epochs_test.d.ts +7 -1
- package/dest/e2e_epochs/epochs_test.d.ts.map +1 -1
- package/dest/e2e_epochs/epochs_test.js +31 -9
- package/dest/e2e_fees/bridging_race.notest.js +3 -5
- package/dest/e2e_fees/fees_test.d.ts +13 -13
- package/dest/e2e_fees/fees_test.d.ts.map +1 -1
- package/dest/e2e_fees/fees_test.js +123 -141
- package/dest/e2e_l1_publisher/write_json.d.ts +2 -2
- package/dest/e2e_l1_publisher/write_json.d.ts.map +1 -1
- package/dest/e2e_l1_publisher/write_json.js +19 -15
- package/dest/e2e_nested_contract/nested_contract_test.d.ts +6 -9
- package/dest/e2e_nested_contract/nested_contract_test.d.ts.map +1 -1
- package/dest/e2e_nested_contract/nested_contract_test.js +31 -39
- package/dest/e2e_p2p/inactivity_slash_test.d.ts +3 -3
- package/dest/e2e_p2p/inactivity_slash_test.d.ts.map +1 -1
- package/dest/e2e_p2p/inactivity_slash_test.js +3 -3
- package/dest/e2e_p2p/p2p_network.d.ts +7 -6
- package/dest/e2e_p2p/p2p_network.d.ts.map +1 -1
- package/dest/e2e_p2p/p2p_network.js +111 -104
- package/dest/e2e_p2p/shared.d.ts +6 -6
- package/dest/e2e_p2p/shared.d.ts.map +1 -1
- package/dest/e2e_p2p/shared.js +13 -20
- package/dest/e2e_token_contract/token_contract_test.d.ts +16 -9
- package/dest/e2e_token_contract/token_contract_test.d.ts.map +1 -1
- package/dest/e2e_token_contract/token_contract_test.js +89 -91
- package/dest/fixtures/e2e_prover_test.d.ts +8 -14
- package/dest/fixtures/e2e_prover_test.d.ts.map +1 -1
- package/dest/fixtures/e2e_prover_test.js +86 -95
- package/dest/fixtures/setup.d.ts +218 -0
- package/dest/fixtures/setup.d.ts.map +1 -0
- package/dest/fixtures/setup.js +695 -0
- package/dest/fixtures/setup_p2p_test.d.ts +4 -5
- package/dest/fixtures/setup_p2p_test.d.ts.map +1 -1
- package/dest/fixtures/setup_p2p_test.js +24 -19
- package/dest/fixtures/token_utils.d.ts +1 -1
- package/dest/fixtures/token_utils.d.ts.map +1 -1
- package/dest/fixtures/token_utils.js +7 -4
- package/dest/fixtures/utils.d.ts +5 -194
- package/dest/fixtures/utils.d.ts.map +1 -1
- package/dest/fixtures/utils.js +4 -619
- package/dest/quality_of_service/grafana_client.d.ts +41 -0
- package/dest/quality_of_service/grafana_client.d.ts.map +1 -0
- package/dest/quality_of_service/{alert_checker.js → grafana_client.js} +1 -1
- package/dest/quality_of_service/prometheus_client.d.ts +38 -0
- package/dest/quality_of_service/prometheus_client.d.ts.map +1 -0
- package/dest/quality_of_service/prometheus_client.js +67 -0
- package/dest/shared/cross_chain_test_harness.d.ts +16 -6
- package/dest/shared/cross_chain_test_harness.d.ts.map +1 -1
- package/dest/shared/cross_chain_test_harness.js +13 -13
- package/dest/shared/gas_portal_test_harness.d.ts +11 -1
- package/dest/shared/gas_portal_test_harness.d.ts.map +1 -1
- package/dest/shared/gas_portal_test_harness.js +1 -1
- package/dest/shared/index.d.ts +2 -2
- package/dest/shared/index.d.ts.map +1 -1
- package/dest/shared/submit-transactions.d.ts +3 -3
- package/dest/shared/submit-transactions.d.ts.map +1 -1
- package/dest/shared/submit-transactions.js +9 -11
- package/dest/shared/uniswap_l1_l2.d.ts +3 -28
- package/dest/shared/uniswap_l1_l2.d.ts.map +1 -1
- package/dest/shared/uniswap_l1_l2.js +51 -33
- package/dest/simulators/lending_simulator.d.ts +5 -1
- package/dest/simulators/lending_simulator.d.ts.map +1 -1
- package/dest/simulators/lending_simulator.js +2 -2
- package/dest/spartan/setup_test_wallets.d.ts +4 -3
- package/dest/spartan/setup_test_wallets.d.ts.map +1 -1
- package/dest/spartan/setup_test_wallets.js +61 -34
- package/dest/spartan/tx_metrics.d.ts +51 -2
- package/dest/spartan/tx_metrics.d.ts.map +1 -1
- package/dest/spartan/tx_metrics.js +333 -6
- package/dest/spartan/utils/bot.d.ts +27 -0
- package/dest/spartan/utils/bot.d.ts.map +1 -0
- package/dest/spartan/utils/bot.js +141 -0
- package/dest/spartan/utils/chaos.d.ts +79 -0
- package/dest/spartan/utils/chaos.d.ts.map +1 -0
- package/dest/spartan/utils/chaos.js +142 -0
- package/dest/spartan/utils/clients.d.ts +39 -0
- package/dest/spartan/utils/clients.d.ts.map +1 -0
- package/dest/spartan/utils/clients.js +90 -0
- package/dest/spartan/utils/config.d.ts +36 -0
- package/dest/spartan/utils/config.d.ts.map +1 -0
- package/dest/spartan/utils/config.js +20 -0
- package/dest/spartan/utils/health.d.ts +63 -0
- package/dest/spartan/utils/health.d.ts.map +1 -0
- package/dest/spartan/utils/health.js +202 -0
- package/dest/spartan/utils/helm.d.ts +15 -0
- package/dest/spartan/utils/helm.d.ts.map +1 -0
- package/dest/spartan/utils/helm.js +47 -0
- package/dest/spartan/utils/index.d.ts +9 -0
- package/dest/spartan/utils/index.d.ts.map +1 -0
- package/dest/spartan/utils/index.js +18 -0
- package/dest/spartan/utils/k8s.d.ts +98 -0
- package/dest/spartan/utils/k8s.d.ts.map +1 -0
- package/dest/spartan/utils/k8s.js +257 -0
- package/dest/spartan/utils/nodes.d.ts +31 -0
- package/dest/spartan/utils/nodes.d.ts.map +1 -0
- package/dest/spartan/utils/nodes.js +290 -0
- package/dest/spartan/utils/scripts.d.ts +16 -0
- package/dest/spartan/utils/scripts.d.ts.map +1 -0
- package/dest/spartan/utils/scripts.js +66 -0
- package/dest/spartan/utils.d.ts +2 -253
- package/dest/spartan/utils.d.ts.map +1 -1
- package/dest/spartan/utils.js +1 -892
- package/package.json +40 -39
- package/src/bench/client_flows/benchmark.ts +24 -2
- package/src/bench/client_flows/client_flows_benchmark.ts +138 -204
- package/src/bench/client_flows/data_extractor.ts +1 -1
- package/src/bench/utils.ts +20 -14
- package/src/e2e_blacklist_token_contract/blacklist_token_contract_test.ts +104 -142
- package/src/e2e_cross_chain_messaging/cross_chain_messaging_test.ts +127 -116
- package/src/e2e_deploy_contract/deploy_test.ts +21 -14
- package/src/e2e_epochs/epochs_test.ts +60 -34
- package/src/e2e_fees/bridging_race.notest.ts +3 -9
- package/src/e2e_fees/fees_test.ts +172 -220
- package/src/e2e_l1_publisher/write_json.ts +21 -16
- package/src/e2e_nested_contract/nested_contract_test.ts +33 -56
- package/src/e2e_p2p/inactivity_slash_test.ts +5 -5
- package/src/e2e_p2p/p2p_network.ts +172 -168
- package/src/e2e_p2p/shared.ts +26 -27
- package/src/e2e_token_contract/token_contract_test.ts +103 -118
- package/src/fixtures/e2e_prover_test.ts +99 -134
- package/src/fixtures/setup.ts +1017 -0
- package/src/fixtures/setup_p2p_test.ts +15 -20
- package/src/fixtures/token_utils.ts +6 -5
- package/src/fixtures/utils.ts +27 -907
- package/src/quality_of_service/{alert_checker.ts → grafana_client.ts} +1 -1
- package/src/quality_of_service/prometheus_client.ts +113 -0
- package/src/shared/cross_chain_test_harness.ts +16 -36
- package/src/shared/gas_portal_test_harness.ts +1 -1
- package/src/shared/index.ts +1 -1
- package/src/shared/submit-transactions.ts +9 -15
- package/src/shared/uniswap_l1_l2.ts +58 -77
- package/src/simulators/lending_simulator.ts +2 -2
- package/src/spartan/setup_test_wallets.ts +79 -25
- package/src/spartan/tx_metrics.ts +255 -9
- package/src/spartan/utils/bot.ts +185 -0
- package/src/spartan/utils/chaos.ts +253 -0
- package/src/spartan/utils/clients.ts +100 -0
- package/src/spartan/utils/config.ts +26 -0
- package/src/spartan/utils/health.ts +255 -0
- package/src/spartan/utils/helm.ts +84 -0
- package/src/spartan/utils/index.ts +62 -0
- package/src/spartan/utils/k8s.ts +375 -0
- package/src/spartan/utils/nodes.ts +323 -0
- package/src/spartan/utils/scripts.ts +63 -0
- package/src/spartan/utils.ts +1 -1158
- package/dest/fixtures/snapshot_manager.d.ts +0 -93
- package/dest/fixtures/snapshot_manager.d.ts.map +0 -1
- package/dest/fixtures/snapshot_manager.js +0 -493
- package/dest/quality_of_service/alert_checker.d.ts +0 -41
- package/dest/quality_of_service/alert_checker.d.ts.map +0 -1
- package/src/fixtures/snapshot_manager.ts +0 -651
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/aztec.js/log';
|
|
2
|
+
import type { Logger } from '@aztec/foundation/log';
|
|
3
|
+
|
|
4
|
+
import { exec } from 'child_process';
|
|
5
|
+
import { promisify } from 'util';
|
|
6
|
+
|
|
7
|
+
const execAsync = promisify(exec);
|
|
8
|
+
|
|
9
|
+
const logger = createLogger('e2e:k8s-utils');
|
|
10
|
+
|
|
11
|
+
function shellQuote(value: string) {
|
|
12
|
+
// Single-quote safe shell escaping: ' -> '\''
|
|
13
|
+
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function valuesToArgs(values: Record<string, string | number | boolean>) {
|
|
17
|
+
return Object.entries(values)
|
|
18
|
+
.map(([key, value]) =>
|
|
19
|
+
typeof value === 'number' || typeof value === 'boolean'
|
|
20
|
+
? `--set ${key}=${value}`
|
|
21
|
+
: `--set-string ${key}=${shellQuote(String(value))}`,
|
|
22
|
+
)
|
|
23
|
+
.join(' ');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function createHelmCommand({
|
|
27
|
+
instanceName,
|
|
28
|
+
helmChartDir,
|
|
29
|
+
namespace,
|
|
30
|
+
valuesFile,
|
|
31
|
+
timeout,
|
|
32
|
+
values,
|
|
33
|
+
reuseValues = false,
|
|
34
|
+
}: {
|
|
35
|
+
instanceName: string;
|
|
36
|
+
helmChartDir: string;
|
|
37
|
+
namespace: string;
|
|
38
|
+
valuesFile: string | undefined;
|
|
39
|
+
timeout: string;
|
|
40
|
+
values: Record<string, string | number | boolean>;
|
|
41
|
+
reuseValues?: boolean;
|
|
42
|
+
}) {
|
|
43
|
+
const valuesFileArgs = valuesFile ? `--values ${helmChartDir}/values/${valuesFile}` : '';
|
|
44
|
+
const reuseValuesArgs = reuseValues ? '--reuse-values' : '';
|
|
45
|
+
return `helm upgrade --install ${instanceName} ${helmChartDir} --namespace ${namespace} ${valuesFileArgs} ${reuseValuesArgs} --wait --timeout=${timeout} ${valuesToArgs(
|
|
46
|
+
values,
|
|
47
|
+
)}`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function execHelmCommand(args: Parameters<typeof createHelmCommand>[0]) {
|
|
51
|
+
const helmCommand = createHelmCommand(args);
|
|
52
|
+
logger.info(`helm command: ${helmCommand}`);
|
|
53
|
+
const { stdout } = await execAsync(helmCommand);
|
|
54
|
+
return stdout;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function getHelmReleaseStatus(instanceName: string, namespace: string): Promise<string | undefined> {
|
|
58
|
+
try {
|
|
59
|
+
const { stdout } = await execAsync(
|
|
60
|
+
`helm list --namespace ${namespace} --all --filter '^${instanceName}$' --output json | cat`,
|
|
61
|
+
);
|
|
62
|
+
const parsed = JSON.parse(stdout) as Array<{ name?: string; status?: string }>;
|
|
63
|
+
const row = parsed.find(r => r.name === instanceName);
|
|
64
|
+
return row?.status;
|
|
65
|
+
} catch {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function forceDeleteHelmReleaseRecord(instanceName: string, namespace: string, log?: Logger) {
|
|
71
|
+
const labelSelector = `owner=helm,name=${instanceName}`;
|
|
72
|
+
const cmd = `kubectl delete secret -n ${namespace} -l ${labelSelector} --ignore-not-found=true`;
|
|
73
|
+
(log ?? logger).warn(`Force deleting Helm release record: ${cmd}`);
|
|
74
|
+
await execAsync(cmd).catch(() => undefined);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export async function hasDeployedHelmRelease(instanceName: string, namespace: string): Promise<boolean> {
|
|
78
|
+
try {
|
|
79
|
+
const status = await getHelmReleaseStatus(instanceName, namespace);
|
|
80
|
+
return status?.toLowerCase() === 'deployed';
|
|
81
|
+
} catch {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Re-export all utilities from individual modules
|
|
2
|
+
// Note: Internal helpers (helm commands, etc.) are not re-exported to maintain the original public API
|
|
3
|
+
|
|
4
|
+
// Config
|
|
5
|
+
export { type TestConfig, setupEnvironment } from './config.js';
|
|
6
|
+
|
|
7
|
+
// Scripts
|
|
8
|
+
export { getGitProjectRoot, getAztecBin, runAztecBin, runProjectScript } from './scripts.js';
|
|
9
|
+
|
|
10
|
+
// K8s operations
|
|
11
|
+
export {
|
|
12
|
+
startPortForward,
|
|
13
|
+
getExternalIP,
|
|
14
|
+
startPortForwardForPrometeheus,
|
|
15
|
+
startPortForwardForRPC,
|
|
16
|
+
startPortForwardForEthereum,
|
|
17
|
+
deleteResourceByName,
|
|
18
|
+
deleteResourceByLabel,
|
|
19
|
+
waitForResourceByLabel,
|
|
20
|
+
waitForResourceByName,
|
|
21
|
+
waitForResourcesByName,
|
|
22
|
+
getChartDir,
|
|
23
|
+
type ServiceEndpoint,
|
|
24
|
+
getServiceEndpoint,
|
|
25
|
+
getRPCEndpoint,
|
|
26
|
+
getEthereumEndpoint,
|
|
27
|
+
} from './k8s.js';
|
|
28
|
+
|
|
29
|
+
// Chaos Mesh
|
|
30
|
+
export {
|
|
31
|
+
uninstallChaosMesh,
|
|
32
|
+
installChaosMeshChart,
|
|
33
|
+
applyProverFailure,
|
|
34
|
+
applyValidatorFailure,
|
|
35
|
+
applyProverKill,
|
|
36
|
+
applyProverBrokerKill,
|
|
37
|
+
applyBootNodeFailure,
|
|
38
|
+
applyValidatorKill,
|
|
39
|
+
applyNetworkShaping,
|
|
40
|
+
} from './chaos.js';
|
|
41
|
+
|
|
42
|
+
// Bot management
|
|
43
|
+
export { restartBot, installTransferBot, uninstallTransferBot } from './bot.js';
|
|
44
|
+
|
|
45
|
+
// Node operations (sequencers, validators, pods)
|
|
46
|
+
export {
|
|
47
|
+
awaitCheckpointNumber,
|
|
48
|
+
getSequencers,
|
|
49
|
+
updateSequencersConfig,
|
|
50
|
+
getSequencersConfig,
|
|
51
|
+
withSequencersAdmin,
|
|
52
|
+
setValidatorTxDrop,
|
|
53
|
+
restartValidators,
|
|
54
|
+
enableValidatorDynamicBootNode,
|
|
55
|
+
rollAztecPods,
|
|
56
|
+
} from './nodes.js';
|
|
57
|
+
|
|
58
|
+
// Client utilities
|
|
59
|
+
export { getPublicViemClient, getL1DeploymentAddresses, getNodeClient } from './clients.js';
|
|
60
|
+
|
|
61
|
+
// Health checks
|
|
62
|
+
export { ChainHealth, type ChainHealthSnapshot } from './health.js';
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
import { createLogger } from '@aztec/aztec.js/log';
|
|
2
|
+
import { promiseWithResolvers } from '@aztec/foundation/promise';
|
|
3
|
+
import { retryUntil } from '@aztec/foundation/retry';
|
|
4
|
+
|
|
5
|
+
import { type ChildProcess, exec, spawn } from 'child_process';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { promisify } from 'util';
|
|
8
|
+
|
|
9
|
+
const execAsync = promisify(exec);
|
|
10
|
+
|
|
11
|
+
const logger = createLogger('e2e:k8s-utils');
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Represents an endpoint to reach a K8s service.
|
|
15
|
+
* May be a LoadBalancer external IP or a port-forward.
|
|
16
|
+
*/
|
|
17
|
+
export interface ServiceEndpoint {
|
|
18
|
+
url: string;
|
|
19
|
+
process?: ChildProcess;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function startPortForward({
|
|
23
|
+
resource,
|
|
24
|
+
namespace,
|
|
25
|
+
containerPort,
|
|
26
|
+
hostPort,
|
|
27
|
+
}: {
|
|
28
|
+
resource: string;
|
|
29
|
+
namespace: string;
|
|
30
|
+
containerPort: number;
|
|
31
|
+
// If not provided, the port will be chosen automatically
|
|
32
|
+
hostPort?: number;
|
|
33
|
+
}): Promise<{
|
|
34
|
+
process: ChildProcess;
|
|
35
|
+
port: number;
|
|
36
|
+
}> {
|
|
37
|
+
const hostPortAsString = hostPort ? hostPort.toString() : '';
|
|
38
|
+
|
|
39
|
+
logger.debug(`kubectl port-forward -n ${namespace} ${resource} ${hostPortAsString}:${containerPort}`);
|
|
40
|
+
|
|
41
|
+
const process = spawn(
|
|
42
|
+
'kubectl',
|
|
43
|
+
['port-forward', '-n', namespace, resource, `${hostPortAsString}:${containerPort}`],
|
|
44
|
+
{
|
|
45
|
+
detached: true,
|
|
46
|
+
windowsHide: true,
|
|
47
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
48
|
+
},
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
let isResolved = false;
|
|
52
|
+
const connected = new Promise<number>((resolve, reject) => {
|
|
53
|
+
process.stdout?.on('data', data => {
|
|
54
|
+
const str = data.toString() as string;
|
|
55
|
+
if (!isResolved && str.includes('Forwarding from')) {
|
|
56
|
+
isResolved = true;
|
|
57
|
+
logger.debug(`Port forward for ${resource}: ${str}`);
|
|
58
|
+
const port = str.search(/:\d+/);
|
|
59
|
+
if (port === -1) {
|
|
60
|
+
reject(new Error('Port not found in port forward output'));
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const portNumber = parseInt(str.slice(port + 1));
|
|
64
|
+
logger.verbose(`Port forwarded for ${resource} at ${portNumber}:${containerPort}`);
|
|
65
|
+
resolve(portNumber);
|
|
66
|
+
} else {
|
|
67
|
+
logger.silent(str);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
process.stderr?.on('data', data => {
|
|
71
|
+
logger.verbose(`Port forward for ${resource}: ${data.toString()}`);
|
|
72
|
+
// It's a strange thing:
|
|
73
|
+
// If we don't pipe stderr, then the port forwarding does not work.
|
|
74
|
+
// Log to silent because this doesn't actually report errors,
|
|
75
|
+
// just extremely verbose debug logs.
|
|
76
|
+
logger.silent(data.toString());
|
|
77
|
+
});
|
|
78
|
+
process.on('close', () => {
|
|
79
|
+
if (!isResolved) {
|
|
80
|
+
isResolved = true;
|
|
81
|
+
const msg = `Port forward for ${resource} closed before connection established`;
|
|
82
|
+
logger.warn(msg);
|
|
83
|
+
reject(new Error(msg));
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
process.on('error', error => {
|
|
87
|
+
if (!isResolved) {
|
|
88
|
+
isResolved = true;
|
|
89
|
+
const msg = `Port forward for ${resource} error: ${error}`;
|
|
90
|
+
logger.error(msg);
|
|
91
|
+
reject(new Error(msg));
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
process.on('exit', code => {
|
|
95
|
+
if (!isResolved) {
|
|
96
|
+
isResolved = true;
|
|
97
|
+
const msg = `Port forward for ${resource} exited with code ${code}`;
|
|
98
|
+
logger.verbose(msg);
|
|
99
|
+
reject(new Error(msg));
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const port = await connected;
|
|
105
|
+
|
|
106
|
+
return { process, port };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function getExternalIP(namespace: string, serviceName: string): Promise<string> {
|
|
110
|
+
const { promise, resolve, reject } = promiseWithResolvers<string>();
|
|
111
|
+
const process = spawn(
|
|
112
|
+
'kubectl',
|
|
113
|
+
[
|
|
114
|
+
'get',
|
|
115
|
+
'service',
|
|
116
|
+
'-n',
|
|
117
|
+
namespace,
|
|
118
|
+
`${namespace}-${serviceName}`,
|
|
119
|
+
'--output',
|
|
120
|
+
"jsonpath='{.status.loadBalancer.ingress[0].ip}'",
|
|
121
|
+
],
|
|
122
|
+
{
|
|
123
|
+
stdio: 'pipe',
|
|
124
|
+
},
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
let ip = '';
|
|
128
|
+
process.stdout.on('data', data => {
|
|
129
|
+
ip += data;
|
|
130
|
+
});
|
|
131
|
+
process.on('error', err => {
|
|
132
|
+
reject(err);
|
|
133
|
+
});
|
|
134
|
+
process.on('exit', () => {
|
|
135
|
+
// kubectl prints JSON. Remove the quotes
|
|
136
|
+
resolve(ip.replace(/"|'/g, ''));
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
return promise;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Gets an endpoint for a K8s service.
|
|
144
|
+
* By default, tries to get the external IP first and falls back to port-forward if unavailable.
|
|
145
|
+
*
|
|
146
|
+
* @param opts.namespace - K8s namespace
|
|
147
|
+
* @param opts.serviceName - Service name suffix (e.g., 'rpc-aztec-node', 'eth-execution')
|
|
148
|
+
* @param opts.containerPort - Port the service exposes
|
|
149
|
+
* @param opts.usePortForward - If true, skip external IP check and always use port-forward
|
|
150
|
+
*/
|
|
151
|
+
export async function getServiceEndpoint(opts: {
|
|
152
|
+
namespace: string;
|
|
153
|
+
serviceName: string;
|
|
154
|
+
containerPort: number;
|
|
155
|
+
forcePortForward?: boolean;
|
|
156
|
+
}): Promise<ServiceEndpoint> {
|
|
157
|
+
const { namespace, serviceName, containerPort, forcePortForward } = opts;
|
|
158
|
+
|
|
159
|
+
if (!forcePortForward) {
|
|
160
|
+
try {
|
|
161
|
+
const ip = await retryUntil(
|
|
162
|
+
async () => {
|
|
163
|
+
try {
|
|
164
|
+
const ip = await getExternalIP(namespace, serviceName);
|
|
165
|
+
if (ip && ip !== '' && ip !== '<pending>' && ip !== 'null') {
|
|
166
|
+
return ip;
|
|
167
|
+
}
|
|
168
|
+
} catch (err) {
|
|
169
|
+
logger.verbose(`Failed to get external IP for ${serviceName}: ${err}`);
|
|
170
|
+
}
|
|
171
|
+
return undefined;
|
|
172
|
+
},
|
|
173
|
+
`external IP for ${serviceName}`,
|
|
174
|
+
30,
|
|
175
|
+
5,
|
|
176
|
+
);
|
|
177
|
+
logger.info(`Using external IP for ${serviceName}: ${ip}:${containerPort}`);
|
|
178
|
+
return { url: `http://${ip}:${containerPort}` };
|
|
179
|
+
} catch {
|
|
180
|
+
logger.warn(`External IP not available for ${serviceName} after 5min, using port-forward`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Fallback to port-forward
|
|
185
|
+
const resource = `svc/${namespace}-${serviceName}`;
|
|
186
|
+
|
|
187
|
+
const { process, port } = await startPortForward({
|
|
188
|
+
resource,
|
|
189
|
+
namespace,
|
|
190
|
+
containerPort,
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
return { url: `http://127.0.0.1:${port}`, process };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Gets an endpoint for the RPC node service.
|
|
198
|
+
* Tries external IP first, falls back to port-forward.
|
|
199
|
+
*
|
|
200
|
+
* @param namespace - K8s namespace
|
|
201
|
+
* @param usePortForward - If true, skip external IP and use port-forward directly
|
|
202
|
+
*/
|
|
203
|
+
export async function getRPCEndpoint(namespace: string, forcePortForward?: boolean): Promise<ServiceEndpoint> {
|
|
204
|
+
return await getServiceEndpoint({
|
|
205
|
+
namespace,
|
|
206
|
+
serviceName: 'rpc-aztec-node',
|
|
207
|
+
containerPort: 8080,
|
|
208
|
+
forcePortForward,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Gets an endpoint for the Ethereum execution service.
|
|
214
|
+
* Tries external IP first, falls back to port-forward.
|
|
215
|
+
*
|
|
216
|
+
* @param namespace - K8s namespace
|
|
217
|
+
* @param usePortForward - If true, skip external IP and use port-forward directly
|
|
218
|
+
*/
|
|
219
|
+
export async function getEthereumEndpoint(namespace: string, forcePortForward?: boolean): Promise<ServiceEndpoint> {
|
|
220
|
+
return await getServiceEndpoint({
|
|
221
|
+
namespace,
|
|
222
|
+
serviceName: 'eth-execution',
|
|
223
|
+
containerPort: 8545,
|
|
224
|
+
forcePortForward,
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export function startPortForwardForPrometeheus(namespace: string) {
|
|
229
|
+
return startPortForward({
|
|
230
|
+
resource: `svc/${namespace}-prometheus-server`,
|
|
231
|
+
namespace,
|
|
232
|
+
containerPort: 80,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export function startPortForwardForRPC(namespace: string, index = 0) {
|
|
237
|
+
return startPortForward({
|
|
238
|
+
resource: `pod/${namespace}-rpc-aztec-node-${index}`,
|
|
239
|
+
namespace,
|
|
240
|
+
containerPort: 8080,
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export function startPortForwardForEthereum(namespace: string) {
|
|
245
|
+
return startPortForward({
|
|
246
|
+
resource: `services/${namespace}-eth-execution`,
|
|
247
|
+
namespace,
|
|
248
|
+
containerPort: 8545,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export async function deleteResourceByName({
|
|
253
|
+
resource,
|
|
254
|
+
namespace,
|
|
255
|
+
name,
|
|
256
|
+
force = false,
|
|
257
|
+
}: {
|
|
258
|
+
resource: string;
|
|
259
|
+
namespace: string;
|
|
260
|
+
name: string;
|
|
261
|
+
force?: boolean;
|
|
262
|
+
}) {
|
|
263
|
+
const command = `kubectl delete ${resource} ${name} -n ${namespace} --ignore-not-found=true --wait=true ${
|
|
264
|
+
force ? '--force' : ''
|
|
265
|
+
}`;
|
|
266
|
+
logger.info(`command: ${command}`);
|
|
267
|
+
const { stdout } = await execAsync(command);
|
|
268
|
+
return stdout;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export async function deleteResourceByLabel({
|
|
272
|
+
resource,
|
|
273
|
+
namespace,
|
|
274
|
+
label,
|
|
275
|
+
timeout = '5m',
|
|
276
|
+
force = false,
|
|
277
|
+
}: {
|
|
278
|
+
resource: string;
|
|
279
|
+
namespace: string;
|
|
280
|
+
label: string;
|
|
281
|
+
timeout?: string;
|
|
282
|
+
force?: boolean;
|
|
283
|
+
}) {
|
|
284
|
+
try {
|
|
285
|
+
// Match both plain and group-qualified names (e.g., "podchaos" or "podchaos.chaos-mesh.org")
|
|
286
|
+
const escaped = resource.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
287
|
+
const regex = `(^|\\.)${escaped}(\\.|$)`;
|
|
288
|
+
await execAsync(`kubectl api-resources --no-headers -o name | grep -Eq '${regex}'`);
|
|
289
|
+
} catch (error) {
|
|
290
|
+
logger.warn(`Resource type '${resource}' not found in cluster, skipping deletion ${error}`);
|
|
291
|
+
return '';
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const command = `kubectl delete ${resource} -l ${label} -n ${namespace} --ignore-not-found=true --wait=true --timeout=${timeout} ${
|
|
295
|
+
force ? '--force' : ''
|
|
296
|
+
}`;
|
|
297
|
+
logger.info(`command: ${command}`);
|
|
298
|
+
const { stdout } = await execAsync(command);
|
|
299
|
+
return stdout;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export async function waitForResourceByLabel({
|
|
303
|
+
resource,
|
|
304
|
+
label,
|
|
305
|
+
namespace,
|
|
306
|
+
condition = 'Ready',
|
|
307
|
+
timeout = '10m',
|
|
308
|
+
}: {
|
|
309
|
+
resource: string;
|
|
310
|
+
label: string;
|
|
311
|
+
namespace: string;
|
|
312
|
+
condition?: string;
|
|
313
|
+
timeout?: string;
|
|
314
|
+
}) {
|
|
315
|
+
const command = `kubectl wait ${resource} -l ${label} --for=condition=${condition} -n ${namespace} --timeout=${timeout}`;
|
|
316
|
+
logger.info(`command: ${command}`);
|
|
317
|
+
const { stdout } = await execAsync(command);
|
|
318
|
+
return stdout;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export async function waitForResourceByName({
|
|
322
|
+
resource,
|
|
323
|
+
name,
|
|
324
|
+
namespace,
|
|
325
|
+
condition = 'Ready',
|
|
326
|
+
timeout = '10m',
|
|
327
|
+
}: {
|
|
328
|
+
resource: string;
|
|
329
|
+
name: string;
|
|
330
|
+
namespace: string;
|
|
331
|
+
condition?: string;
|
|
332
|
+
timeout?: string;
|
|
333
|
+
}) {
|
|
334
|
+
const command = `kubectl wait ${resource}/${name} --for=condition=${condition} -n ${namespace} --timeout=${timeout}`;
|
|
335
|
+
logger.info(`command: ${command}`);
|
|
336
|
+
const { stdout } = await execAsync(command);
|
|
337
|
+
return stdout;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export async function waitForResourcesByName({
|
|
341
|
+
resource,
|
|
342
|
+
names,
|
|
343
|
+
namespace,
|
|
344
|
+
condition = 'Ready',
|
|
345
|
+
timeout = '10m',
|
|
346
|
+
}: {
|
|
347
|
+
resource: string;
|
|
348
|
+
names: string[];
|
|
349
|
+
namespace: string;
|
|
350
|
+
condition?: string;
|
|
351
|
+
timeout?: string;
|
|
352
|
+
}) {
|
|
353
|
+
if (!names.length) {
|
|
354
|
+
throw new Error(`No ${resource} names provided to waitForResourcesByName`);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// Wait all in parallel; if any fails, surface which one.
|
|
358
|
+
await Promise.all(
|
|
359
|
+
names.map(async name => {
|
|
360
|
+
try {
|
|
361
|
+
await waitForResourceByName({ resource, name, namespace, condition, timeout });
|
|
362
|
+
} catch (err) {
|
|
363
|
+
throw new Error(
|
|
364
|
+
`Failed waiting for ${resource}/${name} condition=${condition} timeout=${timeout} namespace=${namespace}: ${String(
|
|
365
|
+
err,
|
|
366
|
+
)}`,
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
}),
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export function getChartDir(spartanDir: string, chartName: string) {
|
|
374
|
+
return path.join(spartanDir.trim(), chartName);
|
|
375
|
+
}
|