Repository navigation
feat(components): extract SSA status applier and 3P contract breach handling - #1104
Conversation
…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
|
/gemini review |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
…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
|
/gemini review |
There was a problem hiding this comment.
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.
…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
|
/gemini review |
There was a problem hiding this comment.
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.
|
/gemini review |
There was a problem hiding this comment.
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.
…ected envtest runfile paths
|
/gemini review |
There was a problem hiding this comment.
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.
…envtest stop timeout
…st-admission-suite-b548436001 # Conflicts: # pkg/components/bridge/BUILD.bazel
…ing in README TAG=agy CONV=12b1d67e-1270-4c7e-92d3-97f70afc7ce5
…st-admission-suite-b548436001
|
/gemini review |
There was a problem hiding this comment.
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.
…use internal/logging TAG=agy CONV=12b1d67e-1270-4c7e-92d3-97f70afc7ce5
Summary
Extracts Kubernetes Server-Side Apply (
fieldManager: "xmc-bridge") status persistence and conflict-resilient finalizer synchronization intopkg/components/bridge/status_applier.go, wires it intocmd/xmc_bridge/main.go, and introducesReasonContractBroken/ErrContractBreachhandling for malformed 3P wrapper status payloads with full unit test coverage.Key Changes
fieldManager: "xmc-bridge") & Finalizer Sync (pkg/components/bridge/status_applier.go,cmd/xmc_bridge/main.go):ApplyComponentStatusSSA,SyncComponentFinalizers,BuildStatus,BuildStatusMap,ComponentGVR, andFieldManagerBridgeinpkg/components/bridgeand delegated fromcmd/xmc_bridge/main.go.SyncComponentFinalizerswith inputDeepCopy(),retry.RetryOnConflict, and immediate error propagation ifGetfails during conflict recovery.pkg/components/bridge/status_applier_test.go.pkg/components/bridge/conditions.go,k8s_status_detector.go,wrapper_reconciler.go):ReasonContractBroken = "ContractBroken"andErrContractBreachwhen 3P.statusor.status.conditionspayloads are structurally malformed or fail JSONPath evaluation, settingDegraded=True, Ready=False, Reason=ContractBrokenwhile preservingReasonStatusDetectionFailedfor K8s API/transport errors.Assumptions & Design Decisions
status_applier.goand 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 hermeticcontroller-runtime/pkg/envtestintegration suite (test/integration/components_admission_test.goandpkg/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