-
-
Notifications
You must be signed in to change notification settings - Fork 210
[feat]: return list of discovered targets #1392
Description
Description of the feature
Feature Request: kapitan list --targets
Summary
Add a kapitan list --targets command to quickly enumerate all discovered targets, with support for multiple output formats (plain, JSON, YAML) to enable tooling integration and shell autocompletion.
Motivation
Currently, discovering available targets requires either:
- Manually inspecting the
inventory/targets/directory structure - Running a full
kapitan compileand observing output - Parsing inventory files directly with external tools
This creates friction for:
- Shell autocompletion — Tab-completing
kapitan compile -t <TAB>requires knowing valid targets - CI/CD pipelines — Dynamic target discovery for matrix builds or selective compilation
- IDE/editor integration — Providing target suggestions in development environments
- Scripting — Wrapping Kapitan in higher-level automation without hardcoding target lists
Proposed Solution
Command Interface
# Plain list (default) — one target per line
kapitan list --targets
# JSON output
kapitan list --targets --output-format=json
kapitan list --targets -o json
# YAML output
kapitan list --targets --output-format=yaml
kapitan list --targets -o yamlOutput Examples
Plain (default):
production/cluster-eu-west-1
production/cluster-us-east-1
staging/cluster-staging
dev/local
JSON:
{
"targets": [
"production/cluster-eu-west-1",
"production/cluster-us-east-1",
"staging/cluster-staging",
"dev/local"
]
}YAML:
targets:
- production/cluster-eu-west-1
- production/cluster-us-east-1
- staging/cluster-staging
- dev/localPerformance Considerations
Speed is critical for this feature, particularly for autocompletion where latency directly impacts UX. Target times should be < 100ms for typical inventories.
Recommended Implementation Approach
-
Minimal inventory loading — Only discover target names from filesystem paths; avoid full inventory compilation/reclass resolution
-
Skip class resolution — Don't process
classes:inheritance chains; just enumerate files ininventory/targets/ -
Lazy imports — Defer heavy module imports (Jinja2, reclass, etc.) that aren't needed for simple enumeration
-
Consider caching — Optional: cache target list with filesystem mtime checking for very large inventories
-
Parallel directory walking — For inventories with deep nesting,
os.scandir()or similar efficient directory traversal
Additional Considerations
Future Extensibility
The kapitan list subcommand could later support:
- `kapitan list --targets production/* — glob filtering
Flags
| Flag | Short | Description |
|---|---|---|
--output-format |
-o |
Output format: plain (default), json, yaml |
--inventory-path |
-i |
Override inventory path (existing global flag) |
Acceptance Criteria
-
kapitan list --targetsreturns all targets, one per line -
-o jsonoutputs valid JSON with{"targets": [...]}structure -
-o yamloutputs valid YAML withtargets:list - Execution completes in < 100ms for inventories with 100+ targets
- No inventory compilation or class resolution performed
- Exit code 0 on success, non-zero on errors
- Works with
--inventory-pathoverride
Additional context
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
Status