Skip to content

Extract the skipped NG simulation into a dedicated processor running in a separate goroutine - #292

Open
shaikenov wants to merge 5 commits into
kubernetes-sigs:mainfrom
shaikenov:skipped-ngs-async-oss
Open

shaikenov wants to merge 5 commits into
kubernetes-sigs:mainfrom
shaikenov:skipped-ngs-async-oss

Conversation

@shaikenov

@shaikenov shaikenov commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

What type of PR is this?

/kind bug

What this PR does / why we need it:

Extract the skipped NG simulation into a separate processor which will be run in a separate goroutine unblocking the CA critical scale up path.

As of now skipped NG simulation (ref: kubernetes/autoscaler#9346) is run in the scale up orchestrator as a part of general scale up simulation which has big impact on the scale up time and the overall CA loop performance.

Which issue(s) this PR fixes:

Addresses #289

Special notes for your reviewer:

I tried to structure the chain in the following way so it is easier to review:

  1. Remove synchronous skipped NG simulation from ScaleUpOrchestrator -
    Returns ScaleUpOrchestrator to its pre-feature behavior so skipped node group predicate checks never block the main scale-up loop.

  2. Add background Evaluator for skipped node group predicate checks -
    Introduces the background worker goroutine with its own dedicated framework.Handle (distinct scheduler profile name on the shared informer factory) and a 1-node PredicateSnapshot so each skipped node group is evaluated in isolation off the main loop. This starts with the simplest model: every job evaluates all current (pod group, skipped NG) pairs and publishes verdicts as a whole, keyed by (pod UID, node group ID), with rate limiting (PairsPerSecond) and inter-pod affinity stripped.

  3. Add async ScaleUpStatusProcessor and wire it in AutoscalerBuilder -
    Wires ScaleUpStatusProcessor into the scale-up status processing chain (after proactive-scaleup's pod-injection filter and before CapacityBuffer's fake-pod processor) and starts Evaluator.Run after cache sync. On each loop, Process resolves templates from TemplateNodeInfoRegistry (no synchronous cloud-provider fallback), bounds work by MaxPairsPerLoop, looks up the latest verdicts, schedules the current pairs, and moves incompatible skipped node groups to RejectedNodeGroups (leaving unknown pairs conservatively in SkippedNodeGroups).

  4. Cache (pod, skipped NG) verdicts across loops -
    Makes evaluation incremental with a TTL-backed verdictCache (DefaultVerdictTTL = 30m), periodic/between-job expiry sweeps with map compaction, and clustersnapshot.WithoutPod so cached SchedulingErrors do not pin deep-copied exemplar pods in memory. Only unknown or expired pairs are handed to the worker, and pairs that became freshly cached while queued are skipped.

  5. Merge pending jobs instead of replacing them -
    Multiple ScaleUpStatuses can be processed per loop (e.g. across scale-up salvo iterations or async node group initializers) with different pod sets. Instead of overwriting pending, incoming jobs are merged behind any existing pending job in FIFO order (deduplicated by (pod UID, node group ID) and bounded by MaxPairsPerLoop), while the currently running job finishes to completion before the worker drains the merged pending job.

Open points:

  1. Key cached verdicts by pod group signature: key the verdict cache by pod group instead of pod UID. Cache size then follows the number of pod groups, verdicts survive pod churn (e.g. Jobs recreating pods), and spec changes are picked up right away.
  2. Skip DRA pods: leave pods using ResourceClaims or DRA-backed extended resources as skipped, because the evaluator's DRA-less snapshot would wrongly reject them. Until this lands, the first PR can misreport DRA pods when DRA is enabled.
  3. Support CSINode-aware scheduling: pass CSINodeAwareSchedulingEnabled to the evaluator so volume-limit and CSI predicates match the main simulation.
  4. Add Prometheus metrics: add a job duration label, an evaluated-pairs counter, a cache-entries gauge, and a hit/miss lookup counter.
  5. Need to add a possibility to control the additional knobs that control the simulation time - DefaultMaxPairsPerLoop and DefaultPairsPerSecond - via CLI flags preferrably.

All of these will be addressed in the follow ups.

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@kubernetes-prow kubernetes-prow Bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/bug Categorizes issue or PR as related to a bug. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Nov 23, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

This issue is currently awaiting triage.

If SIG Autoscaling contributors determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@kubernetes-prow kubernetes-prow Bot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Nov 23, 2026
@shaikenov
shaikenov force-pushed the skipped-ngs-async-oss branch 3 times, most recently from 97188dd to bb0b698 Compare December 1, 2026 16:20
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: shaikenov
Once this PR has been reviewed and has the lgtm label, please assign omerap12 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@shaikenov
shaikenov force-pushed the skipped-ngs-async-oss branch from bb0b698 to d24246a Compare December 2, 2026 13:21
@kubernetes-prow kubernetes-prow Bot added release-note-none Denotes a PR that doesn't merit a release note. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Dec 2, 2026
…rator

Removes getRemainingPodsConsideringSkippedNodeGroups and
findSkippedNodeGroupsSatisfyingPodPredicates from ScaleUpOrchestrator so
that skipped node group predicate checks do not block the main scale-up loop.

GetRemainingPods now only takes the pod groups and the skipped node groups,
and every remaining pod is reported with the full set of skipped node
groups. TestScaleUpSimulationForSkippedNodeGroups is removed with it.

With this commit alone ScaleUpSimulationForSkippedNodeGroupsEnabled has no
effect; the next two commits re-add the attribution asynchronously with a
background Evaluator and ScaleUpStatusProcessor.
Adds Evaluator and NewEvaluatorFrameworkHandle in pkg/processors/skippednodegroups: a background goroutine with its own scheduler framework.Handle and a 1-node PredicateSnapshot, so that skipped node group predicate checks never run on the main loop.

Key details:
- Each job evaluates all current (pod group, skipped node group) pairs on a private 1-node snapshot and publishes verdicts as a whole, keyed by (pod UID, node group id).
- NewEvaluatorFrameworkHandle builds a dedicated framework handle on the shared informer factory with a distinct profile name so plugins never share DelegatingLister or collide on informer indexers.
- PairsPerSecond (20k by default) throttles the worker, and inter-pod affinity is stripped from the evaluated pod copy since it cannot be evaluated against a lone template node.
- ScaleUpStatusProcessor and AutoscalerBuilder wiring are added in the next commit; incremental caching and job merging follow in subsequent commits.
Adds ScaleUpStatusProcessor in pkg/processors/skippednodegroups and wires it with Evaluator in AutoscalerBuilder.

On each scale-up loop, Process gathers skipped node group templates from TemplateNodeInfoRegistry, groups unschedulable pods into equivalence groups bounded by MaxPairsPerLoop (200k by default), looks up the Evaluator's latest verdicts, schedules the current pairs for background evaluation, and moves incompatible skipped node groups to RejectedNodeGroups while keeping pairs without a verdict yet in SkippedNodeGroups.

Key wiring and safety details:
- Composed before CapacityBuffer's FakePodsScaleUpStatusProcessor and after ProactiveScaleup's podinjection filter so CapacityBuffer events keep attributed reasons while injected pods are filtered out beforehand.
- Evaluator.Run starts only after AutoscalerBuilder finishes cache sync.
- TemplateNodeInfoRegistry misses do not fall back to cloud-provider ng.TemplateNodeInfo calls on the main loop.
- scaleUp:skippedNodeGroupsSimulation now measures the processor's work on the main loop instead of the synchronous predicate checks.

Known limitations of this version:
- When several statuses are processed per loop with different pods (e.g. one per scale-up salvo iteration), a pending job is replaced by the newer one and every finished job replaces all published verdicts, so verdicts of pods that only appear in an earlier status of the loop can be lost. Fixed by the follow-up commits that cache verdicts and merge jobs.
- DRA and CSINode-aware scheduling are not enabled on the evaluator, so pods using DRA can be attributed incorrectly and CSI volume limits are not checked. Both are handled in a follow-up change.
Makes the async skipped node groups Evaluator incremental: verdicts are kept
in a dedicated verdictCache (verdict.go) across loops and the worker only
evaluates (pod group, skipped node group) pairs that are not cached yet,
instead of re-evaluating every pair on every loop.

- Lookup: the main loop resolves each pair from the cache and hands only
  unknown pairs (never evaluated, or expired) to the worker. Lookups are
  read-only.
- Keys: (pod UID, node group id). A group's verdict is the cached verdict of
  any of its pods, so new replicas of a known group are served right away.
- Expiry: every verdict is dropped after VerdictTTL (30 minutes by default)
  and evaluated again on the next loop that asks for it, so changes the key
  does not capture (node group template updates, informer-backed predicate
  inputs such as PVC/PV binding state) are picked up within the TTL. Until
  then a verdict can be stale, and an expired verdict is unknown (the node
  group is left skipped) until it has been evaluated again. VerdictTTL <= 0
  disables expiry.
- Worker: skips pairs that became freshly cached while queued and stores
  each pod-free verdict as soon as it is computed, instead of publishing a
  whole job at once. A newer job still replaces a pending one, but the
  replaced pairs stay unknown and are requested again by the next loop.
- Memory bounds: expired verdicts are swept (both periodically in Run and
  between jobs in ProcessPendingNow). The sweep is what drops verdicts of
  pods that are gone or of node groups that are no longer skipped, since
  nothing looks those up again. Shrinking far below peak triggers map
  compaction.
- clustersnapshot: adds WithoutPod, which copies a SchedulingError without
  the pod it was created for, and lets schedulingError.Error() handle a nil
  pod, so cached verdicts neither pin deep-copied exemplar pods in memory
  nor name them in Error().

Known limitations of this version:
- A newer job replaces the pending one, so when several statuses are
  processed per loop (e.g. one per scale-up salvo iteration), pairs that
  only appear in an earlier status can keep being replaced while the worker
  is busy. Fixed by the follow-up that merges jobs.
- Verdicts are keyed by pod UID. A follow-up change keys them by pod group
  signature, which fixes:
  - cache size and main-loop lookups scale with pending pods x skipped node
    groups rather than pod groups;
  - a group's verdict is lost once every pod it was stored for is gone,
    e.g. for Jobs that keep recreating pods;
  - mutable scheduling fields (e.g. added tolerations) are only picked up
    once the verdict expires.
Several statuses can be processed per loop (e.g. one per scale-up salvo
iteration) with different pods. While a newer job replaced the pending one,
pairs that only appear in an earlier status could keep being replaced while
the worker was busy, so jobs are now merged.

- Hand-off: a new job is merged behind any existing pending job in FIFO order
  (deduplicated by (pod UID, node group id), bounded by MaxPairsPerLoop)
  under e.mu instead of replacing it. Templates are merged by node group,
  keeping the existing pending job's template NodeInfo. Pairs cut off by
  MaxPairsPerLoop stay unknown and are requested again by the next loop.
- Worker: finishes the currently running job to completion before picking up
  the next pending job, and logs enqueued/finished job counts and cache size.
- Tests: merging pending jobs, overlapping salvo statuses, and MaxPairsPerLoop
  bounding on merged jobs.
@shaikenov
shaikenov force-pushed the skipped-ngs-async-oss branch from d24246a to b94ca3a Compare December 4, 2026 11:59
@kubernetes-prow kubernetes-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 4, 2026
@shaikenov
shaikenov marked this pull request as ready for review December 4, 2026 12:00
@kubernetes-prow kubernetes-prow Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 4, 2026
@kubernetes-prow
kubernetes-prow Bot requested review from Choraden and damikag December 4, 2026 12:00
@shaikenov

Copy link
Copy Markdown
Member Author

Apologies for the huge diff here :(

I tried to limit the change as much as possible, but to extensively cover the basic scenario. Tried to have the change splitted in isolated commits, so it is easier to review - hope it helps :).

There is a list of open points that are not covered in this PR, but will be covered in the follow up (such as better caching for pod group signatures, CSI/DRA nodes, metrics, etc - PTAL at the description).

/assign @mtrqq

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants