Skip to content

✨ feat(cli): add validate subcommand (PIPE-VALIDATE-01) - #289

Merged
konih merged 1 commit into
mainfrom
feat/pipe-validate-01-config-validate
Aug 10, 2026
Merged

konih merged 1 commit into
mainfrom
feat/pipe-validate-01-config-validate

Conversation

@Xiilent

@Xiilent Xiilent commented Aug 9, 2026

Copy link
Copy Markdown

collect.go's runCollectPipeline calls pipeline.LoadConfig, which only does structural YAML decoding: nothing in cmd/cli or internal/pipeline ran internal/validation. So collect and init silently accepted config directories the operator's admission webhook would reject on create/update, and there was no way to lint a kollect config in CI without a cluster.

kollect-pipeline validate --config <dir> runs the same internal/validation checks the webhook's per-kind validators apply (ValidateProfile, ValidateTargetSpec, ValidateSnapshotSinkSpec + their warning helpers), minus the cluster-dependent KollectScope checks that need a live client. Warnings go to stderr and don't fail the run; invalid objects go to stderr and exit 2.

@Xiilent
Xiilent requested a review from konih as a code owner August 9, 2026 09:24
@codecov

codecov Bot commented Aug 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@konih
konih force-pushed the feat/pipe-validate-01-config-validate branch from ca2711c to c799abd Compare August 10, 2026 14:42
collect.go's runCollectPipeline calls pipeline.LoadConfig, which only does
structural YAML decoding: nothing in cmd/cli or internal/pipeline ran
internal/validation. So collect and init silently accepted config directories
the operator's admission webhook would reject on create/update, and there was
no way to lint a kollect config in CI without a cluster.

`kollect-pipeline validate --config <dir>` runs the same internal/validation
checks the webhook's per-kind validators apply (ValidateProfile, ValidateTargetSpec,
ValidateSnapshotSinkSpec + their warning helpers), minus the cluster-dependent
KollectScope checks that need a live client. Warnings go to stderr and don't
fail the run; invalid objects go to stderr and exit 2.
@konih
konih force-pushed the feat/pipe-validate-01-config-validate branch from c799abd to 2f094ca Compare August 10, 2026 14:44
@sonarqubecloud

Copy link
Copy Markdown

@konih konih left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REVIEW: APPROVE (external-contributor path — reviewed per /merge-open-prs Step 3)

The claim under test: does validateLoaded actually mirror the webhooks? A hand-written mirror of another package's validation is the failure mode that matters here — drift is silent and turns a green validate into a false assurance. Checked it call-for-call against the three webhook sources rather than taking the PR description's word for it:

Webhook Calls In validateLoaded?
kollectprofile_webhook.go ValidateProfile, ProfileInvalid, ProfileWarnings all three ✅
kollecttarget_webhook.go ValidateTargetSpec, TargetInvalid both ✅ (no target warning helper exists, so nothing is skipped)
family_sink_webhook.go ValidateSnapshotSinkSpec, SnapshotSinkInvalid, ValidateGitSinkWarnings, ValidateSinkConfigWarnings all four ✅

The only sink-webhook calls not mirrored are ValidateSinkIntervalAgainstScopeFloor / ScopeLoadErrors / ScopeMinExportInterval — exactly the cluster-dependent KollectScope checks, and the Long help text tells the operator so. The exclusion set is accurate and documented, which is what makes this safe to trust in CI.

ValidateDatabaseSinkSpec / ValidateEventSinkSpec are absent, correctly: pipeline.LoadConfig does not load those kinds at all, so validate covers exactly what the pipeline itself supports.

Unknown kinds are not a silent pass. Worth noting since a linter that ignores what it doesn't recognize is worse than no linter: decodeDocuments records unregistered kinds as warnings (deliberate CRD forward-compat), and runValidate prints loaded.Warnings to stderr before its own. So a typo'd kind: surfaces as warning: skipped unknown kind ... rather than vanishing. It still exits 0 — acceptable given the documented forward-compat intent.

Other

  • ExitFatalError = 2 (cmd/cli/exitcode.go:17) matches the PR description's stated exit-2 contract.
  • Warnings → stderr and non-fatal; invalid → stderr and exit 2; the success line → stdout. Correct stream discipline for a CI linter.
  • PersistentPostRun gains the validate case alongside collect/init, so the exit code actually propagates rather than defaulting to 0.
  • Profiles/sinks continue past warning collection once invalid — right call, warnings on an already-rejected object are noise.

Non-blocking observation — validateLoaded enumerates LoadResult's kinds by hand, so if a future kind is added to LoadResult the compiler will not force a matching validator here; it would just be skipped. Bounded and low-risk today (the struct has four fields, Secrets being correctly out of scope), but a compile-time coupling or a guard test would keep it honest as the CRD set grows.

Rebased onto main after #288/#290 landed and re-verified green — the pre-rebase run did not cover the interaction with #290's .go-arch-lint.yml change or #288's edit to the same doc file.

@konih
konih merged commit b4399fb into main Aug 10, 2026
36 checks passed
@konih
konih deleted the feat/pipe-validate-01-config-validate branch August 10, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants