close
Skip to content

sql: fix DataCacheConfig diff when enabled=false#7145

Merged
cheftako merged 1 commit into
GoogleCloudPlatform:masterfrom
anhdle-sso:fix-sqlinstance-datacacheconfig-diff
Mar 25, 2026
Merged

sql: fix DataCacheConfig diff when enabled=false#7145
cheftako merged 1 commit into
GoogleCloudPlatform:masterfrom
anhdle-sso:fix-sqlinstance-datacacheconfig-diff

Conversation

@anhdle-sso
Copy link
Copy Markdown
Collaborator

BRIEF Change description

This PR fixes a diff in SQLInstance where .settings.dataCacheConfig is incorrectly detected as different when dataCacheEnabled is false, because GCP omits the field in its response.

Fixes #7144

WHY do we need this change?

When dataCacheEnabled is set to false, GCP returns a nil object for dataCacheConfig. The previous equality logic used PointersMatch, which failed when comparing a non-nil desired object (with dataCacheEnabled: false) against a nil actual object.

Special notes for your reviewer:

None.

Does this PR add something which needs to be 'release noted'?

NONE

Additional documentation e.g., references, usage docs, etc.:

NONE

Intended Milestone

NONE

Tests you have done

  • Verified using hack/compare-mock pkg/test/resourcefixture/testdata/basic/sql/v1beta1/sqlinstance/sqlinstance-datacacheconfig-direct that the resource becomes Ready.

@anhdle-sso anhdle-sso force-pushed the fix-sqlinstance-datacacheconfig-diff branch from 1c710b8 to 0692efd Compare March 23, 2026 23:46
@anhdle-sso anhdle-sso force-pushed the fix-sqlinstance-datacacheconfig-diff branch 3 times, most recently from e343283 to 1e68a81 Compare March 24, 2026 00:56
@codebot-robot
Copy link
Copy Markdown
Collaborator

--- INVESTIGATION REPORT ---
Run ID: 23465885489
Name: tests-scenarios-unclassified
Cause: Infrastructure
Details: The job failed because it hit the 1-hour timeout (TEST_TIMEOUT=3600s) during an earlier workflow run. Running the SQL scenarios locally confirms they pass in under 3 minutes, so the timeout was not caused by the PR's code. Additionally, other workflows were cancelled because the checks were re-triggered via a new commit/push. The code changes in the PR compile successfully and linting has passed in the subsequent runs.
Action Taken: None

(This report was generated by Overseer)

@codebot-robot codebot-robot self-assigned this Mar 24, 2026
Copy link
Copy Markdown
Collaborator

@codebot-robot codebot-robot left a comment

Choose a reason for hiding this comment

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

This is a clean and solid fix that successfully addresses the DataCacheConfig false diff loop when DataCacheEnabled is disabled. The changes precisely mimic GCP's API response behavior by entirely omitting the DataCacheConfig object, and the mock updates align nicely with this real response format. Overall, the fix is logically sound and testing is properly updated.

I have left a few minor maintainability suggestions aimed at improving code conciseness, preserving context about metadata fields (like ForceSendFields) previously documented in the equality function, and future-proofing the equality check if GCP adds more fields to DataCacheConfig down the line.

(This review was generated by Overseer)

return true
// GCP omits DataCacheConfig when DataCacheEnabled is false.
// Treat nil and false as equivalent.
desiredEnabled := false
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If this nil-safe getter pattern is used frequently or if this function grows, consider abstracting this into a simple helper like isDataCacheEnabled(config *api.DataCacheConfig) bool. This would reduce the body of this check to return isDataCacheEnabled(desired) == isDataCacheEnabled(actual).

// Ignore ForceSendFields. Assume it is set correctly in desired.
// Ignore NullFields. Assume it is set correctly in desired.
return true
return desiredEnabled == actualEnabled
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Returning a straight boolean equivalence here effectively discards checking any other fields in the struct. While DataCacheEnabled is the only substantive property today, any future fields added by GCP (e.g., a cache size setting) will be silently ignored when both sides evaluate as enabled. Consider restructuring this to perform a field-by-field check (or adding a TODO comment) if both caches are enabled.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not blocking but I do think that at some point fields may get added. When that happens we would need to fix this code anyway but either a TODO or a slight restructure like the following would make that easier.

if desiredEnabled != actualEnabled {
    return false
}
// All fields match returning true
return true

Comment thread mockgcp/mocksql/sqlinstance.go
return true
// GCP omits DataCacheConfig when DataCacheEnabled is false.
// Treat nil and false as equivalent.
desiredEnabled := false
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This block can be simplified into a single, idiomatic inline assignment to improve conciseness:

@codebot-robot
Copy link
Copy Markdown
Collaborator

@justinsb This PR is successful, mergeable and ready for review. Could you please review and approve it? (Overseer)

1 similar comment
@codebot-robot
Copy link
Copy Markdown
Collaborator

@justinsb This PR is successful, mergeable and ready for review. Could you please review and approve it? (Overseer)

@codebot-robot
Copy link
Copy Markdown
Collaborator

Starting task: address-feedback (new feedback since last commit/action)

Copy link
Copy Markdown
Collaborator

@codebot-robot codebot-robot left a comment

Choose a reason for hiding this comment

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

Thanks for the feedback! I've updated the PR:

  1. Abstracted the nil-safe getter pattern into an isDataCacheEnabled helper.
  2. Restructured the boolean equivalence check to explicitly return early for the disabled case, leaving room for future field-by-field comparisons if both are enabled.
  3. Added a comment in mocksql explaining the GCP response behavior.
  4. Simplified the desiredEnabled / actualEnabled assignments.

(This comment was generated by Overseer)

@codebot-robot
Copy link
Copy Markdown
Collaborator

@maqiuyujoyce This PR is successful, mergeable and ready for review. Could you please review and approve it? (Overseer)

Copy link
Copy Markdown
Collaborator

@cheftako cheftako left a comment

Choose a reason for hiding this comment

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

There is a nice to have here but not blocking.

// Ignore ForceSendFields. Assume it is set correctly in desired.
// Ignore NullFields. Assume it is set correctly in desired.
return true
return desiredEnabled == actualEnabled
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not blocking but I do think that at some point fields may get added. When that happens we would need to fix this code anyway but either a TODO or a slight restructure like the following would make that easier.

if desiredEnabled != actualEnabled {
    return false
}
// All fields match returning true
return true

@cheftako cheftako added this pull request to the merge queue Mar 25, 2026
@google-oss-prow google-oss-prow Bot added the lgtm label Mar 25, 2026
@google-oss-prow
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cheftako

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@cheftako cheftako added this to the 1.148 milestone Mar 25, 2026
@cheftako
Copy link
Copy Markdown
Collaborator

/cc @acpana

@google-oss-prow google-oss-prow Bot requested a review from acpana March 25, 2026 19:04
Merged via the queue into GoogleCloudPlatform:master with commit a2fb838 Mar 25, 2026
329 of 331 checks passed
acpana added a commit that referenced this pull request Mar 30, 2026
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.

SQLInstance .settings.dataCacheConfig constance update

3 participants