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

Support SQL Server Switchover (after resolving conflicts) #11850

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Philip-Jonany
Copy link

Support SQL Server Switchover through terraform
The full design doc can be found in go/sqlserver-switchover-terraform-proposal (Googler-only)

*This CL will NOT be submitted until the API changes are rolled out, and that my manual testing passes without causing a permadiff.

Copy link

google-cla bot commented Sep 27, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@modular-magician modular-magician added the awaiting-approval Pull requests that needs reviewer's approval to run presubmit tests label Sep 27, 2024
Copy link
Contributor

@slevenick slevenick left a comment

Choose a reason for hiding this comment

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

Overall no major concerns as long as the tests pass and the functionality works correctly

oldReplicaNames, newReplicaNames := d.GetChange("replica_names")
_, newMasterInstanceName := d.GetChange("master_instance_name")
_, newReplicaConfiguration := d.GetChange("replica_configuration")
if len(newReplicaConfiguration.([]interface{})) != 1 || newReplicaConfiguration.([]interface{})[0] == nil{
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there docs on how this should work from an outside of Terraform perspective?

I'm having trouble figuring out why we expect switchover to only work if the new replica configuration is empty

Copy link
Author

Choose a reason for hiding this comment

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

In his function, we check that the old replica has a replica configuration. If it's not set or empty, we return false === invalid, don't do switchover. This is a check for isEmpty before I access cascadable_replica, which is under replica_configuration.

go/sqlserver-switchover-terraform-proposal contains the user journey through terraform switchover.

replicaConfiguration := newReplicaConfiguration.([]interface{})[0].(map[string]interface{})
cascadableReplica, cascadableReplicaFieldExists := replicaConfiguration["cascadable_replica"]

return newMasterInstanceName != nil &&
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a very confusing return statement to parse. Can you split this out somehow? I'd even prefer nested if statements

Copy link
Author

Choose a reason for hiding this comment

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

I split the related booleans into variables such as instanceTypeChangedFromPrimaryToReplica and newMasterNotInNewReplicaNames, hopefully this makes it cleaner. Open to suggestions to renaming/rearranging the boolean!

Copy link
Author

@Philip-Jonany Philip-Jonany left a comment

Choose a reason for hiding this comment

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

Two main changes:
File got refactored from .go.erb to .go.tmpl
Added customdiff for cascadable_replica: force replacement unless it's switchover.

oldReplicaNames, newReplicaNames := d.GetChange("replica_names")
_, newMasterInstanceName := d.GetChange("master_instance_name")
_, newReplicaConfiguration := d.GetChange("replica_configuration")
if len(newReplicaConfiguration.([]interface{})) != 1 || newReplicaConfiguration.([]interface{})[0] == nil{
Copy link
Author

Choose a reason for hiding this comment

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

In his function, we check that the old replica has a replica configuration. If it's not set or empty, we return false === invalid, don't do switchover. This is a check for isEmpty before I access cascadable_replica, which is under replica_configuration.

go/sqlserver-switchover-terraform-proposal contains the user journey through terraform switchover.

replicaConfiguration := newReplicaConfiguration.([]interface{})[0].(map[string]interface{})
cascadableReplica, cascadableReplicaFieldExists := replicaConfiguration["cascadable_replica"]

return newMasterInstanceName != nil &&
Copy link
Author

Choose a reason for hiding this comment

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

I split the related booleans into variables such as instanceTypeChangedFromPrimaryToReplica and newMasterNotInNewReplicaNames, hopefully this makes it cleaner. Open to suggestions to renaming/rearranging the boolean!

in tests. API is rolled out.
@modular-magician modular-magician added service/sqladmin-cp and removed awaiting-approval Pull requests that needs reviewer's approval to run presubmit tests labels Oct 11, 2024
@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 4 files changed, 493 insertions(+), 17 deletions(-))
google-beta provider: Diff ( 4 files changed, 493 insertions(+), 17 deletions(-))

Missing test report

Your PR includes resource fields which are not covered by any test.

Resource: google_sql_database_instance (140 total tests)
Please add an acceptance test which includes these fields. The test should include the following:

resource "google_sql_database_instance" "primary" {
  replica_configuration {
    ca_certificate     = # value needed
    client_certificate = # value needed
    client_key         = # value needed
    dump_file_path     = # value needed
  }
}

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 99
Passed tests: 84
Skipped tests: 14
Affected tests: 1

Click here to see the affected service packages
  • sql

Action taken

Found 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
  • TestAccSqlDatabaseInstance_SwitchoverSuccess

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

🔴 Tests failed during RECORDING mode:
TestAccSqlDatabaseInstance_SwitchoverSuccess[Error message] [Debug log]

🔴 Errors occurred during RECORDING mode. Please fix them to complete your PR.

View the build log or the debug log for each test

@Philip-Jonany Philip-Jonany marked this pull request as ready for review October 15, 2024 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants