Skip to content

Add opt-in cleanup policy for related-resource copies#181

Open
wojciech12 wants to merge 1 commit into
kcp-dev:mainfrom
wojciech12:feature/support-deletion-of-releated-resource
Open

Add opt-in cleanup policy for related-resource copies#181
wojciech12 wants to merge 1 commit into
kcp-dev:mainfrom
wojciech12:feature/support-deletion-of-releated-resource

Conversation

@wojciech12

Copy link
Copy Markdown

For origin: service related resources the agent never prunes a copy when its origin object is deleted mid-life; the copy is orphaned permanently (no per-object finalizer, no set-diff). Even on primary teardown, copies whose origin already vanished are not reclaimed.

Add a cleanupPolicy field to RelatedResourceSpec with three values:

  • Orphan (default): copies are never deleted (== legacy cleanup:false).
  • OnPrimaryDeletion: copies deleted only on primary deletion (== legacy cleanup:true).
  • MatchOrigin: a copy is pruned as soon as its origin object is gone, and all copies are deleted on primary teardown (also reclaiming mid-life orphans).

The prune is List-and-diff driven by the primary reconcile, never a finalizer on related objects (issues #172/#116). Copies are labelled with owning-primary and identifier provenance so only agent-created copies are ever deleted, scoped to the destination client so the origin object is never touched. The List is cluster-wide (scoped by the provenance label selector) so copies mapped into a different namespace via spec.object.namespace rewrites are pruned too. The deprecated cleanup bool is still honoured via EffectiveCleanupPolicy(). CEL rules require watch for MatchOrigin+origin:service and reject cleanup:true+Orphan.

Extends the opt-in cleanup work from #114 (PR #164).

Summary

What Type of PR Is This?

/kind feature

Related Issue(s)

Fixes #

Release Notes

Add a cleanupPolicy field to RelatedResourceSpec with three values:

  • Orphan (default): copies are never deleted (== legacy cleanup:false).
  • OnPrimaryDeletion: copies deleted only on primary deletion (== legacy cleanup:true).
  • MatchOrigin: a copy is pruned as soon as its origin object is gone, and all copies are deleted on primary teardown (also reclaiming mid-life orphans).

@kcp-ci-bot

Copy link
Copy Markdown
Contributor

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@kcp-ci-bot kcp-ci-bot added kind/feature Categorizes issue or PR as related to a new feature. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jul 18, 2026
@kcp-ci-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign xrstf for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kcp-ci-bot kcp-ci-bot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. dco-signoff: no Indicates the PR's author has not signed the DCO. labels Jul 18, 2026
@kcp-ci-bot

Copy link
Copy Markdown
Contributor

Hi @wojciech12. Thanks for your PR.

I'm waiting for a kcp-dev member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@kcp-ci-bot kcp-ci-bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jul 18, 2026
For `origin: service` related resources the agent never prunes a copy when its
origin object is deleted mid-life; the copy is orphaned permanently (no
per-object finalizer, no set-diff). Even on primary teardown, copies whose
origin already vanished are not reclaimed.

Add a `cleanupPolicy` field to RelatedResourceSpec with three values:

  - Orphan (default): copies are never deleted (== legacy cleanup:false).
  - OnPrimaryDeletion: copies deleted only on primary deletion (== legacy cleanup:true).
  - MatchOrigin: a copy is pruned as soon as its origin object is gone, and all
    copies are deleted on primary teardown (also reclaiming mid-life orphans).

The prune is List-and-diff driven by the primary reconcile, never a finalizer on
related objects (issues kcp-dev#172/kcp-dev#116). Copies are labelled with owning-primary and
identifier provenance so only agent-created copies are ever deleted, scoped to
the destination client so the origin object is never touched. The List is
cluster-wide (scoped by the provenance label selector) so copies mapped into a
different namespace via spec.object.namespace rewrites are pruned too. The
deprecated `cleanup` bool is still honoured via EffectiveCleanupPolicy(). CEL
rules require `watch` for MatchOrigin+origin:service and reject cleanup:true+Orphan.

Extends the opt-in cleanup work from kcp-dev#114 (PR kcp-dev#164).

Signed-off-by: wojciech12 <wojciech.barczynski@kubermatic.com>
@wojciech12
wojciech12 force-pushed the feature/support-deletion-of-releated-resource branch from bb0462a to 62c8745 Compare July 18, 2026 19:12
@kcp-ci-bot kcp-ci-bot added dco-signoff: yes Indicates the PR's author has signed the DCO. and removed dco-signoff: no Indicates the PR's author has not signed the DCO. labels Jul 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the DCO. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. kind/feature Categorizes issue or PR as related to a new feature. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants