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

refactor: Removes unused RootDiskSize field and simplify ExtraAPIInfo construction #2974

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const (
type ExtraAPIInfo struct {
ZoneNameNumShards map[string]int64
ZoneNameReplicationSpecIDs map[string]string
RootDiskSize *float64
ContainerIDs map[string]string
UsingLegacySchema bool
ForceLegacySchemaFailed bool
Expand Down
17 changes: 3 additions & 14 deletions internal/service/advancedclustertpf/resource_compatiblity.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func findNumShardsUpdates(ctx context.Context, state, plan *TFModel, diags *diag
func resolveAPIInfo(ctx context.Context, diags *diag.Diagnostics, client *config.MongoDBClient, plan *TFModel, clusterLatest *admin.ClusterDescription20240805, forceLegacySchema bool) *ExtraAPIInfo {
var (
api20240530 = client.AtlasV220240530.ClustersApi
rootDiskSize = conversion.NilForUnknown(plan.DiskSizeGB, plan.DiskSizeGB.ValueFloat64Pointer())
projectID = plan.ProjectID.ValueString()
clusterName = plan.Name.ValueString()
forceLegacySchemaFailed = false
Expand All @@ -56,28 +55,18 @@ func resolveAPIInfo(ctx context.Context, diags *diag.Diagnostics, client *config
return nil
}
}
if rootDiskSize == nil {
rootDiskSize = findRegionRootDiskSize(clusterLatest.ReplicationSpecs)
}
containerIDs, err := resolveContainerIDs(ctx, projectID, clusterLatest, client.AtlasV2.NetworkPeeringApi)
if err != nil {
diags.AddError(errorResolveContainerIDs, fmt.Sprintf("cluster name = %s, error details: %s", clusterName, err.Error()))
return nil
}
info := &ExtraAPIInfo{
return &ExtraAPIInfo{
ContainerIDs: containerIDs,
RootDiskSize: rootDiskSize,
ZoneNameReplicationSpecIDs: replicationSpecIDsFromOldAPI(clusterRespOld),
ForceLegacySchemaFailed: forceLegacySchemaFailed,
ZoneNameNumShards: numShardsMapFromOldAPI(clusterRespOld),
marcosuma marked this conversation as resolved.
Show resolved Hide resolved
UsingLegacySchema: forceLegacySchema || usingLegacySchema(ctx, plan.ReplicationSpecs, diags),
}
if forceLegacySchema {
Copy link
Member

Choose a reason for hiding this comment

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

nice refactor

info.UsingLegacySchema = true
info.ZoneNameNumShards = numShardsMapFromOldAPI(clusterRespOld) // plan is empty in data source Read when forcing legacy, so we get num_shards from the old API
} else {
info.UsingLegacySchema = usingLegacySchema(ctx, plan.ReplicationSpecs, diags)
info.ZoneNameNumShards = numShardsMap(ctx, plan.ReplicationSpecs, diags)
}
return info
}

// instead of using `num_shards` explode the replication specs, and set disk_size_gb
Expand Down
Loading