8000 feat(components): extract SSA status applier and 3P contract breach handling by VLukiantsev · Pull Request #1104 · google/xmc · GitHub
[go: up one dir, main page]

Skip to content

feat(components): extract SSA status applier and 3P contract breach handling - #1104

Merged
VLukiantsev merged 12 commits into
mainfrom
feat/components-envtest-admission-suite-b548436001
Oct 8, 2026
Merged

VLukiantsev merged 12 commits into
mainfrom
feat/components-envtest-admission-suite-b548436001

Conversation

@VLukiantsev
@VLukiantsev VLukiantsev commented Oct 6, 2026 •
Copy link
Copy Markdown
Collaborator

Summary

Extracts Kubernetes Server-Side Apply (fieldManager: "xmc-bridge") status persistence and conflict-resilient finalizer synchronization into pkg/components/bridge/status_applier.go, wires it into cmd/xmc_bridge/main.go, and introduces ReasonContractBroken / ErrContractBreach handling for malformed 3P wrapper status payloads with full unit test coverage.

Key Changes

  • Server-Side Apply (fieldManager: "xmc-bridge") & Finalizer Sync (pkg/components/bridge/status_applier.go, cmd/xmc_bridge/main.go):
    • Exported ApplyComponentStatusSSA, SyncComponentFinalizers, BuildStatus, BuildStatusMap, ComponentGVR, and FieldManagerBridge in pkg/components/bridge and delegated from cmd/xmc_bridge/main.go.
    • Hardened SyncComponentFinalizers with input DeepCopy(), retry.RetryOnConflict, and immediate error propagation if Get fails during conflict recovery.
    • Added dedicated unit tests in pkg/components/bridge/status_applier_test.go.
  • 3P Contract Breach Handling (pkg/components/bridge/conditions.go, k8s_status_detector.go, wrapper_reconciler.go):
    • Added ReasonContractBroken = "ContractBroken" and ErrContractBreach when 3P .status or .status.conditions payloads are structurally malformed or fail JSONPath evaluation, setting Degraded=True, Ready=False, Reason=ContractBroken while preserving ReasonStatusDetectionFailed for K8s API/transport errors.

Assumptions & Design Decisions

  • Vertical Stack (Layer 1 of 2): This PR lands the production status_applier.go and 3P contract breach handling along with fast unit tests (status_applier_test.go, k8s_status_detector_test.go, cmd/xmc_bridge/main_test.go). The hermetic controller-runtime/pkg/envtest integration suite (test/integration/components_admission_test.go and pkg/components/bridge/reconciler_test.go) is stacked directly on top in the follow-up PR.

Verification

bazel test //pkg/components/bridge/... //cmd/xmc_bridge/...

Fixes: b/548436001
TAG=agy

…gration suite

Add hermetic controller-runtime envtest integration suites for Component
CRD admission (test/integration/components_admission_test.go) and bridge
reconciliation (pkg/components/bridge/reconciler_test.go):
- Provision kubebuilder envtest (v1.30.3 etcd and kube-apiserver) via
  standard http_archive in MODULE.bazel with KUBEBUILDER_ASSETS fallback.
- Export ApplyComponentStatusSSA (fieldManager: "xmc-bridge") and
  SyncComponentFinalizers in pkg/components/bridge and reuse from
  cmd/xmc_bridge.
- Add ReasonContractBroken ("ContractBroken") and ErrContractBreach for
  malformed 3P status payloads and JSONPath evaluation breaches.
- Test CEL schema validations, ValidatingAdmissionPolicy DELETE rejection
  when deletionProtection=true (and breakglass/false paths), SSA status
  condition merging, and malformed 3P status handling.

Fixes bug 548436001

TAG=agy
CONV=12b1d67e-1270-4c7e-92d3-97f70afc7ce5
@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 refactors the xmc_bridge controller by extracting status application and finalizer synchronization logic into a dedicated status_applier.go file in the bridge package. It also introduces robust validation for third-party status payloads, raising a contract breach error (ErrContractBreach) when malformed payloads are encountered, and adds comprehensive integration tests using envtest to verify admission policies, CEL validations, and controller behavior. Feedback on these changes suggests improving SyncComponentFinalizers by adding a nil check for the dynamic client and using a JSON Merge Patch instead of a full update to prevent optimistic locking conflicts in concurrent environments.

Comment thread pkg/components/bridge/status_applier.go Resolved
@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 refactors the xmc_bridge controller by extracting status serialization, Server-Side Apply (SSA), and finalizer synchronization logic into a new status_applier.go file within the bridge package. It also introduces robust validation for third-party status payloads, returning a contract breach error (ErrContractBreach) when payloads are malformed, and adds comprehensive integration tests using kubebuilder_envtest. Feedback on these changes highlights a potential nil pointer dereference in SyncComponentFinalizers due to a missing check on the client parameter, as well as hardcoded fallback paths for kubebuilder-envtest assets that will cause test failures on non-Linux or non-amd64 development environments.

Comment thread pkg/components/bridge/status_applier.go Resolved
…nentFinalizers

Add a nil dynamic client guard to SyncComponentFinalizers and wrap
finalizer Update operations in retry.RetryOnConflict so concurrent
resource updates do not cause optimistic concurrency failures while
preserving resourceVersion safety.

Comment link: #1104 (comment)

TAG=agy
CONV=12b1d67e-1270-4c7e-92d3-97f70afc7ce5
@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 refactors the xmc_bridge controller by moving status and finalizer synchronization logic into the bridge package, introducing robust contract breach handling for malformed third-party status payloads, and adding comprehensive integration tests using envtest. Feedback on these changes highlights two issues: first, in SyncComponentFinalizers, a failed Get call during a conflict retry can lead to a silent failure where finalizer updates are not persisted; second, the waitForVAPActivation integration test helper could spin indefinitely on 'not found' errors if canary recreation fails during polling.

Comment thread pkg/components/bridge/status_applier.go Resolved
…h for envtest fallback

- Return Get errors immediately during retry.RetryOnConflict in
  SyncComponentFinalizers to prevent silent no-op retries on mutated
  in-memory items.
- Recreate the VAP readiness canary if Delete returns NotFound and
  propagate Create errors in waitForVAPActivation.
- Construct local kubebuilder-envtest fallback paths dynamically via
  runtime.GOOS and runtime.GOARCH.

Comment link: #1104 (comment)

TAG=agy
CONV=12b1d67e-1270-4c7e-92d3-97f70afc7ce5
@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 refactors the xmc_bridge controller by extracting status application and finalizer synchronization logic into a dedicated status_applier.go file. It also introduces a contract breach mechanism (ErrContractBreach) to handle malformed third-party status payloads and adds comprehensive integration tests using Kubebuilder's envtest. The review feedback highlights several improvement opportunities: adding a nil check for updated in ApplyComponentStatusSSA to prevent panics, swapping checks in SyncComponentFinalizers to return early, using unstructured.NestedSlice to robustly parse conditions, and ignoring 'already exists' errors during integration test polling to prevent flakiness.

Comment thread pkg/components/bridge/status_applier.go Resolved
Comment thread pkg/components/bridge/status_applier.go Resolved
@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 refactors the status and finalizer synchronization logic of the xmc_bridge controller by extracting it into a dedicated status_applier.go helper. It also introduces validation for third-party status payloads to handle contract breaches (ErrContractBreach) and adds integration tests using Kubebuilder envtest. Feedback on these changes highlights that mutating the item parameter in-place within SyncComponentFinalizers can cause inconsistent states during retries, and recommends deep-copying it first. Additionally, the helper functions for locating envtest binaries in reconciler_test.go and components_admission_test.go should be optimized to avoid walking the entire TEST_SRCDIR in large Bazel workspaces.

Comment thread pkg/components/bridge/status_applier.go Resolved
@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 refactors the xmc-bridge controller by extracting status application and finalizer synchronization logic into a dedicated status_applier.go helper, while introducing robust validation for third-party status payloads to handle contract breaches. Additionally, it integrates local envtest execution for both unit and admission policy integration tests. The review feedback suggests optimizing status serialization in ApplyComponentStatusSSA by passing the typed status struct directly to avoid reflection overhead, and increasing the aggressive ControlPlaneStopTimeout in the test environments to prevent flaky test failures in CI.

Comment thread pkg/components/bridge/status_applier.go Resolved
@VLukiantsev
VLukiantsev marked this pull request as ready for review October 7, 2026 08:43
@github-actions
github-actions Bot requested a review from andrzejfudro October 7, 2026 08:43
@VLukiantsev
VLukiantsev requested review from janzak-dev and removed request for andrzejfudro October 7, 2026 08:44
@VLukiantsev
VLukiantsev marked this pull request as draft October 7, 2026 08:47
@VLukiantsev
VLukiantsev removed the request for review from janzak-dev October 7, 2026 08:47
@VLukiantsev VLukiantsev changed the title feat(components): implement controller envtest and CRD admission integration suite feat(components): extract SSA status applier and 3P contract breach handling Oct 7, 2026
@VLukiantsev
VLukiantsev added this pull request to stack #1119 October 7, 2026 09:03
…ing in README

TAG=agy
CONV=12b1d67e-1270-4c7e-92d3-97f70afc7ce5
@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 refactors the status application and finalizer synchronization logic of the xmc-bridge controller by moving it from cmd/xmc_bridge/main.go to a new helper file pkg/components/bridge/status_applier.go, accompanied by comprehensive unit tests. It also introduces structural contract validation for third-party status payloads in k8s_status_detector.go, returning a new ErrContractBreach error when the payload is malformed. This error is handled in wrapper_reconciler.go to transition the component to a degraded state with the reason ContractBroken. Additionally, test sizes are explicitly set to "small" in Bazel build files, and unused dependencies are cleaned up. As there are no review comments provided, I have no feedback to evaluate.

@VLukiantsev
VLukiantsev marked this pull request as ready for review October 7, 2026 11:04
@github-actions
github-actions Bot requested a review from pachopepe October 7, 2026 11:04
@VLukiantsev VLukiantsev added the priority::2-high top of mind. should not wait. label Oct 7, 2026
Comment thread pkg/components/bridge/status_applier.go Resolved
Comment thread pkg/components/bridge/README.md Resolved
…use internal/logging

TAG=agy
CONV=12b1d67e-1270-4c7e-92d3-97f70afc7ce5
@VLukiantsev
VLukiantsev requested a review from pachopepe October 7, 2026 14:05
@VLukiantsev
VLukiantsev added this pull request to the merge queue Oct 8, 2026
Merged via the queue into main with commit b797cc2 Oct 8, 2026
11 checks passed
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