Skip to content

Add support for Orphan management policy#864

Merged
bobh66 merged 2 commits intocrossplane:mainfrom
nokia:add_orphan_policy
Feb 3, 2026
Merged

Add support for Orphan management policy#864
bobh66 merged 2 commits intocrossplane:mainfrom
nokia:add_orphan_policy

Conversation

@bobh66
Copy link
Contributor

@bobh66 bobh66 commented Aug 6, 2025

Description of your changes

Added an Orphan management policy value which maps to ['Observe', 'Create', 'Update', 'LateInitialize'] in order to simplify the migration from deletionPolicy to managementPolicies and facilitate controlled orphaning of resources.

Fixes #6694 (Crossplane)

Tested using provider-kubernetes running a private branch of crossplane-runtime. Created an Object containing a Secret with the managementPolicies: ['Orphan'] and verified that when the Object was deleted the Secret remained.

Docs PR is crossplane/docs#993

Fixes crossplane/crossplane#6694

I have:

Need help with this checklist? See the cheat sheet.

@bobh66 bobh66 requested a review from a team as a code owner August 6, 2025 21:08
@bobh66 bobh66 requested a review from jbw976 August 6, 2025 21:08
@bobh66 bobh66 marked this pull request as draft August 6, 2025 21:08
@bobh66 bobh66 marked this pull request as ready for review September 12, 2025 22:22
@bobh66 bobh66 moved this to In Review in Crossplane Roadmap Oct 24, 2025
@bobh66 bobh66 added this to the v2.1 milestone Oct 24, 2025
Copy link
Member

@jbw976 jbw976 left a comment

Choose a reason for hiding this comment

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

This looks like a nice convenience policy that streamlines the experience for enabling the orphaning of resources. Thanks @bobh66! just a couple questions

// PLEASE UPDATE THIS WHEN RELEASING.
"baseBranches": [
'main',
'release-1.18',
Copy link
Member

Choose a reason for hiding this comment

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

this was already done in #865, so it's odd to see here again 🤔

@lsviben
Copy link
Contributor

lsviben commented Oct 28, 2025

IMO the idea of management policies is that we define primitives like Observe, Create, Update, Delete that clearly state what will be done with the resources. I intentionally didnt put LateInitialize here as its a bit of an outlier and in hindsight should have been a separate feature outside of management policies.

Adding more policies when we can do the same with the existing ones seems the move in the wrong direction. IMO it would just complicate things more. As its not a primitive, but a policy like * which contains more policies it would be another special case that cannot be combined with other policies.

If we really need a simplifier for management policies, maybe we should introduce a separate field:
managementPolicyAlias which would be translated into managementPolicies.

So you could just set managementPolicyAlias: Orphan which would fill in managementPolicies: ['Observe', 'Create', 'Update', 'LateInitialize'].

@lsviben lsviben mentioned this pull request Oct 28, 2025
4 tasks
@bobh66
Copy link
Contributor Author

bobh66 commented Nov 4, 2025

@lsviben I don't disagree that adding Orphan is a workaround, but I'm not sure that adding another field is a better solution. deletionPolicy was a simple and clean interface - maybe managementPolicies should have been a map instead of a list, which would have made it easier to convert from deletionPolicy, and would also make it easier to do things like mustCreate:

   managementPolicies:
    observe: true   # true/false
    create: required  # true/false/requried
    update: false  # true/false
    delete: false  # true/false

@lsviben
Copy link
Contributor

lsviben commented Dec 2, 2025

@lsviben I don't disagree that adding Orphan is a workaround, but I'm not sure that adding another field is a better solution. deletionPolicy was a simple and clean interface - maybe managementPolicies should have been a map instead of a list, which would have made it easier to convert from deletionPolicy, and would also make it easier to do things like mustCreate:

   managementPolicies:
    observe: true   # true/false
    create: required  # true/false/requried
    update: false  # true/false
    delete: false  # true/false

In hindsight and with the context we have today, maybe it would be easier. Although I am wondering if there would be even more things popipng up along with required.

But we should work with what we have today unless we want to make breaking changes. I just added some propositions that came to my mind how to overcome these issues without making changes to the managementpolicies API itself.

Fixes #6694

Signed-off-by: Bob Haddleton <bob.haddleton@nokia.com>
@bobh66 bobh66 force-pushed the add_orphan_policy branch from 2caf1b9 to 4285eb2 Compare February 3, 2026 16:59
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 3, 2026

📝 Walkthrough

Walkthrough

Adds a new ManagementAction value "Orphan", exposes it in v1, and updates policy resolution and reconciler checks to treat Orphan as a valid action for create/update/late-initialize flows; tests expanded to cover Orphan behavior and a test name typo was fixed.

Changes

Cohort / File(s) Summary
API Constants
apis/common/policies.go, apis/common/v1/policies.go
Adds ManagementActionOrphan constant and updates the kubebuilder enum validation to include "Orphan"; exposes the constant in the v1 API.
Policy Evaluation Logic
pkg/reconciler/managed/policies.go
Extends default supported policies to include Orphan and updates ShouldCreate, ShouldUpdate, and ShouldLateInitialize checks to accept Orphan alongside Create/Update/LateInitialize/All policies.
Test Coverage
pkg/reconciler/managed/reconciler_legacy_test.go, pkg/reconciler/managed/reconciler_modern_test.go
Adds multiple test cases validating reconciliation behavior under the Orphan management action (create/update/late-init paths) and fixes a typo in a test name.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Controller as Controller\n(runner)
participant Resolver as ManagementPoliciesResolver
participant Reconciler as ManagedReconciler
participant External as ExternalSystem
Controller->>Resolver: Query allowed actions (includes "Orphan")
Resolver-->>Controller: Allowed actions (Create, Update, LateInitialize, Orphan, ...)
Controller->>Reconciler: Reconcile request (policy = Orphan)
Reconciler->>External: Perform non-Delete operations (create/update/late-init)
External-->>Reconciler: Success / Status
Reconciler-->>Controller: Conditioned status + requeue decision

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • negz
  • jbw976

Thanks — would you like a short changelog entry or a migration note for CRD consumers?

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding support for a new Orphan management policy, and meets the 72-character requirement.
Description check ✅ Passed The description clearly relates to the changeset, providing context about the Orphan policy value, its purpose, testing approach, and references to related issues and documentation.
Breaking Changes ✅ Passed This pull request introduces only additive changes to the public Go API without any breaking modifications. Two new exported constants (ManagementActionOrphan) are added to the API enum in apis/common/policies.go and apis/common/v1/policies.go, and the kubebuilder validation tag is extended to include "Orphan" as a valid value. In pkg/reconciler/managed/policies.go, the functions ShouldCreate(), ShouldUpdate(), and ShouldLateInitialize() are extended to recognize the new ManagementActionOrphan value, but their signatures remain unchanged and the behavior changes are backward-compatible. Existing code that doesn't use the new Orphan action will continue to work exactly as before. No exported functions, types, or methods are removed, renamed, or have breaking signature changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@apis/common/policies.go`:
- Line 25: The kubebuilder validation tag on the Policy enum uses a comma
between MustCreate and Orphan which prevents Orphan from being recognized; edit
the kubebuilder tag string (the line containing
"+kubebuilder:validation:Enum=Observe;Create;Update;Delete;LateInitialize;*;MustCreate,Orphan")
and replace the comma with a semicolon so it reads "...;MustCreate;Orphan" to
match the semicolon separators used elsewhere and ensure correct CRD validation.

@bobh66 bobh66 force-pushed the add_orphan_policy branch from 4285eb2 to 51deaf0 Compare February 3, 2026 17:30
Signed-off-by: Bob Haddleton <bob.haddleton@nokia.com>
@bobh66 bobh66 force-pushed the add_orphan_policy branch from 51deaf0 to 7857ee9 Compare February 3, 2026 17:42
@bobh66 bobh66 merged commit 26bc05a into crossplane:main Feb 3, 2026
11 checks passed
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.

Add support for an Orphan managementPolicy

3 participants