Skip to content

[EssentialContactsContact] Support automatic acquisition of existing contact by email on 409 ALREADY_EXISTS - #13845

Merged
anhdle-sso merged 5 commits into
GoogleCloudPlatform:masterfrom
ada-coder-bot:issue-13840-1791498875
Oct 12, 2026
Merged

anhdle-sso merged 5 commits into
GoogleCloudPlatform:masterfrom
ada-coder-bot:issue-13840-1791498875

Conversation

@ada-coder-bot

Copy link
Copy Markdown
Collaborator

Description

Support automatic resource acquisition by spec.email for EssentialContactsContact when spec.resourceID (and status.externalRef) is not specified and a contact with the same email already exists under the target parent (projectRef, folderRef, or organizationRef).

Summary of Changes

  • Direct Controller (essentialcontactscontact_controller.go):
    • Implemented acquireExistingContact and findContactByEmail to automatically adopt pre-existing essential contacts matching spec.email under the specified parent when creation encounters HTTP 409 (ALREADY_EXISTS).
    • Updated status.externalRef and mutable spec fields (notificationCategorySubscriptions, languageTag) upon successful acquisition.
  • Direct Map Utils (maputils.go):
    • Updated IsAlreadyExists to recognize googleapi.Error with HTTP code 409 in addition to gRPC/apierror status codes.
  • Mock GCP (methodcall.go & contact.go):
    • Added HTTP status code 409 Conflict mapping for codes.AlreadyExists in httptogrpc/methodcall.go.
    • Updated mockessentialcontacts to search contacts by project ID/number and generate unique server IDs upon collision.
  • Test Fixture:
    • Added essentialcontactscontact-acquire test fixture to test acquiring existing contact and patching mutable fields.

Fixes #13840

[EssentialContactsContact] Support automatic acquisition of existing contact by email on 409 ALREADY_EXISTS

This PR was generated by the overseer agent (powered by the gemini-3.7-flash model).

@ada-coder-bot ada-coder-bot added enhancement New feature or request overseer labels Oct 8, 2026
@argus-watcher-bot argus-watcher-bot added priority/high overseer/ready-for-human This PR is ready to be looked at by a human labels Oct 9, 2026
@anhdle-sso

Copy link
Copy Markdown
Collaborator

Thanks for working on this! The implementation logic looks solid.

We tested this scenario against real GCP using ./hack/record-gcp "fixtures/essentialcontactscontact-acquire$" and confirmed that the acquire and update lifecycle works as expected on live GCP APIs.

Could we please:

  1. Run ./hack/record-gcp "fixtures/essentialcontactscontact-acquire$" to record and commit the authentic real GCP _http.log.
  2. Fix the minor differences in mockessentialcontacts to align with authentic GCP responses:
    • 409 Error Message: Real GCP does not enclose the email in brackets (e.g. There is already a contact with the given email address alerts-...@test.com. To add new category subscriptions, please use UpdateContact instead. instead of [alerts-...@test.com]).
    • 404 Not Found Message: Real GCP returns "message": "Requested entity was not found." rather than "message": "contact ... not found".

@argus-watcher-bot

Copy link
Copy Markdown
Collaborator

🤖 AI Factory started addressing review feedback for this pull request.

@ada-coder-bot

Copy link
Copy Markdown
Collaborator Author

Thanks for the review and verification!

I have addressed both feedback items:

  1. Recorded authentic real GCP logs:

    • Recorded live GCP traffic for fixtures/essentialcontactscontact-acquire$ and committed the authentic golden log _http.log.
    • Recording timestamps (PDT):
      • Start: Fri Oct 9 16:07:09 PDT 2026
      • Finish: Fri Oct 9 16:07:25 PDT 2026
  2. Aligned MockGCP with authentic GCP responses:

    • Updated the 409 Conflict error message in mockessentialcontacts (CreateContact) to remove brackets around the email address (There is already a contact with the given email address alerts-...@test.com. To add new category subscriptions, please use UpdateContact instead.).
    • Updated 404 Not Found error responses across GetContact, UpdateContact, and DeleteContact in mockessentialcontacts to return "message": "Requested entity was not found.".
    • Updated and aligned _http_mock.log, verifying both real and mock tests pass with zero diffs.

(This comment was generated by overseer)

@argus-watcher-bot

Copy link
Copy Markdown
Collaborator

🤖 AI Factory started investigating CI check failures for this pull request.

Note: We recommend waiting for the 'ready-for-human' label before leaving review comments. Comments added while the system is actively working may be associated with outdated commits once a new commit is pushed, causing them to be ignored.

@ada-coder-bot

Copy link
Copy Markdown
Collaborator Author

Investigating unit-tests-2-of-4 failure

Run: 38006812508
Name: unit-tests-2-of-4
Cause: Test Failure
Details: In TestGoldenLogAlignment, fixture essentialcontacts/v1beta1/essentialcontactscontact/essentialcontactscontact-acquire failed when comparing _http.log against _http_mock.log. The Essential Contacts API assigns arbitrary integer contact IDs upon creation (real GCP assigned contacts/2, whereas Mock GCP generated contacts/7). Because cleanURL and normalizeRepresentation in pkg/test/resourcefixture/golden_alignment_test.go did not normalize the server-generated contact IDs (unlike other server-generated resources like forwardingRules and instanceGroupManagers), the alignment test failed on the contact ID payload and URL mismatch.
Action Taken: Normalized server-generated contact IDs (/contacts/[0-9]+ -> /contacts/${contactID}) in cleanURL and normalizeRepresentation in pkg/test/resourcefixture/golden_alignment_test.go. Verified all TestGoldenLogAlignment tests pass locally and pushed the fix.

(This report was generated by overseer)

@anhdle-sso anhdle-sso left a comment

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.

/lgtm

@anhdle-sso
anhdle-sso added this pull request to the merge queue Oct 12, 2026
@google-oss-prow google-oss-prow Bot added the lgtm label Oct 12, 2026
@google-oss-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: anhdle-sso
Once this PR has been reviewed and has the lgtm label, please assign cheftako for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

Merged via the queue into GoogleCloudPlatform:master with commit 2748d84 Oct 12, 2026
253 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm overseer/ready-for-human This PR is ready to be looked at by a human overseer priority/high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[EssentialContactsContact] Support automatic acquisition of existing contact by email on 409 ALREADY_EXISTS

3 participants

⌂ 换网址