How capsailer/capsailer-cli works
Project Type and Purpose
• Capsailer is a Go-based CLI tool focused on packaging Helm charts and container images into a single “bundle” and deploying them into air-gapped Kubernetes environments. It orchestrates local registry setup, bundle creation, bundle unpacking, and artifact pushing—entirely self-contained, without Docker, skopeo, or internet access on the target cluster.
File Structure Analysis
• Top-level “cmd/capsailer”: entry point (main.go) and subcommand definitions (commands.go).
• “pkg/…”: core modules grouped by feature:
• pkg/build: bundle creation logic (builder.go)
• pkg/deploy: registry deployment logic onto K8s (deployer.go)
• pkg/helm: chart discovery and analysis
• pkg/image: image handling (download, storage)
• pkg/registry: registry interactions (push, pull)
• pkg/utils: shared helpers (manifest loading, archiving, unpacking, progress)
• “docs/” + “.github/” + “examples/”: documentation, CI workflows, usage samples.
• Configuration: go.mod/go.sum, Makefile, mkdocs.yml for docs site, requirements.txt for MkDocs.
Key Architectural Patterns
• CLI + subcommand pattern (likely Cobra under the hood).
• Modular service layers: builder, deployer, registry client, manifest loader.
• Clear separation of concerns: image vs. chart vs. registry vs. file utilities.
• External integration points: Kubernetes API, Helm chart repositories, OCI registry protocols.
Main Components
a. User & CLI Frontend
• User invokes capsailer [init|build|registry|push|unpack]
• CLI parses command, delegates to internal modules.
b. Manifest Loader (pkg/utils/manifest_loader.go)
• Reads user’s YAML manifest → list of images & charts.
c. Build Pipeline (pkg/build/builder.go)
• Image Downloader (pkg/image)
• Helm Chart Analyzer & Fetcher (pkg/helm)
• Archiver (pkg/utils/archive.go) producing bundle.tar.gz
d. Air-gapped Deployment
• Registry Deployer (pkg/deploy/deployer.go) → interacts with Kubernetes API
• Registry Service (ChartMuseum for charts + OCI registry for images)
e. Push Pipeline (pkg/registry & pkg/utils/unpacker.go)
• Unpack bundle → extract images & charts
• Push to in-cluster registry and helm repo
f. External Systems
• Kubernetes cluster’s API server
• Container registry endpoint
• Helm chart repository (ChartMuseum)
Relationships & Data Flows
• CLI → Manifest Loader → Build Pipeline → Bundle artifact
• CLI “registry” → Registry Deployer → K8s API → Deploy registry pods + services
• CLI “push” → Unpacker → Registry Client → push images/charts to registry
• User’s Helm commands interact with deployed ChartMuseum service