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

add podGroup backoff time for coscheduling #559

Merged
merged 2 commits into from
Jul 25, 2023

Conversation

KunWuLuan
Copy link
Member

@KunWuLuan KunWuLuan commented Mar 29, 2023

Adding a backoff in co-scheduling (#429 (comment)) helps to avoid infinite scheduling loop.

Add a new coscheduling plugin argument `podGroupBackoffSeconds` to configure backoff timer for failed PodGroup. User needs to explicitly specify a positive integer to enable this feature.

@k8s-ci-robot k8s-ci-robot added do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Mar 29, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @KunWuLuan. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 29, 2023
@denkensk
Copy link
Member

denkensk commented Apr 3, 2023

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 3, 2023
@KunWuLuan
Copy link
Member Author

/test all

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 23, 2023
@@ -485,7 +485,7 @@ func TestTopologyCachePluginWithoutUpdates(t *testing.T) {
checkPod = podIsPending
}

err = checkPod(1*time.Second, 20, cs, p.pod.Namespace, p.pod.Name)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd expect to see a new (sub-)integration test to simulate what was described in the original issue.

Otherwise, I'd postpone the impl. to next release.

Copy link
Member Author

Choose a reason for hiding this comment

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

Have added a new integration test for the case

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks. But even without introducing the backoff, the integration test seems to be also passing.

weih@m1max:~/go/src/sigs.k8s.io/scheduler-plugins|master⚡ ⇒  go test ./test/integration/... -run TestPodgroupBackoff -count 1
ok  	sigs.k8s.io/scheduler-plugins/test/integration	27.100s
weih@m1max:~/go/src/sigs.k8s.io/scheduler-plugins|master⚡ ⇒  gst
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   test/integration/coscheduling_test.go

Could you update the test to pass and only pass with the backoff changes? in other words, the test is expected to fail on master.

Copy link
Member Author

Choose a reason for hiding this comment

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

No problem

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 28, 2023
@KunWuLuan KunWuLuan force-pushed the master branch 2 times, most recently from d721c00 to 3588a53 Compare June 29, 2023 02:12
pkg/coscheduling/core/core.go Outdated Show resolved Hide resolved
pkg/coscheduling/core/core.go Outdated Show resolved Hide resolved
pkg/coscheduling/core/core.go Outdated Show resolved Hide resolved
Comment on lines 172 to 175
pods, err := cs.frameworkHandler.SharedInformerFactory().Core().V1().Pods().Lister().Pods(pod.Namespace).List(
labels.SelectorFromSet(labels.Set{v1alpha1.PodGroupLabel: util.GetPodGroupLabel(pod)}),
)
if err == nil && len(pods) >= int(pg.Spec.MinMember) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we remove the check here? (given assigned < pg.Spec.MinMember per L150)

Copy link
Contributor

Choose a reason for hiding this comment

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

bump.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we can not remove the check here.

assigned < pg.Spec.MinMember check whether the gang has been satisfied and len(pods) >= int(pg.Spec.MinMember) check whether there is enough pods to schedule.

When the first pod come, scheduler may list not all pods. We will reject the first pod in preFilter

if len(pods) < int(pg.Spec.MinMember) {
return fmt.Errorf("pre-filter pod %v cannot find enough sibling pods, "+
"current pods number: %v, minMember of group: %v", pod.Name, len(pods), pg.Spec.MinMember)
}

But we should not add this pod group to Backoff. If we add this pod group to Backoff, all following pods will be rejected.

apis/config/v1/types.go Outdated Show resolved Hide resolved
@@ -71,6 +72,7 @@ func New(obj runtime.Object, handle framework.Handle) (framework.Plugin, error)
podInformer := handle.SharedInformerFactory().Core().V1().Pods()

scheduleTimeDuration := time.Duration(args.PermitWaitingTimeSeconds) * time.Second
pgBackoff := time.Duration(args.PodGroupBackoffTime) * time.Second
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you check if it's 0/nil here, and if yes, don't instantiate pgBackoff. So that we can check if pgBackoff is nil at L172 and only proceed get pods when it's not nil:

var pgBackoff ...
if args.PodGroupBackoffTime != 0 { ... }

func (pgMgr *PodGroupManager) AddToPodGroupBackoff(pgName string) {
pgMgr.podGroupBackoff.Add(pgName, nil, 10*time.Second)
func (pgMgr *PodGroupManager) BackoffPodGroup(pgName string, backoff time.Duration) {
if backoff == time.Duration(0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

commented elsewhere: IMO we should return as early as possible.

Copy link
Member Author

Choose a reason for hiding this comment

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

we can check whether cs.pgBackoff != nil outside, It's already done

Comment on lines 172 to 175
pods, err := cs.frameworkHandler.SharedInformerFactory().Core().V1().Pods().Lister().Pods(pod.Namespace).List(
labels.SelectorFromSet(labels.Set{v1alpha1.PodGroupLabel: util.GetPodGroupLabel(pod)}),
)
if err == nil && len(pods) >= int(pg.Spec.MinMember) {
Copy link
Contributor

Choose a reason for hiding this comment

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

bump.

@@ -1022,6 +1024,7 @@ profiles:
apiVersion: kubescheduler.config.k8s.io/v1
kind: CoschedulingArgs
permitWaitingTimeSeconds: 10
podGroupBackoffTime: 0
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd expect without explicitly specifying it, UT would also pass. Could you check if you want to add explicit defaulting logic? (convert nil from versioned args to 0 in internal args)

Copy link
Member Author

Choose a reason for hiding this comment

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

podGroupBackoffTime: 0 means we will not backoff pod groups.
I think maybe we don't have to add explicit defaulting logic, because by default nil will be convert to 0

Copy link
Contributor

Choose a reason for hiding this comment

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

That's correct. The previous comment was more about "how it behaves without explicitly setting the argument", and hence I'd like to see this UT passes w/o specifying it to 0.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I added a test for the case

Copy link
Contributor

Choose a reason for hiding this comment

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

sry for confusing, I misread - this is the test for encode.

could you apply this diff - we want to test both defaulting logic (in decode), and encode for non-default logic: https://gist.github.com/Huang-Wei/d86f188b4e85b48ad4e3e4aa4bd427da

@Huang-Wei
Copy link
Contributor

One comment ^^ and #559 (comment)

Copy link
Contributor

@Huang-Wei Huang-Wei left a comment

Choose a reason for hiding this comment

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

Final comments. (you can resolve them along with squashing into two commits: one for core changes, the other for code generation). Thanks.

apis/config/v1/types.go Outdated Show resolved Hide resolved
@@ -1022,6 +1024,7 @@ profiles:
apiVersion: kubescheduler.config.k8s.io/v1
kind: CoschedulingArgs
permitWaitingTimeSeconds: 10
podGroupBackoffTime: 0
Copy link
Contributor

Choose a reason for hiding this comment

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

sry for confusing, I misread - this is the test for encode.

could you apply this diff - we want to test both defaulting logic (in decode), and encode for non-default logic: https://gist.github.com/Huang-Wei/d86f188b4e85b48ad4e3e4aa4bd427da

@KunWuLuan
Copy link
Member Author

No problem, but in this diff, we set default backoff time to 60, not to 0, if there is not any args in profile, is this same with our expectation?

Signed-off-by: KunWuLuan <kunwuluan@gmail.com>
@Huang-Wei
Copy link
Contributor

No problem, but in this diff, we set default backoff time to 60, not to 0, if there is not any args in profile, is this same with our expectation?

That was "PermitWaitingTimeSeconds" :) not backoff time. PermitWaitingTimeSeconds defaults to 60 as-is; Backoff time defaults to 0. The logic is accurate.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jul 25, 2023
@Huang-Wei
Copy link
Contributor

Added release note.

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 25, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Huang-Wei, KunWuLuan

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:

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 k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 25, 2023
@k8s-ci-robot k8s-ci-robot merged commit fb9bf41 into kubernetes-sigs:master Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants