Standalone collector and analyzer CLIs
The repository provides three dedicated command-line programs for troubleshooting workflows: collect gathers diagnostic data, analyze evaluates a support bundle, and preflight performs both steps as a readiness check. Each program is a thin command layer over a workflow package, so the same collection and analysis rules can also serve other callers.
Command roles
The three executables divide the troubleshooting lifecycle into reusable stages. The division lets an operator collect data for later use, analyze an existing bundle without access to the target cluster, or run a complete preflight check in one command.
| Executable | Main input | Main result | Workflow package |
|---|---|---|---|
collect | A collector specification from a file, URL, stdin, or Kubernetes Secret | Collector data on stdout as JSON or raw JSON | pkg/collect |
analyze | A support-bundle archive and an analyzer specification | Pass, warning, or failure results on stdout or in an output file | pkg/analyze |
preflight | One or more preflight specifications | Human or machine-readable check results plus a temporary archived bundle | pkg/preflight, with pkg/collect and pkg/analyze |
The standalone programs share the repository's Kubernetes connection flags, logging setup, version command, and profiling support. Their environment settings use the TROUBLESHOOT_ prefix for collect and analyze, while preflight uses PREFLIGHT_ for its own settings. These shared conventions make the programs fit the broader command-line applications family without making them one combined workflow. See CLI troubleshooting for guidance when a command cannot reach its input or target environment.
Collection command
The collect executable is the data-gathering entry point. It accepts a collector specification and selects the collection path from its kind: host collection runs on the machine where the command executes, while remote collection uses Kubernetes to gather data from selected nodes. The command can also expose selected collector types as subcommands so a collector can run inside a troubleshooting pod.
The command sends collected data to standard output. JSON presents the data as structured collector results. Raw output preserves the per-file JSON strings needed by a remote collector. The command applies redaction settings before it reports results and can use Kubernetes, namespace, node-selector, image, and timeout settings when a collection path needs cluster access.
References: home/…/main.go• L1-10 home/…/root.go• L15-89 home/…/run.go• L30-188 home/…/stdout_results.go• L11-102
Analysis command
The analyze executable is the bundle-reading entry point. It loads a support-bundle archive, applies analyzer specifications from a file or URL when requested, and turns the collected files into analysis results. It does not collect new cluster data, so it can run in a separate environment after collect or another producer creates the bundle.
The command supports the regular local analysis path and an advanced path with registered analysis agents. The advanced path can include local analysis and optional Ollama-based analysis. The result view shows the overall outcome and can write a JSON result file. Utility flags can inspect or prepare Ollama without a bundle; normal analysis still requires one.
References: home/…/main.go• L1-13 home/…/root.go• L16-101 home/…/run.go• L29-64 home/…/run.go• L230-331 home/…/run.go• L578-710
Preflight command
The preflight executable is the complete readiness-check entry point. A preflight specification describes the data to collect and the checks to apply. The command reads specs from a URL, local file, stdin, or supported cluster resources, then combines compatible specs before it runs the workflow.
The main run creates a temporary bundle directory, collects cluster and host data, applies analyzers to that data, stores analysis results in the bundle, and archives the bundle. It presents results in interactive or text form and returns distinct exit statuses for pass, warning, failure, and specification problems. This makes preflight suitable for both a person checking a cluster and automation gating an install or upgrade.
References: home/…/main.go• L1-10 home/…/root.go• L22-120 home/…/read_specs.go• L20-83 home/…/run.go• L36-83 home/…/run.go• L89-233
Preflight support commands
The preflight executable also owns commands that prepare or inspect preflight specifications. These commands do not replace the main run; they help move a specification into a form that the run can consume.
| Command | Purpose |
|---|---|
preflight template | Render a templated specification with values. |
preflight docs | Extract documentation from enabled requirements. |
preflight convert | Convert a v1beta2 preflight into a v1beta3 templated spec and values file. |
preflight lint | Find syntax and structural problems before a run. |
preflight oci-fetch | Fetch a preflight from an OCI registry and print it. |
The support commands use the same preflight binary and configuration boundary. Their output can feed the main run or a review step in a release pipeline.
References: home/…/root.go• L91-110 home/…/template.go• L8-40 home/…/docs.go• L19-61 home/…/convert.go• L15-70 home/…/lint.go• L15-73 home/…/oci_fetch.go• L13-39
Workflow package boundaries
The command packages define user-facing input and output. The workflow packages define what collection and analysis mean. This boundary keeps the core behavior available to the preflight flow and to other callers without requiring them to construct a Cobra command.
Collection package
The pkg/collect package maps collector specifications to collector types and returns collected data as file-keyed byte content. Its public collection paths cover host and remote collectors. The package also carries the options needed to reach Kubernetes and report progress, while individual collector types supply the domain-specific data.
The standalone collect command translates CLI arguments into these collection options. The preflight package uses the same collection concepts but adds bundle storage, permission checks, progress handling, and orchestration for a full readiness run.
References: home/…/collect.go• L23-57 home/…/collect.go• L56-95 home/…/collect.go• L97-197 home/…/interfaces.go• L8-31 home/…/collect.go• L26-38
Analysis package
The pkg/analyze package maps analyzer specifications to analyzer types and evaluates them against named collected files. An analyzer produces an AnalyzeResult with an outcome and message. The package can also read local or node-specific collected content through the callbacks supplied by its caller.
The standalone analyze command loads an archive and chooses its analysis mode. The preflight package already has collected data in memory or in its temporary bundle, so it calls the same analysis rules directly and then writes the results back into the bundle.
References: home/…/analyzer.go• L27-43 home/…/analyzer.go• L66-98 home/…/analyzer.go• L115-160 home/…/analyze.go• L15-49 home/…/analyze.go• L52-138
Preflight orchestration
The pkg/preflight package is the bridge between a preflight specification and the two lower-level workflow packages. It resolves the specification, invokes collection for cluster, host, and remote paths, gathers the results into one bundle view, invokes analysis, and maps outcomes to command exit codes.
This relationship means a preflight run is not a third kind of collector or analyzer. It is a coordinated workflow that adds readiness-specific concerns such as spec validation, temporary bundle creation, result upload, archive creation, and interactive progress around the shared collection and analysis capabilities.
References: home/…/run.go• L118-190 home/…/run.go• L192-233 home/…/collect.go• L169-366 home/…/analyze.go• L52-138
End-to-end data flow
The standalone commands can form a staged workflow, while preflight performs the same broad stages in one process. This diagram shows the main relationship between specifications, collected data, analysis, and the final result.
flowchart LR
CS[Collector specification] --> C[collect]
C --> B[Support-bundle data]
B --> A[analyze]
AS[Analyzer specification] --> A
A --> R[Analysis results]
PS[Preflight specification] --> P[preflight]
P --> PC[Collect through pkg/collect]
PC --> PA[Analyze through pkg/analyze]
PA --> PB[Archived preflight bundle]
PA --> PR[Preflight outcome and exit status]
The key handoff is the collected file set. Analyzer rules name files or file groups in that set, so a collector change can affect analysis even when the analyzer code does not change. Remote results add node context before analysis so the same check can report which node produced an outcome.
Staged collection and analysis
The staged path is useful when collection and analysis need different access or run times. collect needs access to the target data source. analyze needs only the resulting bundle and analyzer rules, which allows later review or repeat analysis with a different analyzer specification.
References: home/…/run.go• L138-185 home/…/run.go• L460-529 home/…/collected_contents.go• L21-59
Integrated preflight flow
The integrated path keeps collection and analysis in one readiness check. Collection failures and permission limits affect which data reaches the analyzer, while the final analyzer outcomes determine the process status used by calling automation.
References: home/…/run.go• L123-187 home/…/run.go• L204-233 home/…/run.go• L267-285
CLI entrypoints
Each executable has a small main package and a CLI package that builds the root command. The main package starts command execution; the CLI package defines arguments, flags, subcommands, shared setup, and the call into the workflow package.
| Program | Process entrypoint | Root command | Primary execution call |
|---|---|---|---|
collect | cmd/…/main.go | cmd/collect/cli.RootCmd | runCollect |
analyze | cmd/…/main.go | cmd/analyze/cli.RootCmd | runAnalyzers |
preflight | cmd/…/main.go | cmd/preflight/cli.RootCmd | preflight.RunPreflights |
The root commands also establish logging and profiling before workflow execution. preflight has extra exit-code handling because a warning or failed check is a meaningful result rather than only a command error.
References: home/…/main.go• L8-10 home/…/main.go• L9-11 home/…/main.go• L8-10 home/…/root.go• L67-87
Change checklist
When these files or sections are changed, remember to consider these:
- A collector's output file names or nesting must stay aligned with analyzer file lookups and with remote node result paths.
- Changes to the preflight result model must stay aligned with bundle serialization, text or interactive display, upload behavior, and exit-code mapping.
- Changes to a root command's flag name or environment prefix must be checked against the workflow options that read the value and the documented command examples.
- Changes to preflight spec loading or templating must preserve the handoff from rendered input to validation, concatenation, collection, and analysis.
- Changes to raw collector output must preserve the quoted JSON shape expected by the remote collector path.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A collector specification names an unsupported host collector | collect cannot create the requested collector and stops with an error | Validate collector kind and name before relying on its output. |
| The Kubernetes identity lacks required permissions | Cluster collection can stop before all collectors run, or individual collectors are skipped | Use the permission check and decide whether collect-without-permissions is acceptable for the run. |
| A collector does not produce the file named by an analyzer | The analyzer returns a failed result or has no usable input | Keep collector output paths and analyzer file references as one contract. |
| The analyzer specification or support bundle cannot be read | analyze cannot produce analysis results | Check the input path or URL and the archive format before analysis. |
| A preflight has no collected data or no analysis results | preflight returns a non-success exit status even if the process reached the workflow | Treat collection coverage and analyzer coverage as required inputs to a useful preflight. |
| An Ollama agent is requested without an installed service or model | Advanced analysis cannot register the requested agent | Run the Ollama status or setup utility before enabling that agent. |
Key files
| File | Why to read it |
|---|---|
| cmd/…/main.go | Shows the process entrypoint for the standalone collector. |
| cmd/…/root.go | Defines the collector command contract and shared CLI setup. |
| cmd/…/run.go | Shows how collector specifications become calls into pkg/collect. |
| cmd/…/stdout_results.go | Defines the JSON and raw output shapes. |
| cmd/…/main.go | Shows the process entrypoint for the standalone analyzer. |
| cmd/…/root.go | Defines bundle requirements and analysis-related command options. |
| cmd/…/run.go | Shows bundle loading, analyzer loading, analysis selection, and result display. |
| cmd/…/main.go | Shows the process entrypoint for the preflight executable. |
| cmd/…/root.go | Defines the preflight run and its specification utility commands. |
| pkg/…/run.go | Shows the complete collect, analyze, archive, display, and exit-status flow. |
| pkg/…/collect.go | Shows how preflight collection uses cluster, host, and remote collection paths. |
| pkg/…/analyze.go | Shows how collected data is passed to analyzers, including node context. |
| pkg/…/collect.go | Defines the reusable host and remote collection boundary. |
| pkg/…/analyzer.go | Defines analyzer lookup, execution, and result behavior. |