How kapicorp/kapitan works
Project Type and Purpose
• Kapitan is an advanced configuration management CLI tool written in Python.
• It compiles declarative inventory, templates, and secrets into deployment-ready manifests (YAML, JSON, Terraform, etc.).
• It provides pluggable backends for inventory (Reclass, OmegaConf), input types (jsonnet, jinja2, helm, copy, external), and secret managers (AWS KMS, GCP KMS, Vault, GPG).
High‑Level Architecture Components
a. Presentation Layer
• kapitan CLI entrypoint (bin/kapitan, kapitan/__main__.py)
• Argument parser & command dispatcher (kapitan/cli.py)
b. Application Core
• Initialiser (kapitan/initialiser.py)
• Inventory loader & model (kapitan/inventory/*)
• Input handlers (“compiler adapters”) (kapitan/inputs/*)
• Dependency manager (kapitan/dependency_manager/*)
• Reference resolvers & secrets (kapitan/refs/*)
• Resource library & helpers (kapitan/lib, kapitan/resources.py)
• Validation & linting (kapitan/lint.py, kapitan/validate)
c. External Integrations
• Template engines & tools: Jsonnet, Jinja2, Helm, Kadet
• Secret backends: AWS KMS, GCP KMS, Azure Key Vault, Vault KV/transit, GPG
• Inventory backends: Reclass, OmegaConf
• Optional Docker environment (Dockerfile, container image)
d. Output Layer
• Compiled artifacts written to <target>/compiled directories
• Exported scripts (e.g., apply.sh, kubectl.sh) and manifests (YAML/JSON/Terraform)
Relationships & Interactions
• User invokes kapitan <command> --inventory=<inv> --output=<out>.
→ CLI parses and routes to the Initialiser.
• Initialiser calls the Inventory Loader, which:
→ loads inventory files via selected backend (Reclass/OmegaConf).
• The Compile Engine orchestrates:
→ Input modules pull in components and templates.
→ Reference resolvers decrypt or fetch secrets.
→ Dependency manager orders component renderings.
→ Each input type invokes external tool or library (e.g., run jsonnet, helm template, apply Jinja2 filters).
• Outputs are written to the file system under compiled/ or other target directories.
• Validation & linting modules validate the resulting manifests’ schema, formatting, and policies.
Architectural Patterns & Principles
• Plug‑in/Strategy pattern for inputs, inventory backends, and secret backends.
• Layered Architecture separating CLI, core logic, extension interfaces, and external systems.
• Single Responsibility modules (one module per input type, one per secret backend, etc.).
• Extensibility: new input types or backends drop in under kapitan/inputs or kapitan/refs/secrets.
Elements
• Arrowheads indicating flow direction.
• Rectangles for internal modules
• Clouds for external services