← Back to Pull requests

Introduce relevance filter for ClusterSnapshot #9596

Closed
x13n closed this pull request without merging on Jun 19, 2026 12:56 UTC
View on GitHub
x13n x13n commented on May 06, 2026 08:16 UTC
Author

This feature results in visible (up to almost 10x) loop time reduction in the provided anti-affinity surge benchmark, depending on the topology used.

$ go test -v ./core/bench -bench BenchmarkRunOnceAffinitySurge -run ^$ -benchtime=1x
goos: linux
goarch: amd64
pkg: k8s.io/autoscaler/cluster-autoscaler/core/bench cpu: AMD EPYC 7B13
BenchmarkRunOnceAffinitySurge_Hostname_Default
BenchmarkRunOnceAffinitySurge_Hostname_Default-64 1 606368983108 ns/op
BenchmarkRunOnceAffinitySurge_Hostname_RelevantOnly
BenchmarkRunOnceAffinitySurge_Hostname_RelevantOnly-64 1 72663479496 ns/op
BenchmarkRunOnceAffinitySurge_Zonal_Default
BenchmarkRunOnceAffinitySurge_Zonal_Default-64 1 605389016837 ns/op
BenchmarkRunOnceAffinitySurge_Zonal_RelevantOnly
BenchmarkRunOnceAffinitySurge_Zonal_RelevantOnly-64 1 313136394981 ns/op

What type of PR is this?

/kind feature

What this PR does / why we need it:

Performance improvement.

Which issue(s) this PR fixes:


<!--
Automatically closes linked issue when PR is merged.
Usage: Fixes #<issue number>, or Fixes (paste link of issue).
_If PR is about failing-tests or flakes, please post the related issues/tests in a comment and do not use Fixes_

-->
Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?


<!--
If no, just write "NONE" in the release-note block below.
If yes, a release note is required:
Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".

For more information on release notes see: https://git.k8s.io/community/contributors/guide/release-notes.md
-->
``release-note
Added a new, experimental --relevance-filter-enabled flag, pruning irrelevant nodes before scale up simulations, significantly improving performance at scale when computationally complex scheduling predicates are used (inter pod affinity, topology spreading).


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

<!--
This section can be blank if this pull request does not require a release note.

When adding links which point to resources within git repositories, like
KEPs or supporting documentation, please reference a specific commit and avoid
linking directly to the master branch. This ensures that links reference a
specific point in time, rather than a document that may change over time.

See here for guidance on getting permanent links to files: https://help.github.com/en/articles/getting-permanent-links-to-files

Please use the following format for linking documentation:
- [KEP]: <link>
- [Usage]: <link>
- [Other doc]: <link>
-->
docs

``

/cc @tetianakh @towca
/hold to add unit tests beyond the benchmark

Diff: 692 lines (+688 / -4) across 7 files Reviewer: Choraden Review duration: 63639m
All Vouch review confidence checks passed
Residual risk 0.08 = Change Risk (0.51) × (1 − Review Confidence (0.85)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.51 · 692 lines diff across 7 files
0.51
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.74 · 5 substantive comment(s)
0.74
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
84%
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.391
Real PR Conversation Timeline
15 items
k8s-ci-robot k8s-ci-robot commented on May 06, 2026 08:16 UTC
Contributor

@x13n: GitHub didn't allow me to request PR reviews from the following users: tetianakh.

Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs.

<details>

In response to this:

>This feature results in visible (up to almost 10x) loop time reduction in the provided anti-affinity surge benchmark, depending on the topology used.

>$ go test -v ./core/bench -bench BenchmarkRunOnceAffinitySurge -run ^$ -benchtime=1x

>goos: linux
>goarch: amd64
>pkg: k8s.io/autoscaler/cluster-autoscaler/core/bench cpu: AMD EPYC 7B13
>BenchmarkRunOnceAffinitySurge_Hostname_Default
>BenchmarkRunOnceAffinitySurge_Hostname_Default-64 1 606368983108 ns/op
>BenchmarkRunOnceAffinitySurge_Hostname_RelevantOnly
>BenchmarkRunOnceAffinitySurge_Hostname_RelevantOnly-64 1 72663479496 ns/op
>BenchmarkRunOnceAffinitySurge_Zonal_Default
>BenchmarkRunOnceAffinitySurge_Zonal_Default-64 1 605389016837 ns/op
>BenchmarkRunOnceAffinitySurge_Zonal_RelevantOnly
>BenchmarkRunOnceAffinitySurge_Zonal_RelevantOnly-64 1 313136394981 ns/op
>#### What type of PR is this?

>/kind feature

>#### What this PR does / why we need it:

>Performance improvement.

>#### Which issue(s) this PR fixes:

><!--
>Automatically closes linked issue when PR is merged.
>Usage: Fixes #<issue number>, or Fixes (paste link of issue).
>_If PR is about failing-tests or flakes, please post the related issues/tests in a comment and do not use Fixes_

>-->
>Fixes #
>#### Special notes for your reviewer:

>#### Does this PR introduce a user-facing change?

><!--
>If no, just write "NONE" in the release-note block below.
>If yes, a release note is required:
>Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
>For more information on release notes see: https://git.k8s.io/community/contributors/guide/release-notes.md

>-->
>``release-note
>Added a new, experimental --relevance-filter-enabled flag, pruning irrelevant nodes before scale up simulations, significantly improving performance at scale when computationally complex scheduling predicates are used (inter pod affinity, topology spreading).
>
>
>#### Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:
>
><!--
>This section can be blank if this pull request does not require a release note.
>
>When adding links which point to resources within git repositories, like
>KEPs or supporting documentation, please reference a specific commit and avoid
>linking directly to the master branch. This ensures that links reference a
>specific point in time, rather than a document that may change over time.
>
>See here for guidance on getting permanent links to files: https://help.github.com/en/articles/getting-permanent-links-to-files
>
>Please use the following format for linking documentation:
>- [KEP]: <link>
>- [Usage]: <link>
>- [Other doc]: <link>
>-->
>
docs
>``

>/cc @tetianakh @towca

>/hold to add unit tests beyond the benchmark
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.

</details>

k8s-ci-robot k8s-ci-robot commented on May 06, 2026 08:16 UTC
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.
</details>

k8s-ci-robot k8s-ci-robot commented on May 06, 2026 08:16 UTC
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: <a href="https://github.com/kubernetes/autoscaler/pull/9596#" title="Author self-approved">x13n</a>

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

The pull request process is described here

<details >
Needs approval from an approver in each of these files:

  • ~~cluster-autoscaler/OWNERS~~ [x13n]
  • Approvers can indicate their approval by writing /approve in a comment
    Approvers can cancel approval by writing /approve cancel in a comment
    </details>
    <!-- META={"approvers":[]} -->

    Choraden Choraden commented on code on May 11, 2026 09:15 UTC
    Code Review
    cluster-autoscaler/core/bench/benchmark_runonce_affinity_test.go:1
    @@ -0,0 +1,247 @@
    +/*
    +Copyright The Kubernetes Authors.
    +
    +Licensed under the Apache License, Version 2.0 (the "License");
    +you may not use this file except in compliance with the License.
    +You may obtain a copy of the License at
    +
    +    http://www.apache.org/licenses/LICENSE-2.0
    +
    +Unless required by applicable law or agreed to in writing, software
    +distributed under the License is distributed on an "AS IS" BASIS,
    +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +See the License for the specific language governing permissions and
    +limitations under the License.
    +*/
    +
    +package bench
    +
    +import (
    +	"fmt"
    +	"math/rand"
    +	"testing"
    +	"time"
    +
    +	apiv1 "k8s.io/api/core/v1"
    +	"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
    +	testprovider "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/test"
    +	"k8s.io/autoscaler/cluster-autoscaler/config"
    +	"k8s.io/autoscaler/cluster-autoscaler/expander"
    +	"k8s.io/autoscaler/cluster-autoscaler/simulator/framework"
    +	"k8s.io/autoscaler/cluster-autoscaler/test/integration"
    +	. "k8s.io/autoscaler/cluster-autoscaler/utils/test"
    +)
    +
    +const (
    +	nodesCount        = 5000

    It looks like the benchmark takes too much time to be useable as a CI job. Especially that it is run 8 times to eliminate noise.
    Any chance to decrease the node count? I believe it would still be a worthy signal.

    x13n x13n commented on code on May 11, 2026 13:19 UTC
    Code Review
    cluster-autoscaler/core/bench/benchmark_runonce_affinity_test.go:1
    @@ -0,0 +1,247 @@
    +/*
    +Copyright The Kubernetes Authors.
    +
    +Licensed under the Apache License, Version 2.0 (the "License");
    +you may not use this file except in compliance with the License.
    +You may obtain a copy of the License at
    +
    +    http://www.apache.org/licenses/LICENSE-2.0
    +
    +Unless required by applicable law or agreed to in writing, software
    +distributed under the License is distributed on an "AS IS" BASIS,
    +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +See the License for the specific language governing permissions and
    +limitations under the License.
    +*/
    +
    +package bench
    +
    +import (
    +	"fmt"
    +	"math/rand"
    +	"testing"
    +	"time"
    +
    +	apiv1 "k8s.io/api/core/v1"
    +	"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
    +	testprovider "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/test"
    +	"k8s.io/autoscaler/cluster-autoscaler/config"
    +	"k8s.io/autoscaler/cluster-autoscaler/expander"
    +	"k8s.io/autoscaler/cluster-autoscaler/simulator/framework"
    +	"k8s.io/autoscaler/cluster-autoscaler/test/integration"
    +	. "k8s.io/autoscaler/cluster-autoscaler/utils/test"
    +)
    +
    +const (
    +	nodesCount        = 5000

    The benefit of doing this is mainly visible at scale. I thought of this benchmark as something that would be triggered manually, not as a part of CI. That being said, smaller scale version for CI does sound useful, let me try and split this into larger scale manual and medium scale CI versions.

    x13n x13n commented on code on May 12, 2026 09:30 UTC
    Code Review
    cluster-autoscaler/core/bench/benchmark_runonce_affinity_test.go:1
    @@ -0,0 +1,247 @@
    +/*
    +Copyright The Kubernetes Authors.
    +
    +Licensed under the Apache License, Version 2.0 (the "License");
    +you may not use this file except in compliance with the License.
    +You may obtain a copy of the License at
    +
    +    http://www.apache.org/licenses/LICENSE-2.0
    +
    +Unless required by applicable law or agreed to in writing, software
    +distributed under the License is distributed on an "AS IS" BASIS,
    +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +See the License for the specific language governing permissions and
    +limitations under the License.
    +*/
    +
    +package bench
    +
    +import (
    +	"fmt"
    +	"math/rand"
    +	"testing"
    +	"time"
    +
    +	apiv1 "k8s.io/api/core/v1"
    +	"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
    +	testprovider "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/test"
    +	"k8s.io/autoscaler/cluster-autoscaler/config"
    +	"k8s.io/autoscaler/cluster-autoscaler/expander"
    +	"k8s.io/autoscaler/cluster-autoscaler/simulator/framework"
    +	"k8s.io/autoscaler/cluster-autoscaler/test/integration"
    +	. "k8s.io/autoscaler/cluster-autoscaler/utils/test"
    +)
    +
    +const (
    +	nodesCount        = 5000

    Updated, PTAL.

    Choraden Choraden commented on code on May 13, 2026 09:58 UTC
    Code Review
    cluster-autoscaler/core/bench/benchmark_runonce_affinity_test.go:1
    @@ -0,0 +1,247 @@
    +/*
    +Copyright The Kubernetes Authors.
    +
    +Licensed under the Apache License, Version 2.0 (the "License");
    +you may not use this file except in compliance with the License.
    +You may obtain a copy of the License at
    +
    +    http://www.apache.org/licenses/LICENSE-2.0
    +
    +Unless required by applicable law or agreed to in writing, software
    +distributed under the License is distributed on an "AS IS" BASIS,
    +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +See the License for the specific language governing permissions and
    +limitations under the License.
    +*/
    +
    +package bench
    +
    +import (
    +	"fmt"
    +	"math/rand"
    +	"testing"
    +	"time"
    +
    +	apiv1 "k8s.io/api/core/v1"
    +	"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
    +	testprovider "k8s.io/autoscaler/cluster-autoscaler/cloudprovider/test"
    +	"k8s.io/autoscaler/cluster-autoscaler/config"
    +	"k8s.io/autoscaler/cluster-autoscaler/expander"
    +	"k8s.io/autoscaler/cluster-autoscaler/simulator/framework"
    +	"k8s.io/autoscaler/cluster-autoscaler/test/integration"
    +	. "k8s.io/autoscaler/cluster-autoscaler/utils/test"
    +)
    +
    +const (
    +	nodesCount        = 5000

    Thanks! This looks promising.

    I noticed that the PR bench failed with 143 error though, as it went out of memory. I believe I've found the cause. PTAL #9632

    tetianakh tetianakh commented on May 13, 2026 15:43 UTC
    Contributor

    What overhead does this change introduce in case when all nodes are relevant (e.g. a depoyment with host scoped AA for itself, so there's one pod per node)?

    x13n x13n commented on May 14, 2026 17:27 UTC
    Author

    For host scoped anti-affinity no existing nodes are actually relevant (for host scoped pod affinity a single node is relevant to ensure it works correctly for the first pod). In the scenario you describe, pretty much the entire snapshot should get filtered out.

    tetianakh tetianakh commented on May 15, 2026 16:40 UTC
    Contributor

    Ok, true, that was a bad example. What if all pods have AA that's e.g. zonal, or nodepool scoped?

    x13n x13n commented on May 19, 2026 13:48 UTC
    Author

    If there is zonal/nodepool scoped AA, then there will only be a single node with such pod per topology, and only such nodes should stay. There is an edge case where there is a pod A with zonal anti-affinity to all pods with a specific label (but these pods don't have anti-affinity to that label themselves, so it is possible for them to coexist in the same zone). This could be further optimized as a follow up if needed, to only keep one such node per topology.

    k8s-ci-robot k8s-ci-robot commented on May 29, 2026 01:26 UTC
    Contributor

    PR needs rebase.

    <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.
    </details>

    x13n x13n commented on Jun 19, 2026 12:56 UTC
    Author

    On the last SIG meeting I mentioned I will be experimenting with embedding Karpenter scheduling engine into CA in preparation of the codebase for SDA. In that world, this concept of a relevance filter is likely unnecessary, so closing this PR.

    /close

    k8s-ci-robot k8s-ci-robot commented on Jun 19, 2026 12:56 UTC
    Contributor

    @x13n: Closed this PR.

    <details>

    In response to this:

    >On the last SIG meeting I mentioned I will be experimenting with embedding Karpenter scheduling engine into CA in preparation of the codebase for SDA. In that world, this concept of a relevance filter is likely unnecessary, so closing this PR.

    >/close

    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.
    </details>

    Reviewers
    Assignees
    x13n x13n
    Labels
    risk: low confidence: 84.7% 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: 50.9% (MEDIUM) · Higher = larger blast radius
    50.9%
    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: 84.7% · Lower = rushed or shallow review
    84.7%
    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: 7.8% · Safe to merge
    7.8%