Skip to content

Commit 31d27a5

Browse files
authored
Automated cherry pick of #7299: Update PriorityClass only for WorkloadPriorityClassSource. (#7306)
* Update PriorityClass only for WorkloadPriorityClassSource. * Fix after cherry-pick.
1 parent 9cb13c4 commit 31d27a5

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

pkg/controller/jobframework/reconciler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,8 @@ func (r *JobReconciler) ReconcileGenericJob(ctx context.Context, req ctrl.Reques
596596
}
597597
return ctrl.Result{}, err
598598
}
599-
// update workload priority if job's label changed
600-
if WorkloadPriorityClassName(object) != wl.Spec.PriorityClassName {
599+
// Update workload priority if job's label changed.
600+
if wl.Spec.PriorityClassSource == constants.WorkloadPriorityClassSource && WorkloadPriorityClassName(object) != wl.Spec.PriorityClassName {
601601
log.V(2).Info("Job changed priority, updating workload", "oldPriority", wl.Spec.PriorityClassName, "newPriority", WorkloadPriorityClassName(object))
602602
if _, err = r.updateWorkloadToMatchJob(ctx, job, object, wl); err != nil {
603603
log.Error(err, "Updating workload priority")

pkg/controller/jobs/job/job_controller_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2714,6 +2714,48 @@ func TestReconciler(t *testing.T) {
27142714
},
27152715
},
27162716
},
2717+
"shouldn't update workload when priority class no changes": {
2718+
job: *baseJobWrapper.
2719+
Clone().
2720+
Suspend(true).
2721+
PriorityClass(basePCWrapper.Name).
2722+
UID("test-uid").
2723+
Obj(),
2724+
wantJob: *baseJobWrapper.
2725+
Clone().
2726+
PriorityClass(basePCWrapper.Name).
2727+
UID("test-uid").
2728+
Obj(),
2729+
priorityClasses: []client.Object{
2730+
basePCWrapper.Obj(), baseWPCWrapper.Obj(),
2731+
},
2732+
workloads: []kueue.Workload{
2733+
*utiltesting.MakeWorkload("job", "ns").
2734+
Finalizers(kueue.ResourceInUseFinalizerName).
2735+
PodSets(*utiltesting.MakePodSet(kueue.DefaultPodSetName, 10).PriorityClass(basePCWrapper.Name).Request(corev1.ResourceCPU, "1").Obj()).
2736+
Queue("foo").
2737+
Priority(basePCWrapper.Value).
2738+
PriorityClassSource(constants.PodPriorityClassSource).
2739+
PriorityClass(basePCWrapper.Name).
2740+
Labels(map[string]string{
2741+
controllerconsts.JobUIDLabel: "test-uid",
2742+
}).
2743+
Obj(),
2744+
},
2745+
wantWorkloads: []kueue.Workload{
2746+
*utiltesting.MakeWorkload("job", "ns").
2747+
Finalizers(kueue.ResourceInUseFinalizerName).
2748+
PodSets(*utiltesting.MakePodSet(kueue.DefaultPodSetName, 10).PriorityClass(basePCWrapper.Name).Request(corev1.ResourceCPU, "1").Obj()).
2749+
Queue("foo").
2750+
Priority(basePCWrapper.Value).
2751+
PriorityClassSource(constants.PodPriorityClassSource).
2752+
PriorityClass(basePCWrapper.Name).
2753+
Labels(map[string]string{
2754+
controllerconsts.JobUIDLabel: "test-uid",
2755+
}).
2756+
Obj(),
2757+
},
2758+
},
27172759
"the workload without uid label is created when job's uid is longer than 63 characters": {
27182760
job: *baseJobWrapper.
27192761
Clone().

0 commit comments

Comments
 (0)