← Back to Pull requests

cluster-autoscaler: pass context down RunOnce loop #9887

Closed
unknown closed this pull request without merging on Jul 14, 2026 07:56 UTC
View on GitHub
unknown unknown commented on Jun 28, 2026 19:29 UTC
Author

What type of PR is this?


/kind cleanup

What this PR does

Autoscaler.RunOnce did not accept a context.Context so a graceful termination signal could not interrupt a long-running autoscaling iteration. In large clusters, a single RunOnce call can take longer than the graceful termination period leading to the process being killed without cleaning up properly

This PR threads context.Context through RunOnce and loop.RunAutoscalerOnce and adds cancellation checks in
StaticAutoscaler.RunOnce - one at the start of the iteration and one right before the scale-up/scale-down section ( the most expensive part of the loop ).
When the context is cancelled RunOnce returns early and cleanly without registering an error since this isn't a failure
it's intentional , graceful stop

See https://github.com/kubernetes/autoscaler/issues/9855

Special notes for your reviewer :

  • Only StaticAutoscaler implements the Autoscaler interface and loop/run.go + main.go are the only non-test callers so the blast radius is contained to those plus test call sites

  • Added TestStaticAutoscalerRunOnceWithCancelledContext to verify RunOnce returns cleanly (no error) when the context is already cancelled

  • main.go 's ctx.Done() branches in the main loop already exist

  • this change means the context is now also honored during an in-progress iteration not just between iterations.
    Updated the stale TODO comments there accordingly

    ``release-note
    Pass context.Context down to Autoscaler.RunOnce to allow graceful shutdown to interrupt long-running autoscaling iterations.
    ``

    Diff: 209 lines (+156 / -53) across 2 files Reviewer: yashrajshuklaaa Review duration: 22347m
    All Vouch review confidence checks passed
    Residual risk 0.14 = Change Risk (0.36) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.36 · 209 lines diff across 2 files
    0.36
    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.320
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #9887"
    general weight: 0.35
    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: 36.4% (MEDIUM) · Higher = larger blast radius
    36.4%
    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: 14.4% · Safe to merge
    14.4%