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

Priority-based exclusive placement #687

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/jobset/v1alpha2/jobset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const (
// job placement per topology group (defined as the label value).
// If set at the ReplicatedJob level, all child jobs from the target ReplicatedJobs will be scheduled
// using exclusive job placement per topology group.
// Exclusive placement is enforced within a priority level.
ExclusiveKey string = "alpha.jobset.sigs.k8s.io/exclusive-topology"
// NodeSelectorStrategyKey is an annotation that acts as a flag, the value does not matter.
// If set, the JobSet controller will automatically inject nodeSelectors for the JobSetNameKey label to
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module sigs.k8s.io/jobset

go 1.22.0
go 1.23

require (
github.com/google/go-cmp v0.6.0
Expand Down
4 changes: 4 additions & 0 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ const (
// the JobSet is currently on.
RestartsKey = "jobset.sigs.k8s.io/restart-attempt"

// PriorityKey is a label key to record the pod priority. This is needed to enfroce exclusive placement
ahg-g marked this conversation as resolved.
Show resolved Hide resolved
// only among jobs within the same priority.
PriorityKey = "jobset.sigs.k8s.io/priority"

// MaxParallelism defines the maximum number of parallel Job creations/deltions that
// the JobSet controller can perform.
MaxParallelism = 50
Expand Down
9 changes: 9 additions & 0 deletions pkg/webhooks/pod_mutating_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

jobset "sigs.k8s.io/jobset/api/jobset/v1alpha2"
"sigs.k8s.io/jobset/pkg/constants"
)

// +kubebuilder:webhook:path=/mutate--v1-pod,mutating=true,failurePolicy=fail,groups="",resources=pods,verbs=create,versions=v1,name=mpod.kb.io,sideEffects=None,admissionReviewVersions=v1
Expand Down Expand Up @@ -82,6 +83,9 @@ func (p *podWebhook) Default(ctx context.Context, obj runtime.Object) error {
// scheduled on.
func (p *podWebhook) patchPod(ctx context.Context, pod *corev1.Pod) error {
log := ctrl.LoggerFrom(ctx)
if pod.Spec.Priority != nil {
pod.Labels[constants.PriorityKey] = fmt.Sprint(*pod.Spec.Priority)
}
if pod.Annotations[batchv1.JobCompletionIndexAnnotation] == "0" {
log.V(3).Info(fmt.Sprintf("pod webhook: setting exclusive affinities for pod: %s", pod.Name))
setExclusiveAffinities(pod)
Expand Down Expand Up @@ -128,6 +132,11 @@ func setExclusiveAffinities(pod *corev1.Pod) {
Operator: metav1.LabelSelectorOpNotIn,
Values: []string{pod.Labels[jobset.JobKey]},
},
{
Key: constants.PriorityKey,
Operator: metav1.LabelSelectorOpIn,
Values: []string{pod.Labels[constants.PriorityKey]},
},
}},
TopologyKey: pod.Annotations[jobset.ExclusiveKey],
NamespaceSelector: &metav1.LabelSelector{},
Expand Down