fix(registration): propagate dynamic CRD schema updates via parent.Reconcilers #15034
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 358 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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.352
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #15034"
general
weight: 0.35
sdowell
Description
Internal tracking bug: b/535980652
Alternative to PR #14882 addressing architecture and correctness concerns.
Background
When
registerDefaultControllerinpkg/controller/registration/registration_controller.gowas refactored in commit8c120597897bc8db9a8c0c78c422d6f181e5fcb2to delegate controller dispatching toparent.Add(...),var schemaUpdater k8s.SchemaReferenceUpdaterwas left unassigned, returning(nil, nil).Because
schemaUpdaterwas alwaysnil,ReconcileRegistration.Reconcileskipped callingUpdateSchema(crd)whenever a CRD was updated whilecnrm-controller-managerremained running. For Terraform- and DCL-backed resources (such asComputeRouterNAT), newly introduced CRD schema fields returned by GCP caused reconciliation to fail with"field not declared in schema"/"field not found in schema"until pods were restarted.Changes in this PR
1. Architectural Fix via
parent.Reconcilers:- Instead of tracking
schemaUpdateras a mutable variable inregisterDefaultController's loop (which risks overwriting if multiple reconcilers are supported), implementedk8s.SchemaReferenceUpdaterdirectly on*parent.Reconcilers.-
Reconcilers.UpdateSchemasafely broadcasts the update to any active child reconcilers (r.TFandr.DCL) usingerrors.Join, without overwriting or dropping updates.2. Clean Registration Wiring:
-
registerDefaultControllerreturnsreconcilers, nilwhen TF or DCL is present, andnil, nilfor Direct-only or IAM resources.- Extracted constructor
newReconcileRegistrationinregistration_controller.goto properly encapsulate collaborator initialization.- Added thread-safe
controllerContextFor(gvk)accessor onReconcileRegistrationto avoid white-box access to private state.- Updated
ReconcileRegistration.Reconcileto log and return errors ifUpdateSchema(crd)fails so controller-runtime can requeue with backoff rather than silently swallowing failures.3. Unit Tests (AAA & Stepdown Rule):
- Added
TestReconcilers_UpdateSchema_NilReconcilersinpkg/controller/parent/controller_test.go.- Added unified table-driven test
TestReconcileRegistration_DynamicSchemaUpdateinpkg/controller/registration/registration_controller_test.gocovering Terraform (ComputeRouterNAT), DCL (ComputeFirewallPolicy), and Direct-only (ComputeFirewallPolicyRule) controllers.- Structured all tests in visually separated Arrange, Act, Assert blocks.
- Ensured proper
sync.Onceerror propagation andResourceVersionhandling.Does this PR add something which needs to be 'release noted'?
``
release-note
``Fixed an issue where dynamic CRD schema updates were not propagated to running Terraform- and DCL-backed resource controllers until cnrm-controller-manager pods were restarted.