statefulService.ts


Overview

The **statefulService.ts** file provides core functionality to define and deploy stateful blockchain services (such as daemons and indexers) on Kubernetes using Pulumi, a programmable infrastructure as code tool. It exposes two main functions:

This file automates the translation of high-level blockchain service parameters and lifecycle scripts into Kubernetes-native constructs, enabling scalable, maintainable, and secure deployments on a Kubernetes cluster.


Detailed API Documentation

Types and Imports


Function: createCoinService

function createCoinService(args: CoinServiceArgs, assetName: string): Service

Purpose

Generates a service specification object representing a single blockchain coinstack component (e.g., daemon, indexer). This includes container definitions, port mappings, environment variables, persistent volume claims, lifecycle probe scripts (init, startup, readiness, liveness), and resource limits.

Parameters

Returns

Description and Usage

Example

const daemonService = createCoinService({
  name: 'daemon',
  image: 'shapeshiftdao/bitcoin-daemon:latest',
  ports: { rpc: { port: 8332 } },
  env: { BITCOIN_NETWORK: 'mainnet' },
  cpuLimit: '1000m',
  memoryLimit: '1Gi',
  storageSize: '10Gi',
  storageClassName: 'gp3',
  useMonitorContainer: true,
}, 'bitcoin')

console.log(daemonService.name) // 'bitcoin-daemon'
console.log(daemonService.containers.length) // 2 (main + monitor container)

Function: deployStatefulService

async function deployStatefulService(
  appName: string,
  assetName: string,
  provider: k8s.Provider,
  namespace: string,
  config: Pick<Config, 'rootDomainName' | 'environment' | 'statefulService'>,
  services: Service[],
  volumes?: Array<k8s.types.input.core.v1.Volume>
): Promise<void>

Purpose

Deploys an array of stateful blockchain services as a Kubernetes StatefulSet with supporting resources: Service, ConfigMap, TLS certificates, Traefik ingress routes, and persistent storage. This function orchestrates the full lifecycle deployment of stateful services within a namespace.

Parameters

Returns

Description and Usage

Example

await deployStatefulService(
  'bitcoin-app',
  'bitcoin',
  k8sProvider,
  'default',
  {
    rootDomainName: 'example.com',
    environment: 'prod',
    statefulService: { replicas: 3 },
  },
  [daemonService, indexerService],
  []
)

Implementation Details and Algorithms


Interaction with Other System Components


Visual Diagram: Class and Function Structure

classDiagram
    class createCoinService {
        +args: CoinServiceArgs
        +assetName: string
        +returns Service
    }
    class deployStatefulService {
        +appName: string
        +assetName: string
        +provider: k8s.Provider
        +namespace: string
        +config: Pick<Config, 'rootDomainName' | 'environment' | 'statefulService'>
        +services: Service[]
        +volumes?: k8s.types.input.core.v1.Volume[]
        +returns Promise<void>
    }
    createCoinService <.. deployStatefulService : uses >

Summary

The **statefulService.ts** file is a critical part of the blockchain coinstack deployment automation system. It abstracts the complexity of Kubernetes StatefulSet resource creation for stateful blockchain node services, with rich support for lifecycle scripts, health probes, persistent storage, secure ingress, and TLS certificates. By converting declarative service arguments into Kubernetes manifests programmatically via Pulumi, it enables repeatable, configurable, and scalable deployments suited to the unique requirements of blockchain infrastructure components.