← Back to Pull requests

Greenfield: Implement direct controller, E2E fixtures, and fuzzer for DiscoveryEngineSchema #13777

Merged
ada-coder-bot merged 21 files (1595 lines) on Oct 21, 2026 13:20 UTC
View on GitHub
ada-coder-bot ada-coder-bot commented on Oct 07, 2026 04:05 UTC
Author

This PR implements the direct controller, E2E fixtures, and fuzzer for DiscoveryEngineSchema (discoveryengine.cnrm.cloud.google.com/v1alpha1).

Fixes #13771

Summary of Changes


1. Direct Controller:
- Implemented pkg/controller/direct/discoveryengine/discoveryengineschema_controller.go with GAPIC REST client (NewSchemaRESTClient).
- Implemented Find, Create, Update, Delete, and Export.
- Added semantic JSON unmarshaling comparison in compare() to prevent false diffs caused by whitespace/formatting differences in jsonSchema.
- Handled unsupported result type <nil>: <nil> gracefully during DeleteSchema operation wait.
2. Fuzzer:
- Implemented pkg/controller/direct/discoveryengine/discoveryengineschema_fuzzer.go registering with RegisterKRMSpecFuzzer.
3. Static Configuration:
- Registered DiscoveryEngineSchema with ReconcilerTypeDirect in pkg/controller/resourceconfig/static_config.go.
4. E2E Test Fixtures:
- Created minimal and maximal test fixtures under pkg/test/resourcefixture/testdata/basic/discoveryengine/v1alpha1/discoveryengineschema/.
5. Real GCP Recording:
- Successfully recorded golden files (_http.log, _generated_object_*.golden.yaml, _identities.yaml) against real GCP project cnrm-barni-4 using RECORD_AUDIT_PROBE=1 ./hack/record-gcp.
6. API Field Checks:
- Updated alpha-missingfields.txt to reflect test coverage for .spec.dataStoreRef and .spec.jsonSchema.
7. Journal:
- Added entry to .gemini/journals/discoveryengine.md documenting controller behavior and GCP API considerations.

Testing


  • Recorded all fixtures (discoveryengineschema-minimal, discoveryengineschema-maximal) against real GCP project cnrm-barni-4.

  • Verified round-trip fuzzer tests (TestSomeMappers).

  • Verified CRD template tests (go test ./pkg/crd/template/...).

  • Verified API coverage checks (go test ./tests/apichecks/...).
  • This PR was generated by the overseer,greenfield,step/controller,overseer/review agent (powered by the gemini-3.7-flash model).

    ``release-note
    NONE
    ``

    Diff: 1595 lines (+1592 / -3) across 21 files Reviewer: maqiuyujoyce Review duration: 20715m
    All Vouch review confidence checks passed
    Residual risk 0.10 = Change Risk (0.72) × (1 − Review Confidence (0.86)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.72 · 1595 lines diff across 21 files
    0.72
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.81 · 5 substantive comment(s)
    0.81
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    86%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.400
    Mass File Touch mass_file_touch
    0.080
    Real PR Conversation Timeline
    16 items
    ada-coder-bot ada-coder-bot commented on Oct 07, 2026 04:05 UTC
    Author

    Real GCP Audit Logs Verification

    The following Google Cloud audit logs demonstrate that the real GCP API endpoints (discoveryengine.googleapis.com) were exercised during E2E testing against project cnrm-barni-4:

    ---
    insertId: xaw0xwe2m97y
    logName: projects/cnrm-barni-4/logs/cloudaudit.googleapis.com%2Factivity
    operation:
      first: true
      id: projects/600845353393/locations/global/collections/default_collection/dataStores/datastore-6iza4hcaoe2vbmy/schemas/default_schema/operations/delete-schema-15148982481388079850
      last: true
      producer: discoveryengine.googleapis.com
    protoPayload:
      '@type': type.googleapis.com/google.cloud.audit.AuditLog
      authenticationInfo:
        principalEmail: overseer-kcc-tester@cnrm-barni-4.iam.gserviceaccount.com
      authorizationInfo:
      - granted: true
        permission: discoveryengine.schemas.delete
        permissionType: ADMIN_WRITE
        resource: projects/cnrm-barni-4/locations/global/dataStores/datastore-6iza4hcaoe2vbmy/schemas/default_schema
      methodName: google.cloud.discoveryengine.v1.SchemaService.DeleteSchema
      request:
        '@type': type.googleapis.com/google.cloud.discoveryengine.v1.DeleteSchemaRequest
        name: projects/cnrm-barni-4/locations/global/dataStores/datastore-6iza4hcaoe2vbmy/schemas/default_schema
      requestMetadata:
        callerSuppliedUserAgent: kcc/1.159.0 (+https://github.com/GoogleCloudPlatform/k8s-config-connector) kcc/controller-manager/1.159.0,gzip(gfe)
      resourceName: projects/cnrm-barni-4/locations/global/dataStores/datastore-6iza4hcaoe2vbmy/schemas/default_schema
      serviceName: discoveryengine.googleapis.com
    severity: NOTICE
    timestamp: '2026-10-07T03:45:14.698017508Z'
    ---
    insertId: 7ivjntd5rsi
    logName: projects/cnrm-barni-4/logs/cloudaudit.googleapis.com%2Factivity
    operation:
      first: true
      id: projects/600845353393/locations/global/collections/default_collection/dataStores/datastore-6iza4hcaoe2vbmy/schemas/default_schema/operations/update-schema-16394363439438522526
      producer: discoveryengine.googleapis.com
    protoPayload:
      '@type': type.googleapis.com/google.cloud.audit.AuditLog
      authenticationInfo:
        principalEmail: overseer-kcc-tester@cnrm-barni-4.iam.gserviceaccount.com
      authorizationInfo:
      - granted: true
        permission: discoveryengine.schemas.update
        permissionType: ADMIN_WRITE
        resource: projects/cnrm-barni-4/locations/global/dataStores/datastore-6iza4hcaoe2vbmy/schemas/default_schema
      methodName: google.cloud.discoveryengine.v1.SchemaService.UpdateSchema
      request:
        '@type': type.googleapis.com/google.cloud.discoveryengine.v1.UpdateSchemaRequest
        schema:
          name: projects/cnrm-barni-4/locations/global/dataStores/datastore-6iza4hcaoe2vbmy/schemas/default_schema
      requestMetadata:
        callerSuppliedUserAgent: kcc/1.159.0 (+https://github.com/GoogleCloudPlatform/k8s-config-connector) kcc/controller-manager/1.159.0,gzip(gfe)
      resourceName: projects/cnrm-barni-4/locations/global/dataStores/datastore-6iza4hcaoe2vbmy/schemas/default_schema
      serviceName: discoveryengine.googleapis.com
    severity: NOTICE
    timestamp: '2026-10-07T03:45:08.572945048Z'
    ---
    insertId: 1mtn9cte3sjnr
    logName: projects/cnrm-barni-4/logs/cloudaudit.googleapis.com%2Factivity
    operation:
      first: true
      id: projects/600845353393/locations/global/collections/default_collection/dataStores/datastore-5up7hlnjczaev4y/schemas/default_schema/operations/delete-schema-7512656779557408155
      last: true
      producer: discoveryengine.googleapis.com
    protoPayload:
      '@type': type.googleapis.com/google.cloud.audit.AuditLog
      authenticationInfo:
        principalEmail: overseer-kcc-tester@cnrm-barni-4.iam.gserviceaccount.com
      authorizationInfo:
      - granted: true
        permission: discoveryengine.schemas.delete
        permissionType: ADMIN_WRITE
        resource: projects/cnrm-barni-4/locations/global/dataStores/datastore-5up7hlnjczaev4y/schemas/default_schema
      methodName: google.cloud.discoveryengine.v1.SchemaService.DeleteSchema
      request:
        '@type': type.googleapis.com/google.cloud.discoveryengine.v1.DeleteSchemaRequest
        name: projects/cnrm-barni-4/locations/global/dataStores/datastore-5up7hlnjczaev4y/schemas/default_schema
      requestMetadata:
        callerSuppliedUserAgent: kcc/1.159.0 (+https://github.com/GoogleCloudPlatform/k8s-config-connector) kcc/controller-manager/1.159.0,gzip(gfe)
      resourceName: projects/cnrm-barni-4/locations/global/dataStores/datastore-5up7hlnjczaev4y/schemas/default_schema
      serviceName: discoveryengine.googleapis.com
    severity: NOTICE
    timestamp: '2026-10-07T03:44:16.674217895Z'
    ---
    insertId: 11r7dqfe3n99v
    logName: projects/cnrm-barni-4/logs/cloudaudit.googleapis.com%2Factivity
    operation:
      first: true
      id: projects/600845353393/locations/global/collections/default_collection/dataStores/datastore-5up7hlnjczaev4y/schemas/default_schema/operations/update-schema-5906176711145527115
      producer: discoveryengine.googleapis.com
    protoPayload:
      '@type': type.googleapis.com/google.cloud.audit.AuditLog
      authenticationInfo:
        principalEmail: overseer-kcc-tester@cnrm-barni-4.iam.gserviceaccount.com
      authorizationInfo:
      - granted: true
        permission: discoveryengine.schemas.update
        permissionType: ADMIN_WRITE
        resource: projects/cnrm-barni-4/locations/global/dataStores/datastore-5up7hlnjczaev4y/schemas/default_schema
      methodName: google.cloud.discoveryengine.v1.SchemaService.UpdateSchema
      request:
        '@type': type.googleapis.com/google.cloud.discoveryengine.v1.UpdateSchemaRequest
        schema:
          name: projects/cnrm-barni-4/locations/global/dataStores/datastore-5up7hlnjczaev4y/schemas/default_schema
      requestMetadata:
        callerSuppliedUserAgent: kcc/1.159.0 (+https://github.com/GoogleCloudPlatform/k8s-config-connector) kcc/controller-manager/1.159.0,gzip(gfe)
      resourceName: projects/cnrm-barni-4/locations/global/dataStores/datastore-5up7hlnjczaev4y/schemas/default_schema
      serviceName: discoveryengine.googleapis.com
    severity: NOTICE
    timestamp: '2026-10-07T03:44:11.534516889Z'
    

    argus-watcher-bot argus-watcher-bot commented on Oct 07, 2026 04:23 UTC
    Bot

    🤖 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 ada-coder-bot commented on Oct 07, 2026 05:05 UTC
    Author

    Investigating unit-tests-2-of-4 failure


    Run: 37569786313
    Name: unit-tests-2-of-4
    Cause: Test Failure
    Details: In pkg/cli/powertools/cais unit test TestGoldenIdentitiesYamlFiles, DiscoveryEngineSchema's identity resolution failed because the referenced dependency DiscoveryEngineDataStore in dependencies.yaml did not include status.externalRef. In live E2E tests, the live cluster populates status.externalRef upon creation of the dependency, allowing GetIdentity to resolve successfully when recording _identities.yaml. In static unit tests (TestGoldenIdentitiesYamlFiles), status.externalRef was missing, causing reference normalization to return NewReferenceNotReadyError and mismatching the golden _identities.yaml.
    Action Taken: Added status.externalRef to DiscoveryEngineDataStore in pkg/test/resourcefixture/testdata/basic/discoveryengine/v1alpha1/discoveryengineschema/discoveryengineschema-minimal/dependencies.yaml and pkg/test/resourcefixture/testdata/basic/discoveryengine/v1alpha1/discoveryengineschema/discoveryengineschema-maximal/dependencies.yaml, verified unit test shard 2 of 4 passes locally, and pushed the updated commit.

    (This report was generated by overseer)

    argus-watcher-bot argus-watcher-bot commented on Oct 07, 2026 05:36 UTC
    Bot

    🤖 AI Factory started reviewing this pull request in a sandbox.

    reviewbot-robot reviewbot-robot commented on Oct 07, 2026 05:53 UTC
    Reviewer

    KCC Auto-Review Results


    Trigger criteria matched: Yes
    Client Creation: Pass - Uses official GAPIC Go REST client gcp.NewSchemaRESTClient.
    Default Reconciler Kept: Pass - Greenfield resource correctly registered with ReconcilerTypeDirect in pkg/controller/resourceconfig/static_config.go.
    Proto Diffs & Update Mask: Pass - Uses mappers.OnlySpecFields and common.DiffForTopLevelFields with JSON unmarshaling normalization for whitespace-insensitive schema comparison; UpdateSchemaRequest does not require update_mask.
    Structured Reporting: Pass - structuredreporting.ReportDiff(ctx, diffs) is invoked in Update() prior to sending update requests.
    KRM Status Updates: Pass - Invokes updateStatus on creation, update, and no-op update paths.
    LRO Wait: Pass - Waits on operations in Create, Update, and Delete (handling the REST client empty result gracefully).
    Test Coverage: Pass - Includes minimal and maximal test cases with recorded real GCP fixtures (_http.log, golden YAMLs, _identities.yaml), round-trip fuzzer, and updated missing field exceptions.

    Detailed Findings / Actions Required:


    None. The implementation complies with greenfield controller standards.

    argus-watcher-bot argus-watcher-bot commented on Oct 07, 2026 05:56 UTC
    Bot

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

    acpana acpana commented on Oct 16, 2026 21:23 UTC
    Reviewer

    how come there are no audit probe logs? Either include them or give out a reason as to why you cannot check that the tests ran against real GCP.

    argus-watcher-bot argus-watcher-bot commented on Oct 16, 2026 21:30 UTC
    Bot

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

    argus-watcher-bot argus-watcher-bot commented on Oct 16, 2026 23:34 UTC
    Bot

    🤖 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.

    maqiuyujoyce maqiuyujoyce commented on Oct 21, 2026 08:37 UTC
    Reviewer

    Please add brief code comments in pkg/controller/direct/discoveryengine/discoveryengineschema_controller.go to document the non-obvious API and protobuf behaviors in Update() and compare().

    1. In Update() (around line 241, diffs, _, err := a.compare(...)): Add a comment explaining why updateMask is ignored (_) — i.e., pb.UpdateSchemaRequest in discoveryenginepb does not have an UpdateMask field, so compare() is only used to check diffs.HasDiff() and report diffs via structuredreporting.ReportDiff.

    2. In compare() (around line 284, json.Unmarshal + reflect.DeepEqual):
    Add a comment explaining why semantic JSON comparison is needed — i.e., the GCP API returns jsonSchema as a compacted JSON string and non-deterministically reorders object keys across GET calls, whereas KRM manifests typically format jsonSchema as a multi-line indented string. Since common.DiffForTopLevelFields performs byte-for-byte string comparison on protoreflect.Value, unmarshaling both into any and checking reflect.DeepEqual prevents false diffs and infinite PATCH loops during re-reconciliation.

    Note: Since DiscoveryEngineDataStore doesn't support skipDefaultSchemaCreation yet, the E2E fixtures manage the auto-created default_schema and only hit PATCH (UpdateSchema). We'll follow up in https://github.com/GoogleCloudPlatform/k8s-config-connector/issues/14230 to support skipDefaultSchemaCreation and test the POST (CreateSchema) path.

    argus-watcher-bot argus-watcher-bot commented on Oct 21, 2026 11:19 UTC
    Bot

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

    ada-coder-bot ada-coder-bot commented on Oct 21, 2026 11:28 UTC
    Author

    Please add brief code comments in pkg/controller/direct/discoveryengine/discoveryengineschema_controller.go to document the non-obvious API and protobuf behaviors in Update() and compare().

    > 1. In Update() (around line 241, diffs, _, err := a.compare(...)): Add a comment explaining why updateMask is ignored (_) — i.e., pb.UpdateSchemaRequest in discoveryenginepb does not have an UpdateMask field, so compare() is only used to check diffs.HasDiff() and report diffs via structuredreporting.ReportDiff.

    …

    In reply to @maqiuyujoyce's review

    Please add brief code comments in pkg/controller/direct/discoveryengine/discoveryengineschema_controller.go to document the non-obvious API and protobuf behaviors in Update() and compare().

    > 1. In Update() (around line 241, diffs, _, err := a.compare(...)): Add a comment explaining why updateMask is ignored (_) — i.e., pb.UpdateSchemaRequest in discoveryenginepb does not have an UpdateMask field, so compare() is only used to check diffs.HasDiff() and report diffs via structuredreporting.ReportDiff.

    > 2. In compare() (around line 284, json.Unmarshal + reflect.DeepEqual):

    Add a comment explaining why semantic JSON comparison is needed — i.e., the GCP API returns jsonSchema as a compacted JSON string and non-deterministically reorders object keys across GET calls, whereas KRM manifests typically format jsonSchema as a multi-line indented string. Since common.DiffForTopLevelFields performs byte-for-byte string comparison on protoreflect.Value, unmarshaling both into any and checking reflect.DeepEqual prevents false diffs and infinite PATCH loops during re-reconciliation.

    > Note: Since DiscoveryEngineDataStore doesn't support skipDefaultSchemaCreation yet, the E2E fixtures manage the auto-created default_schema and only hit PATCH (UpdateSchema). We'll follow up in https://github.com/GoogleCloudPlatform/k8s-config-connector/issues/14230 to support skipDefaultSchemaCreation and test the POST (CreateSchema) path.

    Added code comments in pkg/controller/direct/discoveryengine/discoveryengineschema_controller.go to document both behaviors:
    1. In Update(): documented that pb.UpdateSchemaRequest does not support update_mask, so compare() is solely used to detect diffs (diffs.HasDiff()) and report them via structuredreporting.ReportDiff.
    2. In compare(): documented that semantic JSON comparison (json.Unmarshal into any followed by reflect.DeepEqual) is required because the GCP API returns compacted JSON with non-deterministic key ordering across GET calls, preventing false diffs against indented KRM schema strings and avoiding infinite PATCH loops during re-reconciliation.

    (Written by an AI coding agent)

    <sub>🤖 Agent session</sub>

    <!-- factory:task-output kind=Change task=recipe-care-comments-20261021-111946-70a7 reply=5597035904 -->

    ada-coder-bot ada-coder-bot commented on Oct 21, 2026 11:28 UTC
    Author

    Addressed reviewer feedback from @maqiuyujoyce on pkg/controller/direct/discoveryengine/discoveryengineschema_controller.go:

  • Documented why updateMask is ignored in Update().

  • Documented why semantic JSON comparison is used in compare().

  • Verified all fuzzer tests continue to pass.
  • (Written by an AI coding agent)

    <sub>🤖 Agent session</sub>

    <!-- factory:task-output kind=Change task=recipe-care-comments-20261021-111946-70a7 -->

    maqiuyujoyce maqiuyujoyce approved these changes on Oct 21, 2026 12:58 UTC
    Approved Reviewer

    /lgtm

    google-oss-prow[bot] google-oss-prow[bot] commented on Oct 21, 2026 12:59 UTC
    Bot

    [APPROVALNOTIFIER] This PR is APPROVED

    This pull-request has been approved by: <a href="https://github.com/GoogleCloudPlatform/k8s-config-connector/pull/13777#pullrequestreview-5600035187" title="LGTM">maqiuyujoyce</a>

    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:

  • ~~OWNERS~~ [maqiuyujoyce]
  • Approvers can indicate their approval by writing /approve in a comment
    Approvers can cancel approval by writing /approve cancel in a comment
    </details>
    <!-- META={"approvers":[]} -->

    Reviewers
    Assignees
    ada-coder-bot ada-coder-bot
    Labels
    risk: low confidence: 86.2% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 71.5% (HIGH) · Higher = larger blast radius
    71.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 86.2% · Lower = rushed or shallow review
    86.2%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 9.9% · Safe to merge
    9.9%