crossplane-runtime
crossplane-runtime copied to clipboard
Allow managed resources to support an 'external metadata' interface
What problem are you facing?
Many (but far from all) external resources support some kind of generic 'metadata', such as tags or labels. We've identified at least a small handful of ways Crossplane could use this metadata, including:
- Indicating which Crossplane cluster is authoritative for a particular external resource (https://github.com/crossplane/crossplane/issues/2193)
- Indicating which Crossplane managed resource an external resource is associated with (https://github.com/crossplane/crossplane-runtime/pull/123)
- Persisting a deterministic 'external name' for external resources whose actual external name is non-deterministic (i.e. randomly generated by the external API).
Building this kind of functionality is difficult because there is very little consistency in how metadata is supported across external resources; each needs bespoke logic to get and set metadata.
How could Crossplane help solve your problem?
Managed resources could optionally satisfy an interface for getting and setting external metadata. Metadata would still be represented as high-fidelity fields on the managed resource (e.g. a spec.forProvider.tags array), and each ExternalClient would still be responsible for reading and writing those fields from and to the external API. The interface would simply:
- Indicate that the managed resource supported external metadata.
- Provide a standard way to read and modify external metadata.
For example:
type ExternalMetaGetterSetter interface {
Get(key string) string
Set(key, value string)
}
// ExternalTagger is a generic managed.Initializer that works with any
// managed.ExternalMetaGetterSetter.
type ExternalTagger struct {
client client.Client
}
func (e ExternalTagger) Initialize(ctx context.Context, mg resource.Managed) error {
et, ok := mg.(resource.ExternalMetaGetterSetter)
if !ok {
// This kind of resource doesn't support metadata. Nothing to do.
return nil
}
for k, v := resource.GetExternalTags(mg) {
et.Set(k, v)
}
return e.client.Update(ctx, mg)
}
This approach wouldn't really open up any functionality we couldn't build without it, but I suspect it would allow us to avoid repeating our external metadata read/write logic as we use it to power more use cases.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Crossplane does not currently have enough maintainers to address every issue and pull request. This issue has been automatically marked as stale because it has had no activity in the last 90 days. It will be closed in 14 days if no further activity occurs. Leaving a comment starting with /fresh will mark this issue as not stale.