provider-sql
provider-sql copied to clipboard
Autoselect DB Name for me
What problem are you facing?
I have a single application that I've deployed multiple times (multiple testing environments). In the application's manifests it requests a MySQL db (sort of like shared hosting of old). They all unfortunately request the same DB name. Now I have collisions!
Context
When I ask for a Pod on Kubernetes, I'm not expecting the underlying container name to match my pod name. The underlying container name is an implementation detail. If it did do that, then pod A in namespace A would collide with pod A in namespace B.
How could Crossplane help solve your problem?
When I ask crossplane for a SQL database, it can create one with my request name plus a random prefix (to ease debugging), ensuring it doesn't collide with an existing db. Then it would load the DB name into a config map for me to use with my application deployment.
Are you setting the metadata.name field in the Database resource? You can try using the kubernetes-native generateName field instead which will create a unique name and put it in the metadata.name field when the resource is created: https://kubernetes.io/docs/reference/using-api/api-concepts/#generated-values
If you then need to reference that value in another resource on the same Composite you can use a ToCompositeFieldPath patch (Crossplane 1.1).
Interesting, that seems to at least provide a workaround to the issue. My experience with generated values however has been with helm where Helm would lose track of them causing it to create a new resource each deployment.
I don't understanding the Composites enough yet to understand the ToCompositeFieldPath comment, so I'll have to experiment with that.
Closing as stale.