Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KEP-3990: PodTopologySpread DoNotSchedule-to-ScheduleAnyway fallback mode #4150

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sanposhiho
Copy link
Member

  • One-line PR description: PodTopologySpread DoNotSchedule-to-ScheduleAnyway fallback mode
  • Other comments:

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/kep Categorizes KEP tracking issues and PRs modifying the KEP directory labels Aug 12, 2023
@k8s-ci-robot k8s-ci-robot added sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Aug 12, 2023
@sanposhiho
Copy link
Member Author

/assign @alculquicondor @MaciekPytel
/sig scheduling autoscaling

@k8s-ci-robot k8s-ci-robot added the sig/autoscaling Categorizes an issue or PR as relevant to SIG Autoscaling. label Aug 12, 2023
information to express the idea and why it was not acceptable.
-->

### introduce `DoNotScheduleUntilScaleUpFailed` and `DoNotScheduleUntilPreemptionFailed`
Copy link
Member Author

@sanposhiho sanposhiho Aug 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a design similar to what we discussed in the issue. But, I switched this to fallbackCriteria for the reason described here. Open for discussion about which design we should choose.

Even if the Pod is rejected by plugins other than Pod Topology Spread,
when one of specified criteria is satisfied, the scheduler fallbacks from DoNotSchedule to ScheduleAnyway.

One possible mitigation is to add `UnschedulablePlugins`, which equals to [QueuedPodInfo.UnschedulablePlugins](https://github.com/kubernetes/kubernetes/blob/8a7df727820bafed8cef27e094a0212d758fcd40/pkg/scheduler/framework/types.go#L180), to somewhere in Pod status
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alculquicondor What do you think?

@@ -0,0 +1,3 @@
kep-number: 3990
beta:
approver: "@wojtek-t"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wojtek-t I assigned it to you as other sig-scheduling KEPs do.
But, please reassign it to other people if needed. 🙏

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just quickly skimmed through it - I will reviewer deeper when you will have buy-in from the SIG.

@@ -0,0 +1,3 @@
kep-number: 3990
beta:
approver: "@wojtek-t"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just quickly skimmed through it - I will reviewer deeper when you will have buy-in from the SIG.

#### the fallback could be done when it's actually not needed.

Even if the Pod is rejected by plugins other than Pod Topology Spread,
when one of specified criteria is satisfied, the scheduler fallbacks from DoNotSchedule to ScheduleAnyway.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand it - can you clarify?

Copy link
Member Author

@sanposhiho sanposhiho Aug 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, let's say PodA has a required Pod Topology Spread with fallbackCriteria: ScaleUpFailed. When PodA's first scheduling, all Nodes went through Pod Topology Spread filter plugin, but they were rejected by other plugins (e.g., the resource fit filter plugin because of insufficient resources.), and PodA got unschedulable state as a result. Then, the cluster autoscaler tried to create a new Node for PodA but it couldn't make it because of stockout.

In this case, Pod Topology Spread doesn't need to fallback actually because it said OK to all Nodes in the previous scheduling cycle -- meaning Pod Topology Spread isn't the cause of unschedulable in the past scheduling cycle and the fallback won't make PodA schedulable.
But, the problem is that Pod Topology Spread cannot see why this Pod was rejected in the previous scheduling cycle. It only understands that PodA was rejected by someone in the previous scheduling, and the cluster autoscaler couldn't create a new Node.

@wojtek-t wojtek-t self-assigned this Aug 24, 2023
@@ -0,0 +1,35 @@
title: Pod Topology Spread DoNotSchedule to SchedulingAnyway fallback mode
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
title: Pod Topology Spread DoNotSchedule to SchedulingAnyway fallback mode
title: Pod Topology Spread DoNotSchedule to ScheduleAnyway fallback mode

@alculquicondor
Copy link
Member

/cc @mwielgus


A new field `fallbackCriteria` is introduced to `PodSpec.TopologySpreadConstraint[*]`
to represent when to fallback from DoNotSchedule to ScheduleAnyway.
It can contain two values: `ScaleUpFailed` to fallback when the cluster autoscaler fails to create new Node for Pods,
Copy link

@a7i a7i Sep 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it not simply default to FailedScheduling. As far as I know, ScaleUpFailed is a cluster-autoscaler specific event so for those who use something else (e.g. karpenter), then this will not work.

One challenge with FailedScheduling is that's what cluster-autoscaler reacts on so there could be a race condition in cluster-autoscaler scaling up vs. switching to fallback mode.

Copy link
Member Author

@sanposhiho sanposhiho Sep 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part only means that ScaleUpFailed is a new value that will be added to fallbackCriteria. Yes, I took this name from the cluster autoscaler's event name, but it should work with any cluster autoscaler if they update TriggeredScaleUp Pod condition, which is also proposed in this KEP.

@alculquicondor
Copy link
Member

We had too much to bite in this cycle. This will have to wait for the next release :(

Try to get some input from SIG Autoscaling in one of their meetings.

@sanposhiho
Copy link
Member Author

Yes..

Try to get some input from SIG Autoscaling in one of their meetings.

Sure.

should be approved by the remaining approvers and/or the owning SIG (or
SIG Architecture for cross-cutting KEPs).
-->
# KEP-3990: Pod Topology Spread DoNotSchedule to SchedulingAnyway fallback mode

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious if there's an analogous use case for:

  • Preferential node affinity
  • Preferential pod affinity/antiaffinity

Is there any world where a user may want to have more control over how preferences are handled with autoscalers?

Copy link
Member Author

@sanposhiho sanposhiho Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there's an analogous use case for:

Yes, might be. We would wait for the actual usecases from users before implementing the similar stuff in them though, we should make this design to be easy to follow in other scheduling constants

Comment on lines +1014 to +1015
On the other hand, `FallBackCriteria` allows us to unify APIs in all scheduling constraints.
We will just introduce `FallBackCriteria` field in them and there we go.
Copy link

@ellistarn ellistarn Oct 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me think that we might want to model fallback criteria at the pod level.

preferentialFallback:
  - PodAffinity
  - AntiAffinity
  - TopologySpreadConstraints

It may be difficult to get the granularity right, though. At another extreme (as you propose), you'd add a preference policy for each preferred term across the pod spec.

Copy link
Member Author

@sanposhiho sanposhiho Oct 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an interesting idea.
Because when people want to use fallback, they may want to do the same in all required scheduling constraints the Pod has. Also, we may want to give preferentialFallback the way to "fallback in all".

So, maybe it'd be like this:

preferentialFallback:
  schedulingConstraints: 
  - "*" # do fallback in all scheduling constraints.
  # You can also specify individual scheduling constraints name, which supports fallback.
  # (But, note that this KEP's scope is only TopologySpread.)
  fallBackCriteria:
  - ScaleUpFailed

Let me include this idea in the alternative section for now. Like the idea of introducing enums, we can gather feedback from more people about the design choice among them.

Comment on lines +1001 to +1003
Instead of `FallBackCriteria`, introduce `DoNotScheduleUntilScaleUpFailed` and `DoNotScheduleUntilPreemptionFailed` in `WhenUnsatisfiable`.
`DoNotScheduleUntilScaleUpFailed` corresponds to `ScaleUpFailed`,
and `DoNotScheduleUntilPreemptionFailed` corresponds to `PreemptionFailed`.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some benefits to reusing this an existing field with new enum values. I'm a touch concerned with how complicated topologyspreadconstraints are getting, with two new honor fields (with different defaults).

I interact with a bunch of customers who are learning kubernetes scheduling for the first time when onboarding to Karpenter, and communicating the complexity and gotchas of topology is always a huge hurdle to get over.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously, I agree that we need to make it easy to understand as much as possible. But, also introducing a new field doesn't always result in confusion.
For this particular KEP, I think FallBackCriteria is not much more complicated than introducing new enum values in WhenUnsatisfiable. Then, currently I'm leaning towards FallBackCriteria for the ease to introduce it into other scheduling constraints, as described.
But, maybe I'm biased since I know the scheduler/CA, I know everything that this KEP wants to do, etc. 😅
So, I'd like to keep this discussion open to gather more feedback from reviewers.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that topologyspreadconstraints are difficult to explain to clients (been there), but I think this added field is optional complexity. It is also the other way around, right? It is a complex solution to a complex setup, but the complex setup came first. Clients that need to hear this are already dealing with specific cases that call for all of this, and in theory are easier to talk to. Also agree that I don't see it as easier to explain when considering existing field with new enum values, so I guess that if it is hard to explain, it would be hard either way.

Copy link
Contributor

@jsoref jsoref left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apparently i wrote this a while ago...


A new field `fallbackCriteria` is introduced to `PodSpec.TopologySpreadConstraint[*]`
to represent when to fallback from DoNotSchedule to ScheduleAnyway.
It can contain two values: `ScaleUpFailed` to fallback when the cluster autoscaler fails to create new Node for Pods,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
It can contain two values: `ScaleUpFailed` to fallback when the cluster autoscaler fails to create new Node for Pods,
It can contain two values: `ScaleUpFailed` to fall back when the cluster autoscaler fails to create new Node for Pods,

A new field `fallbackCriteria` is introduced to `PodSpec.TopologySpreadConstraint[*]`
to represent when to fallback from DoNotSchedule to ScheduleAnyway.
It can contain two values: `ScaleUpFailed` to fallback when the cluster autoscaler fails to create new Node for Pods,
and `PreemptionFailed` to fallback when the preemption doesn't help to make Pods schedulable.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
and `PreemptionFailed` to fallback when the preemption doesn't help to make Pods schedulable.
and `PreemptionFailed` to fall back when the preemption doesn't help to make Pods schedulable.

#### Story 2

Your cluster doesn't have the cluster autoscaler
and has some low-priority Pods to make space (often called overprovisional Pods, balloon Pods, etc).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
and has some low-priority Pods to make space (often called overprovisional Pods, balloon Pods, etc).
and has some low-priority Pods to make space (often called overprovisional Pods, balloon Pods, etc.).

when one of specified criteria is satisfied, the scheduler fallbacks from DoNotSchedule to ScheduleAnyway.

One possible mitigation is to add `UnschedulablePlugins`, which equals to [QueuedPodInfo.UnschedulablePlugins](https://github.com/kubernetes/kubernetes/blob/8a7df727820bafed8cef27e094a0212d758fcd40/pkg/scheduler/framework/types.go#L180), to somewhere in Pod status
so that Pod Topology Spread can decide to fallback only when the Pod was rejected by Pod Topology Spread.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
so that Pod Topology Spread can decide to fallback only when the Pod was rejected by Pod Topology Spread.
so that Pod Topology Spread can decide to fall back only when the Pod was rejected by Pod Topology Spread.

### new API changes

```go
// FallbackCriterion represents when the scheduler fallbacks from the required scheduling constraint to the preferred one.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// FallbackCriterion represents when the scheduler fallbacks from the required scheduling constraint to the preferred one.
// FallbackCriterion represents when the scheduler falls back from the required scheduling constraint to the preferred one.

Comment on lines +350 to +353
// FallbackCriteria is the list of criteria that the scheduler decides when to fallback from DoNotSchedule to ScheduleAnyway.
// It's valid to set only when WhenUnsatisfiable is DoNotSchedule.
// If multiple criteria are in this list, the scheduler fallbacks when ALL criteria in `FallbackCriterion` are satisfied.
// It's an optional field. The default value is nil, meaning the scheduler never fallbacks.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// FallbackCriteria is the list of criteria that the scheduler decides when to fallback from DoNotSchedule to ScheduleAnyway.
// It's valid to set only when WhenUnsatisfiable is DoNotSchedule.
// If multiple criteria are in this list, the scheduler fallbacks when ALL criteria in `FallbackCriterion` are satisfied.
// It's an optional field. The default value is nil, meaning the scheduler never fallbacks.
// FallbackCriteria is the list of criteria that the scheduler decides when to fall back from DoNotSchedule to ScheduleAnyway.
// It's valid to set only when WhenUnsatisfiable is DoNotSchedule.
// If multiple criteria are in this list, the scheduler falls back when ALL criteria in `FallbackCriterion` are satisfied.
// It's an optional field. The default value is nil, meaning the scheduler never falls back.

@sanposhiho
Copy link
Member Author

Describing the current situation here:

I brought this KEP into SIG/Autoscaling weekly meeting a couple of months ago, and concluded that we had to consider how CA set TriggeredScaleUp: false reliably.

[maciekpytel] - One comment, in general, being unable to trigger scale-up is one failure scenario. However CA can also trigger a scaleup but fail to get capacity, for cloudprovider reasons etc.

  • We’d need to reliably set the status in these conditions, not sure if the CA is able to do this today.
    Could end up in a situation where the CA keeps trying other node groups
  • Will talk internally with other CA maintainers and come back with someone best able to commit to feedback on this.

Weekly meeting note: https://docs.google.com/document/d/1RvhQAEIrVLHbyNnuaT99-6u9ZUMp7BfkPupT2LAZK7w/edit#bookmark=id.oxf7zvbyd9ya

Not sure if we'll make it in this release though, I'll spend some time on this KEP in this release cycle as well - I'll go around CA's implementation to understand scenarios there myself, and elaborate the KEP around there. Thanks for several feedback so far, I'll bring the fixes towards all at the same time.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: sanposhiho
Once this PR has been reviewed and has the lgtm label, please ask for approval from alculquicondor, wojtek-t. For more information see the Kubernetes Code Review Process.

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

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

@k8s-ci-robot
Copy link
Contributor

@sanposhiho: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-enhancements-verify ea3fc17 link true /test pull-enhancements-verify

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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/test-infra repository. I understand the commands that are listed here.

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 15, 2024
@sanposhiho
Copy link
Member Author

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 15, 2024
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/kep Categorizes KEP tracking issues and PRs modifying the KEP directory sig/autoscaling Categorizes an issue or PR as relevant to SIG Autoscaling. sig/scheduling Categorizes an issue or PR as relevant to SIG Scheduling. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
Status: Needs Triage
Development

Successfully merging this pull request may close these issues.

None yet

10 participants