← Back to Pull requests

fix(clusterapi): cache kind version discovery across loop iterations #10441

Closed
unknown closed this pull request without merging on Oct 28, 2026 14:23 UTC
View on GitHub
unknown unknown commented on Oct 19, 2026 01:39 UTC
Author

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 apiGroup instead of apiVersion, 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

  • machineController caches successful kind version resolutions per (apiGroup, kind) for its lifetime, in kindPreferredVersion.

  • readInfrastructureReferenceResource resolves versions through that cache instead of the raw discovery client.
  • Scope

  • Covers the per-loop discovery amplification for infrastructure references.

  • Leaves the scale client and the controller startup lookups unchanged. The scale kind resolver already caches per resource, and the startup lookups run once.
  • Tradeoffs

  • A cached resolution never refreshes until restart. API groups rarely change the version that serves a kind at runtime, and the controller already pins its GVRs at startup, so this matches existing behavior.

  • Considered passing the existing memory.NewMemCacheClient into newMachineController instead. 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

  • Only the Cluster API provider. Resolution results and error behavior for missing groups or kinds are unchanged.
  • Verification

  • New test TestReadInfrastructureReferenceResourceCachesDiscovery fails on master with 4 discovery actions for two wrapper rebuilds and passes with 2 after the fix.

  • New test TestReadInfrastructureReferenceResourceScalesWithoutExtraDiscovery reproduces 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=1 passes.
  • <!-- 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 -->

    Diff: 421 lines (+315 / -106) across 5 files Reviewer: elmiko Review duration: 13724m
    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
    0.45
    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%
    56%
    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.362
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #10441"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% 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: 45% (MEDIUM) · Higher = larger blast radius
    45%
    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: 56.8% · Lower = rushed or shallow review
    56.8%
    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: 19.5% · Safe to merge
    19.5%