crossplane-contrib / provider-sql

An SQL provider for @crossplane
https://crossplane.io
Apache License 2.0
100 stars 57 forks source link

Decouple Kubernetes Resource Name and RDBMS Resource Name #185

Open zhekazuev opened 2 weeks ago

zhekazuev commented 2 weeks ago

What problem are you facing?

Currently, the provider-sql uses the name of the Kubernetes manifest(resource) as the name of the database resource(Role, Database, etc.).

This approach introduces several limitations:

To resolve these issues, I propose introducing a separate field within the spec of the Provider Resources to explicitly define the database resource name, as it works in the next providers:

This will decouple the Kubernetes resource name from the database resource name, allowing greater flexibility and avoiding naming conflicts.

Example with PostgreSQL Role after that changes:

apiVersion: postgresql.sql.crossplane.io/v1alpha1
kind: Role
metadata:
  name: example-role-k8s  # Kubernetes resource name
spec:
  forProvider:
    name: "example_role_in_db"  # Database role name (optional, defaults to object name if not provided)
    # other variants of field name/paths
    # - roleName
    # - role.name: 
...

Benefits:

Implementing this change will enhance the usability and flexibility of the provider-sql for various RDBMS types within Crossplane, ensuring it meets user needs more effectively while maintaining compatibility with existing deployments.

How could Crossplane help solve your problem?

Modify the CRD (CustomResourceDefinition):

Update the Controller Logic:

Tests:

Ben10k commented 3 days ago

Hello @zhekazuev Crossplane already supports this functionality. A resources name can be set using the crossplane.io/external-name annotation. For example:

apiVersion: postgresql.sql.crossplane.io/v1alpha1
kind: Role
metadata:
  name: example-role-k8s  # Kubernetes resource name
  annotations: 
    crossplane.io/external-name: custom_name
spec:

More details here: https://docs.crossplane.io/latest/concepts/managed-resources/#naming-external-resources

zhekazuev commented 3 days ago

Hello @zhekazuev

Crossplane already supports this functionality. A resources name can be set using the crossplane.io/external-name annotation.

For example:


apiVersion: postgresql.sql.crossplane.io/v1alpha1

kind: Role

metadata:

  name: example-role-k8s  # Kubernetes resource name

  annotations: 

    crossplane.io/external-name: custom_name

spec:

More details here: https://docs.crossplane.io/latest/concepts/managed-resources/#naming-external-resources

Hello @Ben10k ,

Thanks for the reply, I thought this functionality needs for Claim/Composition resources naming. I will check and close issue on the next week.