config.ts

Overview

The [config.ts](/projects/291/68824) file provides a robust mechanism to load, validate, and expose configuration settings required for deploying and running an application stack using Pulumi—a modern infrastructure as code tool. This file’s primary purpose is to retrieve configuration values from Pulumi’s state and ensure all required parameters are present and valid before deployment proceeds.

It defines a `Config` interface representing the shape of the configuration object returned, and an asynchronous `getConfig()` function that:

This file is critical for ensuring consistency, correctness, and readiness of deployment configurations before any infrastructure or application resources are provisioned or updated.


Detailed Documentation

Constants

SUPPORTED_NETWORKS: string[]


Interface: Config

export interface Config {
  kubeconfig: string
  config: BaseConfig
  namespace: string
}

Function: getConfig

export const getConfig = async (): Promise<Config>
import { getConfig } from './config'

async function deploy() {
  try {
    const { kubeconfig, config, namespace } = await getConfig()
    console.log(`Deploying to namespace ${namespace} on cluster with config:`, kubeconfig)
    // Proceed with deployment logic using config and kubeconfig
  } catch (error) {
    console.error('Configuration error:', error)
    process.exit(1)
  }
}

deploy()

Important Implementation Details and Algorithms


Interactions with Other Parts of the System


Mermaid Diagram: Flowchart of getConfig() Function Workflow

flowchart TD
    A[Start: Call getConfig()] --> B[Load base config from Pulumi config ('coinstack')]
    B -- success --> C[Create StackReference using config.stack]
    B -- failure --> Z[Throw RunError: Missing configuration]

    C --> D[Fetch kubeconfig, namespaces, defaultNamespace from StackReference]
    D --> E[Derive namespace based on environment]
    E --> F{Is namespace valid?}
    F -- No --> Z2[Throw Error: Invalid environment namespace]
    F -- Yes --> G[Fetch dockerhub and rootDomainName outputs]

    G --> H[Validate required config fields]
    H --> I{Any missing required fields?}
    I -- Yes --> Z3[Throw Error: Missing configuration keys]
    I -- No --> J[Return { kubeconfig, config, namespace }]

    Z --> End[End]
    Z2 --> End
    Z3 --> End

Summary

The [config.ts](/projects/291/68824) file is a critical utility module that:

This design promotes modularity, reusability, and robustness in the infrastructure deployment process.