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

chore: Enable migration tests for clusters in legacy schema #2975

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

lantoli
Copy link
Member

@lantoli lantoli commented Jan 16, 2025

Description

Enable migration tests for clusters in legacy schema. With this PR, all mig tests for TPF are passing.

Link to any related issue(s): CLOUDP-295165

Type of change:

  • Bug fix (non-breaking change which fixes an issue). Please, add the "bug" label to the PR.
  • New feature (non-breaking change which adds functionality). Please, add the "enhancement" label to the PR. A migration guide must be created or updated if the new feature will go in a major version.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected). Please, add the "breaking change" label to the PR. A migration guide must be created or updated.
  • This change requires a documentation update
  • Documentation fix/enhancement

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the contributing guides
  • I have checked that this change does not generate any credentials and that they are NOT accidentally logged anywhere.
  • I have added tests that prove my fix is effective or that my feature works per HashiCorp requirements
  • I have added any necessary documentation (if appropriate)
  • I have run make fmt and formatted my code
  • If changes include deprecations or removals I have added appropriate changelog entries.
  • If changes include removal or addition of 3rd party GitHub actions, I updated our internal document. Reach out to the APIx Integration slack channel to get access to the internal document.

Further comments

@@ -29,7 +29,6 @@ func TestMigAdvancedCluster_singleShardedMultiCloud(t *testing.T) {
}

func TestMigAdvancedCluster_symmetricGeoShardedOldSchema(t *testing.T) {
acc.SkipIfAdvancedClusterV2Schema(t) // unexpected update and then: error operation not permitted, nums_shards from 1 -> > 1
Copy link
Member Author

Choose a reason for hiding this comment

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

the last mig test to enable for TPF


// sendLegacySchemaRequestToRead sets ClusterID to a special value so Read can know whether it must use legacy schema.
// private state can't be used here because it's not available in Move Upgrader.
// ClusterID is computed (not optional) so the value will be overridden in Read and the special value won't ever appear in the state file.
Copy link
Member Author

Choose a reason for hiding this comment

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

let me know if there is any question about why we use ClusterID as a side channel to communicate between State Move / Upgrader and Read. Also if you have a better idea, please let me know

Copy link
Collaborator

Choose a reason for hiding this comment

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

if we go with this option, do you think we can add a check of ClusterID != forceLegacySchema in one of the tests that are testing the upgrade?

@lantoli lantoli marked this pull request as ready for review January 17, 2025 11:23
@lantoli lantoli requested a review from a team as a code owner January 17, 2025 11:23
Comment on lines +190 to +192
func sendLegacySchemaRequestToRead(model *TFModel) {
model.ClusterID = types.StringValue("forceLegacySchema")
}
Copy link
Member

Choose a reason for hiding this comment

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

As an alternative, is it too complex to populate the replication spec list only with the bare minimum so our existing logic detects the legacy sharding config (objects with num_shards)? With this approach we would avoid receivedLegacySchemaRequestInRead using cluster_id which looks more hacky

@@ -39,101 +41,149 @@ func stateUpgraderFromV1(ctx context.Context, req resource.UpgradeStateRequest,
setStateResponse(ctx, &resp.Diagnostics, req.RawState, &resp.State)
}

func setStateResponse(ctx context.Context, diags *diag.Diagnostics, stateIn *tfprotov6.RawState, stateOut *tfsdk.State) {
rawStateValue, err := stateIn.UnmarshalWithOpts(tftypes.Object{
// Minimum attributes needed from source schema. Read will fill in the rest
Copy link
Collaborator

Choose a reason for hiding this comment

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

non-blocking comment: in the future where new attributes will be added, will there be some compile-time or test failure if that field needs to be specified here?

Copy link
Member Author

Choose a reason for hiding this comment

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

in line 69 , we're using: IgnoreUndefinedAttributes: true}
that means that we're flexible in the schema, if you see the code below the real mandatory ones are project_id and cluster, the ones we try to used them in a best-effort basis, it's ok if they don't come (e.g. later when moving from flex cluster)

so the schema doesn't make it fail if they some attribute doesn't exist, later when the value is tried to be read it will be null

Copy link
Collaborator

Choose a reason for hiding this comment

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

it's ok if they don't come
ok then why are we even populating them? What is the advantage of populating? Answering this question should also help me with understanding the consequence of:
later when the value is tried to be read it will be null

Copy link
Member Author

@lantoli lantoli Jan 17, 2025

Choose a reason for hiding this comment

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

if the previous version/resource have them and we don't set them, then there will a plan change, e.g. if timeouts or retain_backups_enabled is defined in SDKv2 and want to migrate to TPF, users will get a plan change saying that timeouts/retain_backups_enabled will be deleted.
(we don't want plan changes when upgrading from sdkv2 to tpf or moved block from cluster to tpf adv_cluster)

in the case that will come with moving from flex cluster to adv_cluster for example, they don't exist so it's ok not to send them.

Copy link
Member Author

Choose a reason for hiding this comment

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

it's to avoid plan changes by filling attributes that Read can't do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants