kubernetes-sigs / karpenter

Karpenter is a Kubernetes Node Autoscaler built for flexibility, performance, and simplicity.
Apache License 2.0
637 stars 206 forks source link

perf: Improve TopologyGroup node domain iteration #1820

Closed jonathan-innis closed 4 days ago

jonathan-innis commented 5 days ago

Fixes #N/A

Description

This change updates our iteration over domains for TSC, affinity, and anti-affinity. Often, we have cases where we have available domains across the cluster, but those domains aren't available for the node we are currently on. This is specifically true with hostname requirements where there is only one option that the node can carry.

Rather than looping through all domain options and adding those as possibilities when they were never really possible because the node doesn't support it, this change adds an optimization to only loop through the available node domains if it's shorter than all available domains.

For hostname, this turns our O(node) operation into an O(1) operation to validate whether the pod can fit on the node.

Before

Screenshot 2024-11-16 at 11 05 06 PM

After

Screenshot 2024-11-17 at 12 38 48 AM

How was this change tested?

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

k8s-ci-robot commented 5 days ago

Skipping CI for Draft Pull Request. If you want CI signal for your change, please convert it to an actual PR. You can still manually trigger a test run with /test all

k8s-ci-robot commented 5 days ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jonathan-innis

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

The pull request process is described here

Needs approval from an approver in each of these files: - ~~[OWNERS](https://github.com/kubernetes-sigs/karpenter/blob/main/OWNERS)~~ [jonathan-innis] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment
coveralls commented 4 days ago

Pull Request Test Coverage Report for Build 11884266313

Details


Files with Coverage Reduction New Missed Lines %
pkg/scheduling/requirements.go 2 98.01%
pkg/controllers/provisioning/scheduling/existingnode.go 2 86.49%
pkg/controllers/provisioning/scheduling/nodeclaim.go 2 87.23%
<!-- Total: 6 -->
Totals Coverage Status
Change from base Build 11882312260: 0.03%
Covered Lines: 8663
Relevant Lines: 10685

💛 - Coveralls
jmdeal commented 4 days ago

/lgtm /hold

jmdeal commented 4 days ago

/lgtm

jmdeal commented 4 days ago

/unhold