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:

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

Parameters

Returns


Internal Steps and Variables

  1. Constants

    const appName = 'unchained'
    const coinstack = 'avalanche'
    
    • appName: The application name under which this coinstack is deployed.

    • coinstack: The blockchain identifier, here "avalanche".

  2. Reading the Sample Environment File

    const sampleEnv = readFileSync('../sample.env')
    
    • Reads the .env sample file that contains environment variables required for the deployment.

    • This raw environment data will be parsed and injected as Kubernetes Secrets during deployment.

  3. 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.

  4. 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 CoinServiceArgs object customized per service type.

    **Service-specific configurations:**

    • Daemon Service

      • Ports:

        • Exposes daemon-rpc on port 9650.

      • ConfigMap Data:

        • Mounts c-chain-config.json read from a local file.

        • Mounts evm.sh lifecycle script.

      • Volume Mounts:

        • Mounts the above ConfigMap data into container paths.

      • Kubernetes Health Probes:

        • startupProbe, livenessProbe, and readinessProbe with 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.json read 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


Interaction with Other System Components


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`.