How helm/chart-testing works
Project type and purpose
• This is a Go-based, open-source, command-line tool named “ct” (Chart Testing) for linting and testing Helm charts in CI/CD workflows.
• It detects which charts have changed (via Git), lints them (using Yamllint/Yamale), installs them (via Helm), and optionally runs tests against a Kubernetes cluster (via Kubectl).
File structure
• Top‐level binaries and scripts:
• Dockerfile, build.sh, setup.sh – build and packaging
• ct/main.go + ct/cmd/*.go – the CLI entrypoint and subcommands (cobra)
• Core packages under pkg/:
• pkg/chart – chart detection and representation
• pkg/config – config file / environment / CLI flag handling (Viper)
• pkg/exec – unified command execution engine
• pkg/ignore – chart ignore logic
• pkg/tool – wrappers for external tools (helm, kubectl, git, linters)
• pkg/util – miscellaneous helpers
• Examples/ and etc/ – sample charts, CI config, lint rules, config schemas
• doc/ – user documentation per command
README for additional insights
• Confirms use of external tools: Helm, Git, Yamllint, Yamale, Kubectl
• Describes configuration hierarchy (flags > env vars > config file)
• Provides usage patterns: local repo vs remote repo vs Docker image
Main components of the system
a. CLI Frontend
– “ct” binary built from ct/main.go + ct/cmd
– Parses user input (CLI flags, env vars, config file via pkg/config)
b. Core Engines
– Chart Detector (pkg/chart + Git wrapper in pkg/tool)
– Linter Engine (pkg/tool → Yamllint, Yamale)
– Installer Engine (pkg/tool → Helm, optionally Kubectl for tests)
– Executor (pkg/exec) to unify calls to external tools
– Ignore Filter (pkg/ignore) to exclude directories/charts
c. External Services/Systems
– Source Control (Git repo)
– Helm Repositories / OCI Registries
– Kubernetes Cluster (for install & tests via Kubectl)
d. Configuration Store
– Config file(s) on host or in /etc/ct, ~/.ct (parsed by pkg/config)
– Environment variables (CT_*)
– CLI flags
Relationships and interactions
1. User → CLI Frontend (ct)
2. CLI Frontend → Config Loader (pkg/config)
3. CLI Frontend → Chart Detector
– Chart Detector calls Git wrapper to list changed files
– Filters through Ignore Filter
4. For each chart:
a. Linter Engine → spawns Yamllint/Yamale
b. Installer Engine → invokes Helm to install charts into cluster
c. (Optional) Test Runner → invokes Kubectl to verify resources
5. Executor provides a unified interface for all external calls
6. Results → CLI Frontend → console output / CI exit codes
Architectural patterns and design principles
• Modular, layered design: separation of concerns between CLI handling, configuration, business logic (chart detection, linting, installing), and external tool execution
• Use of adapters/wrappers (pkg/tool) to isolate direct calls to external binaries
• Dependency injection via pkg/exec so all command calls are testable
• Configuration precedence follows Viper best practices
• Single‐binary distribution; Docker container wraps the binary plus dependencies
Relevant technologies/frameworks/libraries
• Go modules (go.mod)
• Cobra for CLI (ct/cmd)
• Viper for configuration (pkg/config)
• External binaries: helm, git, kubectl, yamllint, yamale
• Goreleaser (build.sh + .goreleaser.yml) for release automation
• Docker for packaging
1. Sketch the user interaction at the top (User invokes ct ...).