fix(clusterapi): cache kind version discovery across loop iterations #10441
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.45) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 421 lines diff across 5 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.362
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #10441"
general
weight: 0.35
elmiko
Why
On large clusters the Cluster API provider can stall its main loop until the liveness probe restarts it. Since CAPI v1beta2, an infrastructureRef carries
apiGroupinstead ofapiVersion, so the provider resolves the kind version through live discovery. The main loop rebuilds every scalable resource wrapper on each iteration, so each node group issues a full discovery round (ServerGroups plus ServerResourcesForGroupVersion) on every loop. With the default discovery rate limits (QPS 5, burst 10) this throttles the client once a cluster has enough node groups. On a cluster with 50 node groups that is 100 discovery calls every loop, a forced wait of roughly 20 seconds per iteration, which can push loop duration past the liveness deadline (15 minutes in the reported incident). After this change a process issues 2 discovery calls in total for its lifetime, one round to warm the cache, and none afterwards.What changed
machineControllercaches successful kind version resolutions per(apiGroup, kind)for its lifetime, inkindPreferredVersion.readInfrastructureReferenceResourceresolves versions through that cache instead of the raw discovery client.Scope
Tradeoffs
memory.NewMemCacheClientintonewMachineControllerinstead. Rejected because that client also caches failures and missing groups, which would stop a provider installed after startup from resolving without a restart. This cache stores successes only, so failed lookups retry on the next loop, same as before.Blast Radius
Verification
TestReadInfrastructureReferenceResourceCachesDiscoveryfails on master with 4 discovery actions for two wrapper rebuilds and passes with 2 after the fix.TestReadInfrastructureReferenceResourceScalesWithoutExtraDiscoveryreproduces the incident shape with 50 node groups across 2 loop iterations. It fails on master with 200 discovery actions (100 wrapper rebuilds, one round each) and passes with 2 after the fix.go test ./cloudprovider/clusterapi/... -count=1passes.<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
Performance
Repeated API version lookups for infrastructure references are reused, reducing redundant discovery work when processing machines that share a resource type.
Previously discovered resource types continue to be reused across repeated scans, including when processing larger groups of machines.
Reliability
Unsuccessful lookups are not reused, allowing later attempts to retry discovery.
Cached results expire after one minute, after which discovery can refresh them.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->