Skip to content

CLOUDP-380507-cluster: update schema and handler implementation#1622

Draft
maastha wants to merge 1 commit intomasterfrom
CLOUDP-380507-cluster
Draft

CLOUDP-380507-cluster: update schema and handler implementation#1622
maastha wants to merge 1 commit intomasterfrom
CLOUDP-380507-cluster

Conversation

@maastha
Copy link
Collaborator

@maastha maastha commented Mar 9, 2026

Proposed changes

Jira ticket: CLOUDP-#

Please include a summary of the fix/feature/change, including any relevant motivation and context.

Link to any related issue(s):

Type of change:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as
    expected)
  • This change requires a documentation update
  • 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.

Manual QA performed:

  • cfn invoke for each of CRUDL/cfn test
  • Updated resource in example
  • Published to AWS private registry
  • Used the template in example to create and update a stack in AWS
  • Deleted stack to ensure resources are deleted
  • Created multiple resources in same stack
  • Validated in Atlas UI
  • Included screenshots

Required Checklist:

  • I have signed the MongoDB CLA
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that this change does not generate any credentials and that they are NOT accidentally logged anywhere.
  • I have added any necessary documentation (if appropriate)
  • I have run make fmt and formatted my code
  • For CFN Resources: I have released by changes in the private registry and proved by change
    works in Atlas

Further comments

Copilot AI review requested due to automatic review settings March 9, 2026 14:08
@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2026

Hey there and thank you for opening this pull request! 👋🏼

We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted.

Details: CONTRIBUTING.md

No release type found in pull request title "CLOUDP-380507-cluster: update schema and handler implementation". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/

Available types:
 - feat
 - fix
 - chore
 - doc
 - test
 - security
 - remove
 - deprecate
 - refactor
 - perf
 - ci
 - revert
 - style

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the MongoDB Atlas Cluster CloudFormation resource to align with newer Atlas Admin API/SDK behavior, including new cluster properties and process args support.

Changes:

  • Bumps cluster resource implementation to use go.mongodb.org/atlas-sdk/v20250312013/admin and switches advanced config calls to GetProcessArgs / UpdateProcessArgs.
  • Extends the CFN schema/model and docs with new cluster properties (e.g., config server management mode, scaling strategy, log redaction) and new process args fields.
  • Adjusts DiskSizeGB handling to map the CFN top-level DiskSizeGB to per-hardware-spec disk sizing in the newer API.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
cfn-resources/cluster/mongodb-atlas-cluster.json Adds new schema properties (cluster + process args) and marks RetainBackups as write-only.
cfn-resources/cluster/docs/processargs.md Documents the two new process args fields.
cfn-resources/cluster/docs/README.md Documents newly added top-level cluster properties.
cfn-resources/cluster/cmd/resource/resource.go Switches to the newer SDK client and updates process args API usage; supports RetainBackups on delete.
cfn-resources/cluster/cmd/resource/model.go Regenerates model structs to include new fields.
cfn-resources/cluster/cmd/resource/mappings.go Updates mapping logic for the new SDK types, adds new fields, and introduces DiskSizeGB translation helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 99 to 100
fmt.Printf("specs: len %d %+v", len(replicationSpecs), rSpecs)
return rSpecs
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

There is a leftover debug print (fmt.Printf) in expandReplicationSpecs that will write cluster configuration details to stdout/logs on every create/update. Please remove this line or replace it with the project’s structured logger at an appropriate debug level (and ensure it’s gated/disabled by default).

Copilot uses AI. Check for mistakes.
Comment on lines +92 to 95
// NumShards is not supported in the v20250312013 API; each shard must be a separate ReplicationSpec entry.
if replicationSpecs[i].ZoneName != nil {
rSpec.ZoneName = admin20231115014.PtrString(cast.ToString(replicationSpecs[i].ZoneName))
rSpec.ZoneName = admin.PtrString(cast.ToString(replicationSpecs[i].ZoneName))
}
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

NumShards is still present in the CFN schema/model (AdvancedReplicationSpec.NumShards), but this mapping now ignores it (comment says the API no longer supports it). This will silently drop a user-specified value. Either remove/deprecate NumShards from the schema/docs (and regenerate), or explicitly return an InvalidRequest error when NumShards is set so users don’t think it’s applied.

Copilot uses AI. Check for mistakes.
Comment on lines +412 to 416
// expandAdvancedSettings maps the CFN ProcessArgs model to the v20250312013 process args request.
// Note: DefaultReadConcern and FailIndexKeyTooLong are not sent as they were removed from the API.
func expandAdvancedSettings(processArgs ProcessArgs) *admin.ClusterDescriptionProcessArgs20240805 {
var args admin.ClusterDescriptionProcessArgs20240805

Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

The implementation intentionally no longer sends or populates DefaultReadConcern and FailIndexKeyTooLong, but these properties remain in the CFN schema/docs. As a result, stack updates that set these fields cannot ever converge to the desired state. Please either (a) remove/deprecate these properties in the schema/docs, or (b) add validation that fails the request when they are set (with a clear message) so the behavior is explicit.

Copilot uses AI. Check for mistakes.
Comment on lines 560 to 567
if currentModel.ReplicationSpecs != nil {
adminRepSpecs := expandReplicationSpecs(currentModel.ReplicationSpecs)
// Apply top-level DiskSizeGB to all hardware specs in the request
if currentModel.DiskSizeGB != nil {
applyDiskSizeGBToSpecs(adminRepSpecs, currentModel.DiskSizeGB)
}
clusterRequest.ReplicationSpecs = &adminRepSpecs
}
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

DiskSizeGB is only applied to the Atlas request when ReplicationSpecs is provided. Since ReplicationSpecs is not a required CFN property, users can update DiskSizeGB without specifying replication specs and this change would be silently ignored. Consider handling the case where DiskSizeGB is set but ReplicationSpecs is nil (e.g., fetch current replication specs and apply the disk size to them, or return an InvalidRequest error instructing users to include ReplicationSpecs).

Copilot uses AI. Check for mistakes.
Comment on lines +709 to +745
// diskSizeGBFromSpecs reads the DiskSizeGB from the first electable spec of the first replication spec.
// In the v20250312013 API, DiskSizeGB is per hardware spec rather than a top-level cluster field.
func diskSizeGBFromSpecs(replicationSpecs []admin.ReplicationSpec20240805) *float64 {
for _, spec := range replicationSpecs {
for _, rc := range spec.GetRegionConfigs() {
if rc.ElectableSpecs != nil && rc.ElectableSpecs.DiskSizeGB != nil {
return rc.ElectableSpecs.DiskSizeGB
}
}
}
return nil
}

// applyDiskSizeGBToSpecs applies the given diskSizeGB value to all hardware specs in all replication specs.
// This maps the CFN top-level DiskSizeGB property to the per-spec field required by the v20250312013 API.
func applyDiskSizeGBToSpecs(replicationSpecs []admin.ReplicationSpec20240805, diskSizeGB *float64) {
if diskSizeGB == nil {
return
}
for i := range replicationSpecs {
if replicationSpecs[i].RegionConfigs == nil {
continue
}
for j := range *replicationSpecs[i].RegionConfigs {
rc := &(*replicationSpecs[i].RegionConfigs)[j]
if rc.ElectableSpecs != nil {
rc.ElectableSpecs.DiskSizeGB = diskSizeGB
}
if rc.AnalyticsSpecs != nil {
rc.AnalyticsSpecs.DiskSizeGB = diskSizeGB
}
if rc.ReadOnlySpecs != nil {
rc.ReadOnlySpecs.DiskSizeGB = diskSizeGB
}
}
}
}
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

The new disk-size translation helpers (diskSizeGBFromSpecs / applyDiskSizeGBToSpecs) introduce non-trivial behavior that impacts create/update/read, but there are no unit tests covering them. Please add tests that verify DiskSizeGB is extracted from electable specs and propagated to electable/analytics/readOnly specs across region configs, and that nil/missing specs are handled correctly.

Copilot uses AI. Check for mistakes.
Comment on lines +34 to +39
"<a href="#tags" title="Tags">Tags</a>" : <i>[ <a href="tag.md">tag</a>, ... ]</i>,
"<a href="#configservermanagementmode" title="ConfigServerManagementMode">ConfigServerManagementMode</a>" : <i>String</i>,
"<a href="#replicasetscalingstrategy" title="ReplicaSetScalingStrategy">ReplicaSetScalingStrategy</a>" : <i>String</i>,
"<a href="#acceptdatarisksandforcereplicasetreconfig" title="AcceptDataRisksAndForceReplicaSetReconfig">AcceptDataRisksAndForceReplicaSetReconfig</a>" : <i>String</i>,
"<a href="#retainbackups" title="RetainBackups">RetainBackups</a>" : <i>Boolean</i>,
"<a href="#redactclientlogdata" title="RedactClientLogData">RedactClientLogData</a>" : <i>Boolean</i>
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

The PR description still contains the template placeholders (e.g., _Jira ticket:_ CLOUDP-#) and no summary/QA info. Please update the PR description to reference CLOUDP-380507 and briefly describe the behavior change and validation/QA performed so reviewers can assess impact.

Copilot uses AI. Check for mistakes.
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.

2 participants