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 pod webhook + reconciler for new "leader pod" exclusive job placement strategy #309

Merged
merged 4 commits into from
Nov 22, 2023

Conversation

danielvegamyhre
Copy link
Contributor

@danielvegamyhre danielvegamyhre commented Sep 26, 2023

Fixes #310

This PR implements the 2nd option described in the linked issue. Specifically, it adds a pod mutating and admission webhook which does the following:

  1. For leader pods, inject exclusive affinities and allow them to be created.
  2. For follower pods, reject admission attempts until the leader pod has been scheduled, then inject a nodeSelector for the same topology as the leader is scheduled on.

The pod reconciler is minimal in this PR, and only has the bare minimum logic needed to setup the indexes used by the webhook to look up pods by name and look up all pods for a job.

Once this PR is submitted, I'll create a follow-up PR with the pod reconciler changes necessary to handle race conditions that can arise in this webhook based exclusive placement strategy.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Sep 26, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: danielvegamyhre

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 requested a review from ahg-g September 26, 2023 19:19
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Sep 26, 2023
main.go Outdated Show resolved Hide resolved
pkg/util/names/names.go Outdated Show resolved Hide resolved
@danielvegamyhre danielvegamyhre changed the title [WIP] Mutating webhook for new exclusive job placement strategy [WIP] Migrate to "leader pod" exclusive job placement strategy Sep 26, 2023
@danielvegamyhre danielvegamyhre changed the title [WIP] Migrate to "leader pod" exclusive job placement strategy Add mutating webhook and pod reconciler for new "leader pod" exclusive job placement strategy Sep 26, 2023
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Sep 26, 2023
api/jobset/v1alpha2/jobset_webhook.go Outdated Show resolved Hide resolved
api/jobset/v1alpha2/jobset_webhook.go Outdated Show resolved Hide resolved
api/jobset/v1alpha2/jobset_webhook.go Outdated Show resolved Hide resolved
api/jobset/v1alpha2/jobset_webhook_test.go Outdated Show resolved Hide resolved
config/components/webhook/manifests.yaml Show resolved Hide resolved
pkg/controllers/pod_controller.go Outdated Show resolved Hide resolved
pkg/controllers/pod_controller.go Outdated Show resolved Hide resolved
pkg/controllers/pod_controller.go Outdated Show resolved Hide resolved
pkg/controllers/pod_controller.go Outdated Show resolved Hide resolved
pkg/controllers/pod_controller.go Outdated Show resolved Hide resolved
@danielvegamyhre danielvegamyhre force-pushed the scheduling branch 3 times, most recently from a76cbd1 to db2c6ec Compare September 26, 2023 23:17
api/jobset/v1alpha2/pod_webhook.go Outdated Show resolved Hide resolved
pkg/controllers/pod_controller.go Outdated Show resolved Hide resolved
pkg/controllers/pod_controller.go Outdated Show resolved Hide resolved
pkg/controllers/pod_controller.go Show resolved Hide resolved
pkg/controllers/pod_controller.go Outdated Show resolved Hide resolved
config/components/webhook/manifests.yaml Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Sep 27, 2023
@danielvegamyhre
Copy link
Contributor Author

/retest

// if Suspend is set, then we assume all jobs will be suspended also.
jobsetSuspended := js.Spec.Suspend != nil && *js.Spec.Suspend
job.Spec.Suspend = ptr.To(jobsetSuspended)

return job, nil
}

// Appends pod affinity/anti-affinity terms to the job pod template spec,
Copy link
Contributor

Choose a reason for hiding this comment

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

I remember a discussion with @vsoch around these annotations. Should we implement the new way of placements in case of users using these annotations rather than deleting this entirely?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not familiar with the context of this PR, but I think a feature of jobset definitely should be to make it easy to ask for common configurations for affinity (or other similar needs for placement). In my case, I did try using one of the defaults here, but it was slightly off for what I needed (so I couldn't use this strategy) and had to implement an entire function akin to the below, with tweaks. I would say it would make sense to:

  1. Define a list of common use cases for affinity / anti-affinity
  2. Associate them with names the user can ask for in a section of the spec
  3. Implement so it's ridiculously easy to just request a named set!

And in this case, it would make sense to only deprecate the existing when an alternative is available. It might be unlikely that someone is using them, in which case maybe OK to delete first, but perhaps adding the new sets first makes sense so if anyone is using them they aren't really angry :)

pkg/webhooks/pod_webhook.go Outdated Show resolved Hide resolved
@ahg-g
Copy link
Contributor

ahg-g commented Oct 5, 2023

You can use make build on your local environment to check for such compiler errors

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 5, 2023
pkg/webhooks/pod_admission_webhook.go Outdated Show resolved Hide resolved
pkg/webhooks/pod_mutating_webhook.go Show resolved Hide resolved
@danielvegamyhre danielvegamyhre force-pushed the scheduling branch 4 times, most recently from feed6dd to 1317dbd Compare November 18, 2023 01:04
@danielvegamyhre danielvegamyhre changed the title Add mutating webhook and pod reconciler for new "leader pod" exclusive job placement strategy Add pod webhook + reconciler for new "leader pod" exclusive job placement strategy Nov 18, 2023
@danielvegamyhre danielvegamyhre force-pushed the scheduling branch 2 times, most recently from 8860b76 to 3c08157 Compare November 19, 2023 02:57
@danielvegamyhre
Copy link
Contributor Author

/retest

pkg/controllers/jobset_controller_test.go Outdated Show resolved Hide resolved
main.go Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
return fmt.Sprintf("%s-%s-%d", jsName, rjobName, jobIndex)
}

func IsLeaderPod(pod *corev1.Pod) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

util/shared sounds repetitive, shared is just another way of saying util.

Do we really need this function here? We probably only need it in the webhook, so lets just define it there and keep this pkg named "names"

Copy link
Contributor Author

@danielvegamyhre danielvegamyhre Nov 22, 2023

Choose a reason for hiding this comment

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

I ended up needing to use this function in the pod reconciler, to check if a follower pod's nodeSelector topology value does not match the leader pod's (and check if the leader pod even exists / was killed), so that's why I placed it in this shared package. This logic was removed from this PR to simplify reviewing, but it will be in a subsequent PR.

Yeah naming this package is hard, but I do think we do need a package of shared functions used by both webhooks and controllers, to serve as a single source of truth and avoid code duplication of course.

Copy link
Contributor

Choose a reason for hiding this comment

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

util by definition is a pkg of "shared" functions, may be rename the pkg to placement to indicate that those functions are for exclusive placement.

Copy link
Contributor

Choose a reason for hiding this comment

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

you can do that in the followup PR

pkg/webhooks/pod_admission_webhook.go Outdated Show resolved Hide resolved
pkg/webhooks/pod_admission_webhook.go Show resolved Hide resolved
pkg/webhooks/pod_admission_webhook.go Outdated Show resolved Hide resolved
pkg/webhooks/pod_mutating_webhook.go Show resolved Hide resolved
@ahg-g
Copy link
Contributor

ahg-g commented Nov 22, 2023

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 22, 2023
@k8s-ci-robot k8s-ci-robot merged commit e876d9d into kubernetes-sigs:main Nov 22, 2023
10 checks passed
@danielvegamyhre danielvegamyhre mentioned this pull request Dec 12, 2023
20 tasks
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. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve scheduling throughput for exclusive job placement per topology
5 participants