UNPKG

@cdklib/argo-synth

Version:

Manage ArgoCD structure with cdk8s

92 lines (88 loc) 3 kB
import * as constructs from 'constructs'; import * as cdk8s from 'cdk8s'; import { Chart, App } from 'cdk8s'; /** * Configuration for a GitOps Helm chart. * * @see {@link GitOpsHelmChart} */ type GitOpsHelmChartConfig = { /** Name of the Helm chart */ name: string; /** Repository of the Helm chart */ repository: string; /** Version of the Helm chart */ version: string; /** Values to pass to the Helm chart */ values: Record<string, unknown>; /** Synth path (relative to the cdk8s App) to save the umbrella chart */ synthPath: string | string[]; }; /** * Creates a Helm umbrella chart for Kubernetes addons. * * You can create Argo applications that point to this directory to manage the helm chart. * * The chart and full values are rendered to the output directory. * * Api Objects under the Helm Chart are rendered to the template/ directory, and will be managed by argo */ declare class GitOpsHelmChart extends Chart { readonly name: string; readonly version: string; readonly repository: string; readonly values: Record<string, unknown>; constructor(scope: App, { name, values, synthPath, version, repository }: GitOpsHelmChartConfig); } /** * ArgoSynth provides utilities for organizing and synthesizing CDK8s apps into * directory structures that work well with ArgoCD's path-based application definitions. * * @example * ```typescript * import { App, Chart } from 'cdk8s'; * import { ArgoSynth } from '@cdklib/argo-synth'; * * // Create an app for each environment * const stagingApp = new App(); * const prodApp = new App(); * * // Create charts for your services * const stagingWebChart = new Chart(stagingApp, 'web'); * const prodWebChart = new Chart(prodApp, 'web'); * * // Set paths for ArgoCD directory structure * ArgoSynth.addPath(stagingWebChart, 'staging', 'web'); * ArgoSynth.addPath(prodWebChart, 'prod', 'web'); * * // Synthesize to output directory * await ArgoSynth.synth('gitops', [stagingApp, prodApp]); * ``` * * This creates a directory structure like: * ``` * gitops/ * ├── staging/ * │ └── web/ * │ └── ... (manifests) * └── prod/ * └── web/ * └── ... (manifests) * ``` * * Which maps cleanly to ArgoCD applications targeting paths like: * - `staging/web` * - `prod/web` */ declare class ArgoSynth { /** Synthesizes multiple applications with regards to ArgoCD paths */ static synth: (outputPath: string, apps: cdk8s.App[], { clean, summary }?: { clean?: boolean; summary?: boolean; }) => Promise<void>; /** Adds a suffix to the synthesized path for ArgoCD apps */ static addPath: (scope: constructs.Construct, ...suffixes: string[]) => void; /** Gets the synth path for the cdk8s App / Chart */ static getPath: (scope: constructs.Construct) => string; } export { ArgoSynth, GitOpsHelmChart, type GitOpsHelmChartConfig as GitOpsHelmChartOptions };