Best-practices for deterministic composed resource names
What's Missing?
I believe one of the problems https://github.com/crossplane/crossplane/pull/3287 intends to fix is ensuring the external names of composed resources are deterministic. The idea being that if a claim was deleted and then recreated, it would result in the same set of external resources (with the same names, in the external system) being recreated.
This is useful for migrating a claim from one control plane to another. It should be possible to:
- Ensure all composed MRs have
deletionPolicy: Orphanso that deleting the MR does not delete the external resource. - Delete the claim from the 'old' control plane.
- Create an identical claim in the 'new' control plane.
- Have Crossplane find and adopt all of the external resources that were orphaned in step 1, as composed resources of the new claim and XR.
In theory this should be possible today, but it requires some forethought to make it work. Specifically you must ensure all composed resources have a crossplane.io/external-name annotation that is deterministically derived from the claim. One way to do this is by patching from the XR's crossplane.io/claim-name annotation as suggested in https://github.com/crossplane/crossplane/issues/3120#issuecomment-1178377398.
I believe we should document this pattern as a Composition best-practice. It doesn't have to specifically be patching from claim-name, but rather being thoughtful and explicit about how your external-name annotations are specified. If you leave this up to Crossplane it will just copy the metadata.name of your composed resources, which will have a random suffix and thus be non-deterministic.