@@ -2,91 +2,34 @@ import { createLogger, sleep } from '@aztec/aztec.js';
22import type { RollupCheatCodes } from '@aztec/aztec/testing' ;
33import type { Logger } from '@aztec/foundation/log' ;
44import { makeBackoff , retry } from '@aztec/foundation/retry' ;
5- import type { SequencerConfig } from '@aztec/sequencer-client' ;
6- import { createAztecNodeAdminClient } from '@aztec/stdlib/interfaces/client' ;
5+ import { type AztecNodeAdminConfig , createAztecNodeAdminClient } from '@aztec/stdlib/interfaces/client' ;
76
87import { ChildProcess , exec , execSync , spawn } from 'child_process' ;
98import path from 'path' ;
109import { promisify } from 'util' ;
1110import { z } from 'zod' ;
1211
13- import { AlertChecker , type AlertConfig } from '../quality_of_service/alert_checker.js ';
12+ export const PXE_SERVICE_NAME = 'services/aztec-infra-rpc-aztec-node ';
1413
1514const execAsync = promisify ( exec ) ;
1615
1716const logger = createLogger ( 'e2e:k8s-utils' ) ;
1817
19- const ethereumHostsSchema = z . string ( ) . refine (
20- str =>
21- str . split ( ',' ) . every ( url => {
22- try {
23- new URL ( url . trim ( ) ) ;
24- return true ;
25- } catch {
26- return false ;
27- }
28- } ) ,
29- 'ETHEREUM_HOSTS must be a comma-separated list of valid URLs' ,
30- ) ;
31-
32- const k8sLocalConfigSchema = z . object ( {
33- ETHEREUM_SLOT_DURATION : z . coerce . number ( ) . min ( 1 , 'ETHEREUM_SLOT_DURATION env variable must be set' ) ,
34- AZTEC_SLOT_DURATION : z . coerce . number ( ) . min ( 1 , 'AZTEC_SLOT_DURATION env variable must be set' ) ,
35- AZTEC_EPOCH_DURATION : z . coerce . number ( ) . min ( 1 , 'AZTEC_EPOCH_DURATION env variable must be set' ) ,
36- AZTEC_PROOF_SUBMISSION_WINDOW : z . coerce . number ( ) . min ( 1 , 'AZTEC_PROOF_SUBMISSION_WINDOW env variable must be set' ) ,
37- AZTEC_REAL_PROOFS : z . string ( ) . default ( 'false' ) ,
38- INSTANCE_NAME : z . string ( ) . min ( 1 , 'INSTANCE_NAME env variable must be set' ) ,
18+ const testConfigSchema = z . object ( {
3919 NAMESPACE : z . string ( ) . min ( 1 , 'NAMESPACE env variable must be set' ) ,
40- CONTAINER_NODE_PORT : z . coerce . number ( ) . default ( 8080 ) ,
41- CONTAINER_NODE_ADMIN_PORT : z . coerce . number ( ) . default ( 8880 ) ,
42- CONTAINER_SEQUENCER_PORT : z . coerce . number ( ) . default ( 8080 ) ,
43- CONTAINER_PROVER_NODE_PORT : z . coerce . number ( ) . default ( 8080 ) ,
44- CONTAINER_PXE_PORT : z . coerce . number ( ) . default ( 8080 ) ,
45- CONTAINER_ETHEREUM_PORT : z . coerce . number ( ) . default ( 8545 ) ,
46- CONTAINER_METRICS_PORT : z . coerce . number ( ) . default ( 80 ) ,
47- GRAFANA_PASSWORD : z . string ( ) . optional ( ) ,
48- METRICS_API_PATH : z . string ( ) . default ( '/api/datasources/proxy/uid/spartan-metrics-prometheus/api/v1' ) ,
49- SPARTAN_DIR : z . string ( ) . min ( 1 , 'SPARTAN_DIR env variable must be set' ) ,
50- ETHEREUM_HOSTS : ethereumHostsSchema . optional ( ) ,
5120 L1_ACCOUNT_MNEMONIC : z . string ( ) . default ( 'test test test test test test test test test test test junk' ) ,
52- SEPOLIA_RUN : z . string ( ) . default ( 'false' ) ,
53- K8S : z . literal ( 'local' ) ,
54- } ) ;
55-
56- const k8sGCloudConfigSchema = k8sLocalConfigSchema . extend ( {
57- K8S : z . literal ( 'gcloud' ) ,
58- CLUSTER_NAME : z . string ( ) . min ( 1 , 'CLUSTER_NAME env variable must be set' ) ,
59- REGION : z . string ( ) . min ( 1 , 'REGION env variable must be set' ) ,
60- PROJECT_ID : z . string ( ) . min ( 1 , 'PROJECT_ID env variable must be set' ) ,
21+ K8S_CLUSTER : z . string ( ) . min ( 1 , 'K8S_CLUSTER env variable must be set' ) ,
22+ REGION : z . string ( ) . optional ( ) ,
23+ PROJECT_ID : z . string ( ) . optional ( ) ,
6124} ) ;
6225
63- const directConfigSchema = z . object ( {
64- PXE_URL : z . string ( ) . url ( 'PXE_URL must be a valid URL' ) ,
65- NODE_URL : z . string ( ) . url ( 'NODE_URL must be a valid URL' ) ,
66- NODE_ADMIN_URL : z . string ( ) . url ( 'NODE_ADMIN_URL must be a valid URL' ) ,
67- ETHEREUM_HOSTS : ethereumHostsSchema ,
68- K8S : z . literal ( 'false' ) ,
69- } ) ;
26+ export type TestConfig = z . infer < typeof testConfigSchema > ;
7027
71- const envSchema = z . discriminatedUnion ( 'K8S' , [ k8sLocalConfigSchema , k8sGCloudConfigSchema , directConfigSchema ] ) ;
72-
73- export type K8sLocalConfig = z . infer < typeof k8sLocalConfigSchema > ;
74- export type K8sGCloudConfig = z . infer < typeof k8sGCloudConfigSchema > ;
75- export type DirectConfig = z . infer < typeof directConfigSchema > ;
76- export type EnvConfig = z . infer < typeof envSchema > ;
77-
78- export function isK8sConfig ( config : EnvConfig ) : config is K8sLocalConfig | K8sGCloudConfig {
79- return config . K8S === 'local' || config . K8S === 'gcloud' ;
80- }
28+ export function setupEnvironment ( env : unknown ) : TestConfig {
29+ const config = testConfigSchema . parse ( env ) ;
8130
82- export function isGCloudConfig ( config : EnvConfig ) : config is K8sGCloudConfig {
83- return config . K8S === 'gcloud' ;
84- }
85-
86- export function setupEnvironment ( env : unknown ) : EnvConfig {
87- const config = envSchema . parse ( env ) ;
88- if ( isGCloudConfig ( config ) ) {
89- const command = `gcloud container clusters get-credentials ${ config . CLUSTER_NAME } --region=${ config . REGION } --project=${ config . PROJECT_ID } ` ;
31+ if ( config . K8S_CLUSTER !== 'kind' ) {
32+ const command = `gcloud container clusters get-credentials ${ config . K8S_CLUSTER } --region=${ config . REGION } --project=${ config . PROJECT_ID } ` ;
9033 execSync ( command ) ;
9134 }
9235 return config ;
@@ -212,6 +155,14 @@ export async function startPortForward({
212155 return { process, port } ;
213156}
214157
158+ export async function startPortForwardForPXE ( namespace : string ) {
159+ return startPortForward ( {
160+ resource : PXE_SERVICE_NAME ,
161+ namespace,
162+ containerPort : 8080 ,
163+ } ) ;
164+ }
165+
215166export async function deleteResourceByName ( {
216167 resource,
217168 namespace,
@@ -550,25 +501,7 @@ export async function enableValidatorDynamicBootNode(
550501 logger . info ( `Validator dynamic boot node enabled` ) ;
551502}
552503
553- export async function runAlertCheck ( config : EnvConfig , alerts : AlertConfig [ ] , logger : Logger ) {
554- if ( isK8sConfig ( config ) ) {
555- const { process, port } = await startPortForward ( {
556- resource : `svc/metrics-grafana` ,
557- namespace : 'metrics' ,
558- containerPort : config . CONTAINER_METRICS_PORT ,
559- } ) ;
560- const alertChecker = new AlertChecker ( logger , {
561- grafanaEndpoint : `http://localhost:${ port } ${ config . METRICS_API_PATH } ` ,
562- grafanaCredentials : `admin:${ config . GRAFANA_PASSWORD } ` ,
563- } ) ;
564- await alertChecker . runAlertCheck ( alerts ) ;
565- process . kill ( ) ;
566- } else {
567- logger . info ( 'Not running alert check in non-k8s environment' ) ;
568- }
569- }
570-
571- export async function updateSequencerConfig ( url : string , config : Partial < SequencerConfig > ) {
504+ export async function updateSequencerConfig ( url : string , config : Partial < AztecNodeAdminConfig > ) {
572505 const node = createAztecNodeAdminClient ( url ) ;
573506 // Retry incase the port forward is not ready yet
574507 await retry ( ( ) => node . setConfig ( config ) , 'Update sequencer config' , makeBackoff ( [ 1 , 3 , 6 ] ) , logger ) ;
@@ -583,7 +516,7 @@ export async function getSequencers(namespace: string) {
583516async function updateK8sSequencersConfig ( args : {
584517 containerPort : number ;
585518 namespace : string ;
586- config : Partial < SequencerConfig > ;
519+ config : Partial < AztecNodeAdminConfig > ;
587520} ) {
588521 const { containerPort, namespace, config } = args ;
589522 const sequencers = await getSequencers ( namespace ) ;
@@ -600,17 +533,17 @@ async function updateK8sSequencersConfig(args: {
600533 }
601534}
602535
603- export async function updateSequencersConfig ( env : EnvConfig , config : Partial < SequencerConfig > ) {
604- if ( isK8sConfig ( env ) ) {
605- await updateK8sSequencersConfig ( {
606- containerPort : env . CONTAINER_NODE_ADMIN_PORT ,
607- namespace : env . NAMESPACE ,
608- config,
609- } ) ;
610- } else {
611- await updateSequencerConfig ( env . NODE_ADMIN_URL , config ) ;
612- }
613- }
536+ // export async function updateSequencersConfig(env: EnvConfig, config: Partial<AztecNodeAdminConfig >) {
537+ // if (isK8sConfig(env)) {
538+ // await updateK8sSequencersConfig({
539+ // containerPort: env.CONTAINER_NODE_ADMIN_PORT,
540+ // namespace: env.NAMESPACE,
541+ // config,
542+ // });
543+ // } else {
544+ // await updateSequencerConfig(env.NODE_ADMIN_URL, config);
545+ // }
546+ // }
614547
615548/**
616549 * Rolls the Aztec pods in the given namespace.
0 commit comments