Skip to content

✨ feat(sink): retract exported objects on inventory deletion, un-wedge finalization (K-28/K-29/K-30) - #382

Closed
konih wants to merge 1 commit into
mainfrom
fm/kollect-b6-deletion
Closed

konih wants to merge 1 commit into
mainfrom
fm/kollect-b6-deletion

Conversation

@konih

@konih konih commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

TL;DR

  • What: inventory deletion now physically retracts exported snapshot objects (git both engines, GitLab, S3/GCS, local) and no longer wedges in Terminating when its sink was deleted first; terminal cleanup wedges become alertable and escapable. Fixes K-28, K-29, K-30 (unify-report batch B6, captain call C-2a).
  • Why: deletion reported silent success over retained data (K-28), a missing sink CR blocked the whole namespace cascade (K-29), and the finalizer wedge had neither a metric nor an operator escape (K-30).
  • Risk: finalizer-path behaviour changes for git/gitlab/s3/gcs/local sinks; deletes objects in user backends on inventory deletion (gated on the exact inventory/<ns>/<name> identity + deterministic part siblings — sibling-inventory safety is test-locked).
  • Reviewer action: read internal/sink/cleanup.go (routing + when retention must be announced) first; the engine delete.go files then follow from it.

Summary

  • sink.ExportCleaner (new seam): DeleteExport(ctx, paths) ([]string, error) returns what was actually removed; sink.RunCleanupExport routes relational sinks to the existing empty-export prune, cleaner backends to object deletion, and everything else to an announced retention (CleanupRetained Warning Event, deletion still completes).
  • Retention is announced — never a false clean tombstone — when the backend cannot retract, layout tree mode is set or merely possible (auto-upgrade is item-content-driven and unobservable at delete time; silence it with explicit spec.layout.mode: document), the sink pathTemplate contains {generation}, or GitLab runs merge_request mode (retraction lands only at MR merge).
  • K-29: apierrors.IsNotFound on sink resolution during finalization → CleanupSinkGone event, finalizer removed, no requeue (namespaced + cluster). Transient errors still retry; terminal errors still retain the finalizer.
  • K-30: kollect_cleanup_terminal_total{kind} (registered, catalogued, docs row, alert rule in troubleshooting) increments on terminal cleanup retention; new kollect.dev/force-cleanup: "true" annotation drops the finalizer only while deleting, without contacting backends, and records CleanupForced.
  • GitLab branchMR: the merge request is opened only when the deletion changed the branch or a probe (git ls-remote) finds a feature branch already pushed (recovery of a commit stranded by a crashed attempt); no-op deletes skip the API call entirely, and the CLI engine no longer pushes pointer-only feature branches.

Things to look at first

  1. internal/sink/cleanup.go — the outcome contract (Cleaned / Pruned / Retained) and the announce gates.
  2. internal/sink/git/delete.go — both engines reuse the export lock, force-fetch semantics, staged-deletion delivery, pathspec-scoped staging (foreign mirror dirt is never committed).
  3. internal/controller/sink_cleanup.go + both finalizers — announcement wiring, force-cleanup ordering.

Risk

  • Deletes real objects in user backends on inventory deletion. Blast radius bounded by the cleanup matchers (CleanupMatchers: exact stem + deterministic part suffix, hive partition confined to the name= segment directory); prefix-sharing siblings (app vs app-v2) are regex-rejected before deletion and test-locked across engines.
  • Known limits (documented in docs/operator-manual/troubleshooting.md): objects exported under a previous sink pathTemplate/format are unaddressable at deletion (no persisted export-path state); hive-sanitized name collisions (app-v2/app_v2) share a partition that export already co-mingles; a cascade-deleted credentials Secret still wedges as terminal (now alertable + escapable via force-cleanup); after deleting an inventory, do not merge stale unmerged export MRs on GitLab feature branches.
  • kollect_export_duration_seconds deliberately does not observe cleanup latency.

Test evidence

  • Test lock: NotFound-sink cleanup completes (both inventory kinds, event asserted); tombstone/retention assertion (s3 part-siblings + hive sweep, local, git both engines incl. no-op rev-count check, controller-level announce per retention cause).
  • Full task test green (envtest included); make lint + go-arch-lint + markdownlint clean.
  • Diff went through four independent hostile review rounds; each raised defect is fixed and regression-tested (deleted-paths contract, MR wedge, generation/tree retention, stranded-commit recovery).

Coordination notes

  • Metrics catalog test updated for the new counter — any concurrent lane touching internal/metrics will see a trivial conflict here.
  • New annotation added in api/v1alpha1/constants.go only (no CRD schema change).

…e finalization

K-28/C-2a: inventory deletion now deletes its exported snapshot objects
(git both engines, gitlab, s3/gcs, local) including deterministic .part
siblings and the parquet hive partition; backends that cannot retract,
git layout trees (explicit or auto-upgraded), {generation} templates and
merge-request mode announce CleanupRetained instead of a false clean
tombstone.

K-29: a sink CR deleted before its inventory no longer wedges deletion:
cleanup completes with a CleanupSinkGone event and the finalizer is
removed.

K-30: terminal cleanup wedges increment kollect_cleanup_terminal_total
and the kollect.dev/force-cleanup annotation (deletion-time only) drops
the finalizer without backend contact, announcing CleanupForced.

Known limits (documented): catch-up pathTemplate/format drift orphans
old-path objects; hive-sanitized name collisions share a partition; a
cascade-deleted credentials Secret still wedges as terminal.

Signed-off-by: Konrad Heimel <[email protected]>
@konih

konih commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #383, which contains this commit's change (retract-on-deletion), now opt-in via deletionPolicy: Delete on the sink, plus the git cleanup hardening.

@konih konih closed this Oct 1, 2026
@konih
konih deleted the fm/kollect-b6-deletion branch October 1, 2026 20:49
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.

1 participant