crossplane-runtime icon indicating copy to clipboard operation
crossplane-runtime copied to clipboard

Add MustCreate management policy

Open bobh66 opened this issue 3 months ago • 2 comments

Description of your changes

Added a MustCreate management policy that requires the external resource to NOT exist before the MR can create it.

Fixes #872

Tested using provider-kubernetes running a private branch of crossplane-runtime. Created a Secret and also an Object containing a Secret with the same name but different data, and managementPolicies: ['MustCreate', 'Observe', 'Update', 'LateInitialize', 'Delete'] and verified that when the Object was created the Secret remained unchanged and the Object reported an error that the Secret it was trying to create was already in existence.

Docs PR is https://github.com/crossplane/docs/pull/993

I have:

Need help with this checklist? See the cheat sheet.

bobh66 avatar Sep 12 '25 19:09 bobh66

Similarly to the comment on adding the Orphan management policy, I am vary of adding new policies to the management policies except for the primitives we have.

Adding MustCreate would be adding a flavour of Create, so I worry that if we go in this direction we would add more such flavours in the future and it could become unmanagable. Or imagine if we would later want to combine the Orphan policy ["Observe", "Create", "Update", "LateInitialize"] from the other PR, with MustCreate. Would we need to add OrphanMustCreate that translates to ["Observe", "MustCreate", "Update", "LateInitialize"]. Furthermore * would lose its meaning as it would not anymore map to ALL.

In general I think the basic policies should follow the methods of the external managed client.

However, I do understand where the issue is coming from and what we are trying to achive here, I just don't think adding a new management policy is the right way. I wonder should we introduce some management options field? We could add mustCreate there, and maybe move lateInitialize there at one point, or anything else that pops out?

lsviben avatar Oct 28 '25 10:10 lsviben

@lsviben I don't disagree that managementPolicies is already too complicated - related comment here

bobh66 avatar Nov 04 '25 16:11 bobh66