Skip to content

Conversation

@lantoli
Copy link
Member

@lantoli lantoli commented Jun 2, 2025

Proposed changes

Fix nil pointer in Cluster. Cluster creation would fail for cluster configs without AdvancedSettings.
Fix regression introduced in #1344.
Issue was not caught in E2E or contract tests because they use AdvancedSettings.

Jira ticket: CLOUDP-321622

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

@lantoli lantoli marked this pull request as ready for review June 2, 2025 10:34
Copilot AI review requested due to automatic review settings June 2, 2025 10:34
@lantoli lantoli requested a review from a team as a code owner June 2, 2025 10:34
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

This PR aims to fix a nil pointer deference issue during Cluster creation by adding appropriate nil checks.

  • Corrects a mistaken nil check on the label’s Value field.
  • Adds a nil check for AdvancedSettings to prevent nil pointer issues.
  • Ensures proper pointer handling for CustomOpensslCipherConfigTls12 in the advanced configuration.
Comments suppressed due to low confidence (2)

cfn-resources/cluster/cmd/resource/mappings.go:204

  • Changing the check from labels[i].Key to labels[i].Value correctly prevents a nil pointer dereference when accessing the Value field. Confirm that similar nil checks are applied consistently in related logic if necessary.
if labels[i].Value != nil {

cfn-resources/cluster/cmd/resource/mappings.go:619

  • The added nil check for processArgs.CustomOpensslCipherConfigTls12 ensures safe pointer handling. Please verify that pointer assignments follow the same pattern consistently across similar configurations.
if processArgs.CustomOpensslCipherConfigTls12 != nil {

clusterRequest.TerminationProtectionEnabled = currentModel.TerminationProtectionEnabled

clusterRequest.AdvancedConfiguration = expandClusterAdvancedConfiguration(*currentModel.AdvancedSettings)
if currentModel.AdvancedSettings != nil {
Copy link

Copilot AI Jun 2, 2025

Choose a reason for hiding this comment

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

Adding the nil check for currentModel.AdvancedSettings prevents a potential nil pointer deference during cluster creation. This approach improves the robustness of the cluster setup.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@oarbusi oarbusi left a comment

Choose a reason for hiding this comment

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

Thank you!!

@lantoli lantoli changed the title fix: Fix nil pointer deference in Cluster fix: Fix nil pointer in Cluster Jun 2, 2025
@lantoli lantoli merged commit 99668cb into master Jun 2, 2025
41 checks passed
@lantoli lantoli deleted the CLOUDP-321622_cluster_nil branch June 2, 2025 11:29
clusterRequest.TerminationProtectionEnabled = currentModel.TerminationProtectionEnabled

clusterRequest.AdvancedConfiguration = expandClusterAdvancedConfiguration(*currentModel.AdvancedSettings)
if currentModel.AdvancedSettings != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Should we add a contract test which does not define AdvancedSettings?

Copy link
Member Author

@lantoli lantoli Jun 2, 2025

Choose a reason for hiding this comment

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

ticket created: CLOUDP-321624

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.

4 participants