← Back to Pull requests

fix(registration): propagate dynamic CRD schema updates via parent.Reconcilers #15034

Closed
unknown closed this pull request without merging on Nov 06, 2026 18:50 UTC
View on GitHub
unknown unknown commented on Nov 05, 2026 18:59 UTC
Author

Description

Internal tracking bug: b/535980652
Alternative to PR #14882 addressing architecture and correctness concerns.

Background


When registerDefaultController in pkg/controller/registration/registration_controller.go was refactored in commit 8c120597897bc8db9a8c0c78c422d6f181e5fcb2 to delegate controller dispatching to parent.Add(...), var schemaUpdater k8s.SchemaReferenceUpdater was left unassigned, returning (nil, nil).
Because schemaUpdater was always nil, ReconcileRegistration.Reconcile skipped calling UpdateSchema(crd) whenever a CRD was updated while cnrm-controller-manager remained running. For Terraform- and DCL-backed resources (such as ComputeRouterNAT), 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 schemaUpdater as a mutable variable in registerDefaultController's loop (which risks overwriting if multiple reconcilers are supported), implemented k8s.SchemaReferenceUpdater directly on *parent.Reconcilers.
- Reconcilers.UpdateSchema safely broadcasts the update to any active child reconcilers (r.TF and r.DCL) using errors.Join, without overwriting or dropping updates.
2. Clean Registration Wiring:
- registerDefaultController returns reconcilers, nil when TF or DCL is present, and nil, nil for Direct-only or IAM resources.
- Extracted constructor newReconcileRegistration in registration_controller.go to properly encapsulate collaborator initialization.
- Added thread-safe controllerContextFor(gvk) accessor on ReconcileRegistration to avoid white-box access to private state.
- Updated ReconcileRegistration.Reconcile to log and return errors if UpdateSchema(crd) fails so controller-runtime can requeue with backoff rather than silently swallowing failures.
3. Unit Tests (AAA & Stepdown Rule):
- Added TestReconcilers_UpdateSchema_NilReconcilers in pkg/controller/parent/controller_test.go.
- Added unified table-driven test TestReconcileRegistration_DynamicSchemaUpdate in pkg/controller/registration/registration_controller_test.go covering Terraform (ComputeRouterNAT), DCL (ComputeFirewallPolicy), and Direct-only (ComputeFirewallPolicyRule) controllers.
- Structured all tests in visually separated Arrange, Act, Assert blocks.
- Ensured proper sync.Once error propagation and ResourceVersion handling.

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

Diff: 358 lines (+268 / -90) across 4 files Reviewer: sdowell Review duration: 1430m
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
0.43
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
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.352
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #15034"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% 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: 42.6% (MEDIUM) · Higher = larger blast radius
42.6%
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: 60.5% · Lower = rushed or shallow review
60.5%
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: 16.8% · Safe to merge
16.8%