← Back to Pull requests

feat(scheduler): honor preferred nodeAffinity in node score #3298

Closed
unknown closed this pull request without merging on Oct 29, 2026 17:10 UTC
View on GitHub
unknown unknown commented on Oct 25, 2026 12:45 UTC
Author

What type of PR is this?

/kind feature

What this PR does / why we need it:

HAMi pick one node inside Filter, so kube-scheduler score plugins (like NodeAffinity) can not change the result.
When pod has preferredDuringSchedulingIgnoredDuringExecution, HAMi just ignore it and only use GPU score.
In my cluster the pod go to node B even node A was preferred with weight 100 (see issue).

This PR add a small bonus to HAMi node score for the node that match pod preferred nodeAffinity.

  • new flag --node-affinity-score-weight (W), default 0 = off, so nothing change after upgrade

  • r = matched term weight / total term weight (0 ~ 1), bonus = W r

  • binpack: score + bonus, spread: score - bonus, so preferred node always win on both policy

  • matching use k8s.io/component-helpers/scheduling/corev1/nodeaffinity, same as kube-scheduler

  • terms are parsed one time per pod in calcScoreWithOptions, then every node only do label match

  • bonus is added after OverrideScore, Filter and Bind flow is not changed

  • chart: scheduler.defaultSchedulerPolicy.nodeAffinityScoreWeight, README table regenerated with helm-docs
  • Pod without preferred affinity is same as before. If W is 0 the code path is skipped totally.

    Which issue(s) this PR fixes:
    Fixes #3062

    Special notes for your reviewer:

  • k8s.io/component-helpers is pinned to v0.37.1, same minor as other k8s.io modules, like you asked.

  • Flag help text say other kube score plugins are still ignored (only preferred nodeAffinity is covered).

  • If the affinity term is invalid (bad operator etc), I log warning and skip the bonus. Pod is not rejected. Tell me if you want fail-close instead.

  • About size: GPU score is 0 ~ 30, so W > 30 make affinity win. Topology score is x10000, so W under 10000 keep topology > affinity > GPU usage. I did not add a hard limit on W, just document it.

  • NodeScore.Node can be nil, in that case no bonus.

  • Tests:

  • - pkg/scheduler/policy/node_affinity_test.go: unit test for parse + bonus (nil pref, nil node, W=0, full match binpack/spread, partial match 70/30, no match)
    - pkg/scheduler/node_affinity_score_test.go: calcScore level with 2 nodes. feature off = old behavior, binpack and spread pick preferred node, many terms follow weight ratio, preferred node unfit → fallback to other node (no Pending), invalid term ignored
  • I used Claude Code for help with tests, comments and reviewing my code. Scheduler logic I wrote and checked by myself.
  • Does this PR introduce a user-facing change?:

    ``release-note
    Scheduler: new flag
    --node-affinity-score-weight (chart value scheduler.defaultSchedulerPolicy.nodeAffinityScoreWeight) adds a bonus to the HAMi node score for nodes matching the Pod's preferred nodeAffinity. Default 0 keeps the current behavior.

    AI Assistance Disclosure:

    I used Claude Code to help me investigate the code, make the changes (I reviewed and approved each one), and refine the content of this PR.

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->
    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    New Features
    Added an optional node-affinity scoring weight to scheduling configuration. When enabled, preferred node-affinity matches influence node ranking in proportion to their weights, according to the configured binpack or spread policy. The default value of
    0` disables this scoring. Configure the setting through the scheduler or Helm chart; invalid weights are rejected.
    Documentation
    * Clarified how node selection and affinity scoring interact, including the limits of other scheduler scoring plugins. Documented the setting’s default and scoring behavior.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 471 lines (+353 / -118) across 5 files Reviewer: blackdragoon26 Review duration: 6025m
    All Vouch review confidence checks passed
    Residual risk 0.18 = Change Risk (0.46) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.46 · 471 lines diff across 5 files
    0.46
    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.368
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3298"
    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: 45.7% (MEDIUM) · Higher = larger blast radius
    45.7%
    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: 18.1% · Safe to merge
    18.1%