Files
kubernetes/pkg
Tetiana Khotiainsteva fb74900c53 scheduler: optimize evaluation of kubernetes.io/hostname-scoped inter-pod affinity
Introduces a "fast-track" evaluation path for inter-pod affinity
and anti-affinity rules that use the "kubernetes.io/hostname" topology key.

If only kubernetes.io/hostname topology is present (which is a common use case), we only need to check the current node.
There is no need to do O(N*M) cluster-wide scans.

Key Optimizations:
 - Categorized affinity and anti-affinity terms into "host-scoped" (kubernetes.io/hostname)
   and "non-host-scoped" groups during PreFilter.
 - Updated NodeInfo and Snapshot to specifically track pods with non-host-scoped
   anti-affinity, allowing the scheduler to skip global map lookups when only
   kubernetes.io/hostname rules are present.
 - Updated the Filter phase to perform efficient local checks against pods
   already on the target node for kubernetes.io/hostname-scoped rules, rather than relying
   on global topology counts.

The change is guarded with the InterPodAffinityHostnameFastPath feature gate.

Testing & Correctness:
 - Added `TestFastTrackInterPodAffinity` to `filtering_test.go` to verify the
   new fast-path logic against various topology and namespace scenarios.
 - Added `TestAffinityDiscrepancy` to `filtering_test.go` to ensure correctness
   when a pod has multiple affinity terms that must be satisfied by a single
   existing pod.
 - Modified relevant integration tests (including preemption and scoring) to
   execute tests combinatorially with the InterPodAffinityHostnameFastPath gate
   both enabled and disabled, ensuring functional parity.
2026-07-25 14:25:58 +02:00
..
…