provider-sql icon indicating copy to clipboard operation
provider-sql copied to clipboard

Use default Mysql port if not specified in the connection secret

Open sendmars opened this issue 2 years ago • 0 comments

What problem are you facing?

If a secret containing connection parameters for Mysql server doesn't contain port, the connection will timeout when attempting to use the provider, e.g. when creating a user:

CannotObserveExternalResource  user/test-user  cannot select user: dial tcp 10.x.x.x:0: i/o timeout

The problem is that provider-aws doesn't write port data for DB cluster (maybe for others as well). While it makes sense to address this in provider-aws, I also believe it makes sense to set a default port in provider-sql, as user's intention would likely be to connect over 3306 (instead of 0).

Example secret created by provider-aws:

apiVersion: v1
data:
  endpoint: [...]
  password: [...]
  username: [...]
kind: Secret
metadata:
  creationTimestamp: "2022-03-22T11:28:56Z"
  name: test-db-connection
  namespace: default
  ownerReferences:
  - apiVersion: rds.aws.crossplane.io/v1alpha1
    controller: true
    kind: DBCluster
    name: cluster-kw87c
    uid: [...]
  resourceVersion: [...]
  uid: [...]
type: connection.crossplane.io/v1alpha1

How could Crossplane help solve your problem?

Assume that the absence of port in the connection secret means that the connection attempt should happen over the default port.

I'd be happy to submit a PR if this proposal makes sense. As far as I can tell the required change is in pkg/clients/mysql/mysql.go, where we could put a default port constant, and use it if the port is an empty string.

sendmars avatar Mar 22 '22 17:03 sendmars