Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Update google_sql_database_instance config to output connection details #48

Merged
merged 3 commits into from
Mar 11, 2022

Conversation

tnthornton
Copy link
Contributor

Description of your changes

Prior to this change, the connection details secret from google_sql_database_instance included no exported attributes as seen in #47.

For this change the ResourceConfigurator for google_sql_database_instance was extended to include transferring details from the exported attributes to the connection details secret that is inline with behavior we see in provider-gcp.

Fixes #47

I have:

  • Read and followed Crossplane's [contribution process].
  • Run make reviewable test to ensure this PR is ready for review.

How has this code been tested

  1. kubectl apply -f examples/sql/instance.yaml
  2. Verified that the connection details secret included the updated information:
$ kubectl -n crossplane-system get secrets example-sql-db-instance-secret -o yaml
apiVersion: v1
data:
  cert: <REDACTED>
  commonName: <REDACTED>
  connectionName: <REDACTED>
  createTime: MjAyMi0wMy0wOVQwMjowOToyMi40Njla
  expirationTime: MjAzMi0wMy0wNlQwMjoxMDoyMi40Njla
  privateIpAddress: ""
  publicIpAddress: <REDACTED>
  sha1Fingerprint: <REDACTED>
kind: Secret
metadata:
  creationTimestamp: "2022-03-09T02:09:12Z"
  name: example-sql-db-instance-secret
  namespace: crossplane-system
  ownerReferences:
  - apiVersion: sql.gcp.jet.crossplane.io/v1alpha2
    controller: true
    kind: DatabaseInstance
    name: example-instance-002
    uid: 9a916bb7-68c9-41a9-9ac2-2fbb4063c104
  resourceVersion: "1744834"
  uid: 05ab12b7-0e3a-4956-8f1a-06b4b01a7182
type: connection.crossplane.io/v1alpha1

Signed-off-by: Taylor Thornton <thornton.tn@gmail.com>
config/sql/config.go Outdated Show resolved Hide resolved
Comment on lines 51 to 62
if a, ok := certattrs["common_name"].(string); ok {
conn["commonName"] = []byte(a)
}
if a, ok := certattrs["create_time"].(string); ok {
conn["createTime"] = []byte(a)
}
if a, ok := certattrs["expiration_time"].(string); ok {
conn["expirationTime"] = []byte(a)
}
if a, ok := certattrs["sha1_fingerprint"].(string); ok {
conn["sha1Fingerprint"] = []byte(a)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need these in connection details secret?

Copy link
Contributor Author

@tnthornton tnthornton Mar 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I don't need them for my current connection details. However, I did add these to keep them consistent with what exists today in provider-gcp https://github.com/crossplane/provider-gcp/blob/master/pkg/controller/database/cloudsql.go#L218-L221.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 I'll update them 👍.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up creating a new const block in config.go versus importing the package from provider-gcp just to get the static strings (that just seemed heavy).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right call 👍

config/sql/config.go Outdated Show resolved Hide resolved
@turkenh
Copy link
Collaborator

turkenh commented Mar 9, 2022

Thanks @tnthornton, looking good, just left couple of minor comments 👍

update cert key name to serverCaCert

Signed-off-by: Taylor Thornton <thornton.tn@gmail.com>
@tnthornton
Copy link
Contributor Author

Thanks for the review @turkenh !. I've made the requested adjustments and verified we get the expected details in the new secret:

data:
  commonName: <REDACTED>
  connectionName: <REDACTED>
  createTime: MjAyMi0wMy0wOVQxNjo1ODozNy4yNTha
  expirationTime: MjAzMi0wMy0wNlQxNjo1OTozNy4yNTha
  privateIpAddress: ""
  publicIpAddress: <REDACTED>
  serverCaCert: <REDACTED>
  sha1Fingerprint: <REDACTED>

Signed-off-by: Taylor Thornton <thornton.tn@gmail.com>
@tnthornton
Copy link
Contributor Author

Updated keys:

  connectionName: <REDACTED>
  privateIP: ""
  publicIP: <REDACTED>
  serverCACertificateCert: <REDACTED>
  serverCACertificateCommonName: <REDACTED>
  serverCACertificateCreateTime: MjAyMi0wMy0xMFQyMDo1OToyNS4yOTda
  serverCACertificateExpirationTime: MjAzMi0wMy0wN1QyMTowMDoyNS4yOTda
  serverCACertificateSha1Fingerprint: <REDACTED>

@turkenh
Copy link
Collaborator

turkenh commented Mar 11, 2022

Thanks @tnthornton 🙌

@turkenh turkenh merged commit 48f0deb into crossplane-contrib:main Mar 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants