Skip to content

Commit

Permalink
Priority-based exclusive placement
Browse files Browse the repository at this point in the history
  • Loading branch information
ahg-g committed Oct 20, 2024
1 parent b92cbdc commit 77c86ea
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
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
// 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

0 comments on commit 77c86ea

Please sign in to comment.