index.ts
Overview
This file serves as the **Pulumi deployment entrypoint** for the Avalanche blockchain coinstack within the Unchained infrastructure platform. It automates the provisioning and configuration of the Avalanche node daemon and indexer services on a Kubernetes cluster.
The script:
Loads essential environment and configuration files.
Retrieves Kubernetes cluster access credentials and namespace info.
Maps the coinstack’s configured stateful services (
daemonandindexer) to detailed deployment arguments, specifying ports, configuration files, volume mounts, and Kubernetes health probes.Invokes a shared
deployCoinstackfunction that executes the actual deployment of Kubernetes resources (StatefulSets, Services, ConfigMaps, ingress) based on these arguments.
This file is a blockchain-specific customization that fits into the broader Multi-Blockchain Coinstacks deployment automation framework, enabling standardized and repeatable infrastructure setup for Avalanche nodes.
Detailed Explanation
Exported Async Function (Default Export)
export = async (): Promise<Outputs> => { ... }
This is the main exported asynchronous function and the Pulumi program entrypoint for this coinstack deployment.
Purpose
To define and prepare all necessary deployment parameters for Avalanche node services.
To invoke the generic
deployCoinstackfunction with these parameters.To return deployment outputs that include references to created Kubernetes resources and metadata.
Parameters
None: It is a zero-argument async function, typical for Pulumi JavaScript/TypeScript entrypoints.
Returns
Promise: Resolves to an object containing deployment output values (such as service endpoints, resource names, etc.) defined by the
Outputstype from the Pulumi coinstack library.
Internal Steps and Variables
Constants
const appName = 'unchained' const coinstack = 'avalanche'appName: The application name under which this coinstack is deployed.coinstack: The blockchain identifier, here"avalanche".
Reading the Sample Environment File
const sampleEnv = readFileSync('../sample.env')Reads the
.envsample file that contains environment variables required for the deployment.This raw environment data will be parsed and injected as Kubernetes Secrets during deployment.
Getting Kubernetes Configuration
const { kubeconfig, config, namespace } = await getConfig()Calls a shared utility
getConfig()that fetches:kubeconfig: The Kubernetes cluster access details.config: The loaded deployment configuration object, which includes service definitions.namespace: The Kubernetes namespace where the resources will be deployed.
Mapping Stateful Services to Deployment Arguments
const coinServiceArgs = config.statefulService?.services?.map((service): CoinServiceArgs => { ... })Iterates over the array of services defined in
config.statefulService.services.For each service, it returns a
CoinServiceArgsobject customized per service type.
**Service-specific configurations:**
Daemon Service
Ports:
Exposes
daemon-rpcon port9650.
ConfigMap Data:
Mounts
c-chain-config.jsonread from a local file.Mounts
evm.shlifecycle script.
Volume Mounts:
Mounts the above ConfigMap data into container paths.
Kubernetes Health Probes:
startupProbe,livenessProbe, andreadinessProbewith specific timeouts and thresholds tuned for Avalanche node startup and health monitoring.
Indexer Service
Merges the default blockbook service arguments (
defaultBlockbookServiceArgs), which provide standard configurations for Blockbook-based indexers.Mounts an
indexer-config.jsonread from a local file into the ConfigMap data.
Error Handling
If a service name is unrecognized, the script throws an error indicating unsupported coin service.
Usage Example
This file itself is the Pulumi program for Avalanche deployment and is executed by Pulumi CLI during deployment.
pulumi up -s <stack-name> -C node/coinstacks/avalanche/pulumi
No parameters are passed explicitly; the execution context and configuration are loaded dynamically.
Important Implementation Details
File Reads for Configuration and Scripts
Uses
fs.readFileSyncto load required JSON and shell script files relative to the script location.These files are injected into Kubernetes ConfigMaps for container consumption.
Service Argument Composition
Uses object spread (
...service) to preserve base service configuration.Adds or overrides properties such as ports, configMapData, volumeMounts, and probes based on service role.
Health Probes
Startup, liveness, and readiness probes are essential for Kubernetes to manage pod lifecycle and ensure high availability.
These are tailored with specific thresholds to accommodate Avalanche daemon startup and runtime behavior.
Integration with Shared Pulumi Libraries
The script imports utilities and types (
deployCoinstack,Outputs,CoinServiceArgs,getConfig) from a centralized Pulumi source directory.This promotes consistency and reuse across multiple blockchain coinstack deployments.
Interaction with Other System Components
Pulumi Core Module (
pulumi/src/coinstack)deployCoinstackhandles the heavy lifting of creating Kubernetes resources (StatefulSets, Services, ConfigMaps, IngressRoutes).This file prepares and normalizes the arguments for
deployCoinstack.
Configuration Management
The
configobject fetched viagetConfig()is central to defining which services to deploy, their base parameters, and environment.
Local Configuration and Script Files
This file depends on local files such as:
../sample.env../daemon/config.json../../../scripts/evm.sh../indexer/config.json
These files provide environment variables and service-specific configurations/scripts injected into Kubernetes pods.
Kubernetes Cluster
The deployment targets a Kubernetes cluster, with secrets, ConfigMaps, StatefulSets, and Services managed via Pulumi.
Blockbook Package Constants
Uses
defaultBlockbookServiceArgsfrom the blockbook package to standardize indexer service configuration.
Mermaid Diagram: Flowchart of This File’s Deployment Workflow
flowchart TD
A[Start Pulumi Deployment] --> B[Read sample.env file]
B --> C[Get Kubernetes Config & Namespace]
C --> D[Parse statefulService.services from config]
D --> E{Service name?}
E -->|daemon| F[Configure Daemon Service Args]
E -->|indexer| G[Configure Indexer Service Args]
E -->|other| H[Throw Error: Unsupported Service]
F --> I[Collect all CoinServiceArgs]
G --> I
I --> J[Call deployCoinstack with Args]
J --> K[Deploy Kubernetes StatefulSets and Services]
K --> L[Finish Deployment and Return Outputs]
Summary
`index.ts` is the Avalanche blockchain coinstack's Pulumi entrypoint script. It defines how the Avalanche node daemon and indexer container services are configured and deployed on Kubernetes, leveraging shared Pulumi deployment utilities. This file customizes service ports, configuration files, volume mounts, and health probes specifically for Avalanche within the Unchained multi-blockchain deployment framework. By mapping configuration-defined services into detailed deployment arguments and invoking the core `deployCoinstack` function, it enables automated, repeatable, and maintainable infrastructure provisioning aligned with the broader platform architecture.
Appendix: Key Types and Functions Used
Entity | Description |
|---|---|
`deployCoinstack` | Core function to deploy all coinstack services as Kubernetes resources. |
`Outputs` | Type representing outputs from the deployment, such as service endpoints and resource IDs. |
`CoinServiceArgs` | Interface describing deployment arguments for an individual blockchain service. |
`getConfig()` | Async function returning Kubernetes config, deployment config, and namespace info. |
`defaultBlockbookServiceArgs` | Predefined default service arguments for Blockbook-based indexer services. |
Example Snippet Extract
const coinServiceArgs = config.statefulService?.services?.map((service): CoinServiceArgs => {
switch (service.name) {
case 'daemon':
return {
...service,
ports: { 'daemon-rpc': { port: 9650 } },
configMapData: {
'c-chain-config.json': readFileSync('../daemon/config.json').toString(),
'evm.sh': readFileSync('../../../scripts/evm.sh').toString(),
},
volumeMounts: [
{ name: 'config-map', mountPath: '/configs/chains/C/config.json', subPath: 'c-chain-config.json' },
{ name: 'config-map', mountPath: '/evm.sh', subPath: 'evm.sh' },
],
startupProbe: { periodSeconds: 30, failureThreshold: 60, timeoutSeconds: 10 },
livenessProbe: { periodSeconds: 30, failureThreshold: 5, timeoutSeconds: 10 },
readinessProbe: { periodSeconds: 30, failureThreshold: 10 },
}
case 'indexer':
return {
...service,
...defaultBlockbookServiceArgs,
configMapData: { 'indexer-config.json': readFileSync('../indexer/config.json').toString() },
}
default:
throw new Error(`no support for coin service: ${service.name}`)
}
})
This completes the comprehensive documentation for `index.ts`.