8000 feat(components): dynamic k8s crd status detector and jsonpath query engine by VLukiantsev · Pull Request #581 · google/xmc · GitHub
[go: up one dir, main page]

Skip to content

feat(components): dynamic k8s crd status detector and jsonpath query engine - #581

Merged
VLukiantsev merged 4 commits into
feat/components-crd-status-detector-core-b548435805from
feat/components-crd-status-detector-b548435805
Sep 9, 2026
Merged

VLukiantsev merged 4 commits into
feat/components-crd-status-detector-core-b548435805from
feat/components-crd-status-detector-b548435805

Conversation

@VLukiantsev
@VLukiantsev VLukiantsev commented Aug 24, 2026 •
Copy link
Copy Markdown
Collaborator

Summary

Implements the dynamic Kubernetes CRD status detector engine and JSONPath query evaluation engine for third-party custom resources in XMC (Layer 6, stacked on top of PR #708).

This PR builds directly upon the StatusDetector contract established in PR #708 by introducing the production K8sStatusDetector implementation using k8s.io/client-go/dynamic and k8s.io/client-go/restmapper. It provides automatic GroupVersionResource (GVR) mapping, resilient handling for uninstalled CRDs (meta.IsNoMatchError), normalized JSONPath evaluation (EvaluateJSONPath), and status condition heuristics (status.conditions[type=Ready]).

Proposed Changes

  1. Concrete Dynamic K8s Status Detector (K8sStatusDetector) (pkg/components/bridge/k8s_status_detector.go):

    • Implements StatusDetector interface using client-go dynamic.Interface and meta.RESTMapper.
    • Dynamic GVR discovery via ResolveGVR with fallback to meta.UnsafeGuessKindToResource.
    • Resilient missing-CRD handling: Returns Found=False, Ready=False with descriptive messages when a CRD is uninstalled or when a custom resource does not exist (apierrors.IsNotFound).
  2. Normalized JSONPath Query Engine (EvaluateJSONPath) (pkg/components/bridge/k8s_status_detector.go):

    • Implements NormalizeJSONPath and EvaluateJSONPath to safely query unstructured objects.
    • Normalizes bare field expressions, leading dots, and bracket notations ({.status.conditions[?(@.type=="Ready")].status}, status.phase, $[0]).
    • Sibling failure message discovery (deriveSiblingMessagePath): Automatically inspects sibling .message fields on failing condition paths.
  3. Status Extraction & Readiness Heuristics (ExtractResourceStatus) (pkg/components/bridge/k8s_status_detector.go):

    • Extracts observed generation, ready conditions, access endpoints, and connection secret names.
    • Evaluates standard conditions or resource phases (Running, Ready, Active).
  4. Daemon Controller Dynamic Wiring (cmd/xmc_bridge/main.go):

    • Initializes discoveryClient and restmapper.NewDeferredDiscoveryRESTMapper.
    • Wires bridge.NewK8sStatusDetector(dynamicClient, mapper) into BridgeProber.
  5. Unit & Dynamic Fake Testing (pkg/components/bridge/k8s_status_detector_test.go):

    • Comprehensive unit tests for GVR resolution, JSONPath query normalization and evaluation, dynamic client fake queries, and missing-CRD fallback.
    • All struct assertions modernized to full cmp.Diff(want, got) comparisons.

Key Contracts & Invariants

  • Separation of Contract from Discovery Engine: Isolates dynamic discovery machinery from controller lifecycle wiring.
  • Fail-Safe Operation: Missing CRDs or absent resources do not trigger error loops or controller crashes.
  • Diff Sizing: Production code is strictly contained to 387 lines ($\le 400$).

Assumptions & Scope Boundary

Verification & Testing

  • bazel test //cmd/xmc_bridge/... //pkg/components/bridge/... passed cleanly.
  • bazel test --@io_bazel_rules_go//go/config:race //pkg/components/bridge:bridge_test //cmd/xmc_bridge:xmc_bridge_test passed (0 race conditions).
  • Pre-commit linters passed (buildifier, gofmt, golangci-lint, addlicense).

TAG=agy
CONV=fa5e1d3a-e399-45eb-a73c-ef8413122857

@gemini-code-assist gemini-code-assist Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new StatusDetector component in pkg/components/bridge to dynamically inspect third-party Kubernetes CRD statuses using a dynamic client and JSONPath evaluation. Feedback highlights a critical issue where the default readiness check and associated test cases utilize JSONPath filter expressions (e.g., [?()]), which are unsupported by k8s.io/client-go/util/jsonpath and will cause runtime parsing errors. It is recommended to programmatically extract the 'Ready' condition to ensure compatibility and robustness.

@VLukiantsev
VLukiantsev force-pushed the feat/components-crd-status-detector-b548435805 branch from 1b05302 to 9d4b7d4 Compare August 24, 2026 17:48
@VLukiantsev
VLukiantsev force-pushed the feat/components-crd-status-detector-b548435805 branch from 88682a7 to 6f2c010 Compare August 25, 2026 15:42
@VLukiantsev
VLukiantsev force-pushed the feat/components-crd-status-detector-b548435805 branch from 6f2c010 to 59d22aa Compare August 25, 2026 16:09
@VLukiantsev
VLukiantsev force-pushed the feat/components-crd-status-detector-b548435805 branch from 59d22aa to 68647e8 Compare August 26, 2026 07:30
@VLukiantsev
VLukiantsev force-pushed the feat/components-crd-status-detector-b548435805 branch 2 times, most recently from 32e6262 to 673ed63 Compare August 26, 2026 08:20
@VLukiantsev
VLukiantsev force-pushed the feat/components-crd-status-detector-b548435805 branch 2 times, most recently from 5f14960 to 5b862b4 Compare August 26, 2026 09:18
@VLukiantsev
VLukiantsev force-pushed the feat/components-crd-status-detector-b548435805 branch from 5b862b4 to 49008e4 Compare August 26, 2026 11:51
@VLukiantsev
Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a dynamic third-party status detector and JSONPath evaluator for XMC components in pkg/components/bridge/. The feedback highlights a potential typed-nil interface panic and performance overhead in EvaluateJSONPath due to repeated JSONPath parsing, missing support for json.Number in extractObservedGeneration, and a redundant client call in DetectStatus.

@VLukiantsev
Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a dynamic third-party status detector in pkg/components/bridge to query Kubernetes custom resources and evaluate their readiness, endpoints, and connection secrets using JSONPath. The review feedback identifies several critical issues: first, jsonpath.JSONPath is not thread-safe, meaning the current caching mechanism will cause data races under concurrent execution; second, ResolveGVR needs to track whether a resource is namespaced to prevent querying cluster-scoped resources within a namespace; and finally, ToBridgeWrapperRef is missing mappings for custom JSONPath configuration fields from the protobuf definition.

@VLukiantsev
VLukiantsev force-pushed the feat/components-crd-status-detector-b548435805 branch from 7f3bc62 to a1f7922 Compare August 26, 2026 13:18 8000
janzak-dev
janzak-dev previously approved these changes Sep 2, 2026
github-actions[bot]
github-actions Bot previously approved these changes Sep 2, 2026
@github-actions github-actions Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤖 Incremental PR Approval

PR author is a code owner and changes since last approval (4 lines) are within the 10-line grace delta.

Preserving prior approval by @janzak-dev on commit 4f52966.

janzak-dev
janzak-dev previously approved these changes Sep 4, 2026
github-actions[bot]
github-actions Bot previously approved these changes Sep 8, 2026
@github-actions github-actions Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤖 Incremental PR Approval

Clean rebase detected with zero semantic patch lines changed.

Preserving prior approval by @janzak-dev on commit e74b2a0.

github-actions[bot]
github-actions Bot previously approved these changes Sep 8, 2026
@github-actions github-actions Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤖 Incremental PR Approval

Clean rebase detected with zero semantic patch lines changed.

Preserving prior approval by @janzak-dev on commit e74b2a0.

github-actions[bot]
github-actions Bot previously approved these changes Sep 8, 2026
@github-actions github-actions Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤖 Incremental PR Approval

Clean rebase detected with zero semantic patch lines changed.

Preserving prior approval by @janzak-dev on commit e74b2a0.

github-actions[bot]
github-actions Bot previously approved these changes Sep 9, 2026
@github-actions github-actions Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤖 Incremental PR Approval

Clean rebase detected with zero semantic patch lines changed.

Preserving prior approval by @janzak-dev on commit e74b2a0.

github-actions[bot]
github-actions Bot previously approved these changes Sep 9, 2026
@github-actions github-actions Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤖 Incremental PR Approval

Clean rebase detected with zero semantic patch lines changed.

Preserving prior approval by @janzak-dev on commit e74b2a0.

…engine

Implement production K8sStatusDetector using client-go dynamic client and
deferred discovery RESTMapper. Adds automatic GroupVersionResource (GVR)
resolution, normalized JSONPath query evaluation, status condition
heuristics, and resilient missing-CRD handling.

TAG=agy
…r handling, candidates, and test fixtures

TAG=agy
@github-actions github-actions Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🤖 Incremental PR Approval

Clean rebase detected with zero semantic patch lines changed.

Preserving prior approval by @janzak-dev on commit e74b2a0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority::2-high top of mind. should not wait.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0