Repository navigation
✨ feat(cli): add validate subcommand (PIPE-VALIDATE-01) - #289
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
ca2711c to
c799abd
Compare
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.
c799abd to
2f094ca
Compare
|
konih
left a comment
There was a problem hiding this comment.
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.
PersistentPostRungains thevalidatecase alongsidecollect/init, so the exit code actually propagates rather than defaulting to 0.- Profiles/sinks
continuepast 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.



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.