Preflight specification and validation
Preflight specification preparation turns one or more declarative check documents into a usable check set. It reads the supplied sources, resolves optional templates and values, joins compatible specifications, and checks that the result still has enough collection and analysis work to support an environment decision. See Preflight workflows for the full run and Preflight execution and results for what happens after this boundary.
Specification contract
Cluster specifications
Preflight describes checks for a Kubernetes environment. Its specification can name cluster collectors, remote collectors, analyzers, a result upload destination, and an optional URI for an additional source. These parts connect evidence gathering to the requirements that the preflight reports.
References: pkg/…/preflight_types.go• L23-30
Host specifications
HostPreflight describes checks for the machine that runs the command and for remote host collection. It uses host collectors, remote collectors, and host analyzers, but it does not use the cluster result upload field. This separate contract keeps machine checks distinct from Kubernetes checks.
References: pkg/…/hostpreflight_types.go• L23-29
Input sources
The preflight command accepts a local file, standard input, an HTTP or OCI source, or a Kubernetes Secret or ConfigMap. A source can contain more than one YAML document. The loader keeps only supported Troubleshoot resources and ignores unrelated documents when it builds the in-memory specification set.
References: cmd/…/root.go• L22-35 pkg/…/loader.go• L65-77 pkg/…/loader.go• L171-237
Preparation pipeline
Preparation creates the boundary between flexible delivery and strict execution. Source-specific input is first turned into YAML documents, then template work and source expansion complete the documents before preflight checks use them.
Source loading
The loader splits multi-document YAML and recognizes supported API versions and kinds. It can also extract preflight documents stored in the expected data fields of a Secret or ConfigMap. A malformed document is ignored in the general loader path unless strict loading is requested; the preflight command then reports specification issues as a preflight error.
References: pkg/…/loader.go• L176-237 pkg/…/loader.go• L240-305 pkg/…/loader.go• L440-502
URI expansion
After the initial load, a non-empty uri can add a fetched specification to the loaded set. URI expansion is optional at command level, so a caller can inspect only the supplied documents when URI loading is disabled. A failed fetch is reported as a warning and does not replace the whole preparation step with an unrelated document.
References: pkg/…/read_specs.go• L43-53 internal/…/specs.go• L376-414
Preparation sequence
The following sequence shows how input becomes the validated set passed to execution.
flowchart LR
A[Files, standard input, or remote sources] --> B[Load YAML documents]
B --> C[Resolve templates and values]
C --> D[Expand specification URIs]
D --> E[Combine compatible preflights]
E --> F[Validate usable work]
F --> G[Environment checks]
The sequence matters because validation must inspect the resolved and combined content. An item that exists only inside a disabled template branch is not available to validation or execution.
References: pkg/…/read_specs.go• L20-83 pkg/…/run.go• L54-83
Template resolution
Value precedence
Template values let one preflight describe several environment profiles. Values files are merged from left to right with later values taking precedence. Command-line --set values apply last, so an operator can make a narrow run-time override without changing the shared files.
References: docs/preflight_template.md• L16-45 pkg/…/read_specs.go• L142-165 pkg/…/template.go• L24-44
Conditional checks
Conditional template blocks control which collectors or analyzers become part of the final specification. This lets a profile turn a capability on or off while keeping its related requirement values together. The rendered output contains only the selected checks and can be reviewed with preflight template or with a dry run.
References: examples/…/simple-v1beta3.yaml• L1-60 pkg/…/run.go• L76-83 docs/preflight_template.md• L6-7
Default values
The template path supplies safe structural defaults for missing nested values. Referenced enabled and create flags default to false, while missing parent maps are created so an absent optional profile can omit its branch instead of causing a template lookup failure. Explicit values remain unchanged.
References: pkg/…/values_defaults.go• L18-43 pkg/…/values_defaults.go• L45-118 pkg/…/values_defaults.go• L120-151
Rendering modes
The API version selects the template style. A v1beta3 preflight uses Helm-style .Values expressions and requires at least one values file or --set value when template markers are present. Older templates use the legacy Go template path. A non-templated v1beta2 document passes through without value processing.
References: pkg/…/read_specs.go• L91-139 pkg/…/template.go• L46-67 docs/preflight_template.md• L41-45
Specification assembly
Cluster grouping
Loaded cluster preflights without an upload destination are combined into one logical local check set. Their collectors, remote collectors, and analyzers are appended in input order. A cluster preflight with an upload destination stays separate so its results retain their intended delivery boundary.
References: pkg/…/read_specs.go• L55-72 pkg/…/concat.go• L7-21
Host grouping
Loaded host preflights are combined into one host check set. Their collectors, remote collectors, and analyzers are also appended in input order. The result is kept as a host preflight so execution can preserve the difference between machine evidence and cluster evidence.
References: pkg/…/read_specs.go• L74-81 pkg/…/concat.go• L23-36
Assembly order
Assembly preserves the order in which source documents contribute check items. It does not describe a conflict policy for duplicate collectors or analyzers; each appended item remains part of the resulting set. This supports modular specification ownership while keeping the final run easy to inspect as one resolved document.
References: pkg/…/concat.go• L7-36 pkg/…/loader.go• L122-131
Validation boundary
Validation checks whether the prepared specification can produce a meaningful result. It returns a warning before collection when no preflight exists, when a host preflight lacks a required class of work, or when applied exclusions remove all usable collectors or analyzers.
Cluster validation
A cluster preflight needs at least one analyzer. Its collector check also accounts for the two basic cluster collectors that the cluster path supplies automatically, so excluding every user-defined collector does not always mean that no cluster evidence remains. If all effective collectors or all analyzers are excluded, validation warns instead of allowing a misleading readiness result.
References: pkg/…/validate_specs.go• L12-77
Host validation
A host preflight needs at least one collector and one analyzer. Host validation has no automatic collector allowance, so an empty or fully excluded host collection set is invalid for a meaningful host decision. The same rule applies when all host analyzers are excluded.
References: pkg/…/validate_specs.go• L79-117
Warning behavior
These checks are pre-run warnings rather than environment outcomes. The command prints the warning and returns without collecting data, while a valid specification continues to the execution stage. This distinction prevents an incomplete specification from being reported as a failed or passed environment.
References: pkg/…/run.go• L54-74 pkg/…/validate_specs.go• L12-34
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the accepted source forms aligned between the CLI, URI expansion, Secret or ConfigMap extraction, and the loader’s supported API versions.
- Keep template value precedence aligned between
preflight templateand normal preflight execution so previewed YAML matches the run. - When adding a conditional check, provide a safe path for missing parent values and confirm that the rendered branch still has its required collector and analyzer pair.
- When changing a top-level preflight field, decide whether assembly should preserve, combine, or isolate it across multiple input documents.
- When changing exclusion behavior or automatic collectors, update the validation meaning of an empty effective check set.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
A templated v1beta3 specification has no values | Preparation stops before the checks run. | Supply a values file or a --set value. |
A values file has invalid YAML or a --set value has invalid syntax | The resolved specification is not produced. | Validate each values source before using it in a run. |
| A required template value is missing outside a guarded branch | Rendering can fail or can produce an invalid check expression. | Seed optional branches with defaults and provide every value used by enabled checks. |
| All effective analyzers are excluded | Validation warns and no readiness decision is made. | Inspect the rendered specification and keep at least one analyzer enabled. |
| A host preflight has no effective collectors | Host collection cannot produce evidence and the run stops with a warning. | Keep a host collector enabled when a host analyzer is enabled. |
| A cluster preflight with an upload destination is merged into the local group | Results can cross an intended delivery boundary. | Preserve upload-bearing cluster preflights as separate runs. |
| A URI source cannot be fetched | The fetched contribution is unavailable and a warning is logged. | Keep the URI reachable and use the local specification as the required baseline. |
Key files
| File | Why to read it |
|---|---|
| pkg/…/read_specs.go | Defines the preparation boundary from input sources through templating, URI expansion, and grouping. |
| pkg/…/template.go | Explains value merging, template mode selection, and the standalone template command behavior. |
| pkg/…/values_defaults.go | Shows the default behavior for missing optional template paths. |
| pkg/…/concat.go | Defines how multiple cluster and host specifications become logical check sets. |
| pkg/…/validate_specs.go | Defines the minimum effective work required before environment checks can start. |
| pkg/…/loader.go | Defines accepted YAML document, API version, Secret, ConfigMap, and strict-loading behavior. |
| internal/…/specs.go | Defines CLI source handling and optional URI expansion. |
| pkg/…/preflight_types.go | Defines the high-level cluster preflight contract. |
| pkg/…/hostpreflight_types.go | Defines the high-level host preflight contract. |
| examples/…/simple-v1beta3.yaml | Illustrates one profile selecting several environment checks through conditional values. |