Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add referencer and selector option for masterInstanceName in Cloud SQL #389

Open
Feggah opened this issue Oct 6, 2021 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@Feggah
Copy link
Collaborator

Feggah commented Oct 6, 2021

What problem are you facing?

Building compositions which creates master and replica databases instances can be challenging because masterInstanceName is only supported by passing the master name directly.

This could be solved by just patching the name to the field. But we have 2 problems with this approach:

  • masterInstanceName needs to be in the format <project-id>:<instance-name>. For example: mycoolproject123:example-db
  • Without the reference, there isn't a depends_on that will wait the master creation then create the replica, it will try to create both at the same time, which will lead to errors.

How could Crossplane help solve your problem?

Adding reference to other CloudSQLInstance in the field masterInstanceName

Workaround for this problem

I defined a field in XR status named masterName, and this field is populated by CombineToComposite in the master database patches. You can see this example below:

- type: CombineToComposite
  combine:
    variables:
      - fromFieldPath: "status.atProvider.project"
      - fromFieldPath: "metadata.labels[crossplane.io/claim-name]"
    strategy: string
    string:
      fmt: "%s:%s"
  toFieldPath: status.masterName

And then you can use FromCompositeFieldPath to populate the masterInstanceName field:

- type: FromCompositeFieldPath
  fromFieldPath: "status.masterName"
  toFieldPath: "spec.forProvider.masterInstanceName"
  policy:
    fromFieldPath: Required

Note that you need to use policy: Required because if you don't, the replica instance will skip this patch while status.masterName isn't fullfilled, which will lead to two separate database instances (as if you've created two masters). By defining this policy, the replica creation will raise errors until the status.masterName is populated.

@Feggah Feggah added the enhancement New feature or request label Oct 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant