Skip to content

Commit

Permalink
Allow decrease reclaimable pods to 0 for suspended job (#1277)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaroslava-serdiuk committed Oct 28, 2023
1 parent d37b3ce commit 1684bf8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/webhooks/workload_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,14 +388,17 @@ func validateReclaimablePodsUpdate(newObj, oldObj *kueue.Workload, basePath *fie
for i := range newObj.Status.ReclaimablePods {
newCount := &newObj.Status.ReclaimablePods[i]
newNames.Insert(newCount.Name)
if !workload.HasQuotaReservation(newObj) && newCount.Count == 0 {
continue
}
oldCount, found := knowPodSets[newCount.Name]
if found && newCount.Count < oldCount.Count {
ret = append(ret, field.Invalid(basePath.Key(newCount.Name).Child("count"), newCount.Count, fmt.Sprintf("cannot be less then %d", oldCount.Count)))
}
}

for name := range knowPodSets {
if !newNames.Has(name) {
if workload.HasQuotaReservation(newObj) && !newNames.Has(name) {
ret = append(ret, field.Required(basePath.Key(name), "cannot be removed"))
}
}
Expand Down
32 changes: 32 additions & 0 deletions pkg/webhooks/workload_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,38 @@ func TestValidateWorkloadUpdate(t *testing.T) {
field.Required(field.NewPath("status", "reclaimablePods").Key("ps2"), ""),
},
},
"reclaimable pod count can go to 0 if the job is suspended": {
before: testingutil.MakeWorkload(testWorkloadName, testWorkloadNamespace).
PodSets(
*testingutil.MakePodSet("ps1", 3).Obj(),
*testingutil.MakePodSet("ps2", 3).Obj(),
).
ReserveQuota(
testingutil.MakeAdmission("cluster-queue").
PodSets(kueue.PodSetAssignment{Name: "ps1"}, kueue.PodSetAssignment{Name: "ps2"}).
Obj(),
).
ReclaimablePods(
kueue.ReclaimablePod{Name: "ps1", Count: 2},
kueue.ReclaimablePod{Name: "ps2", Count: 1},
).
Obj(),
after: testingutil.MakeWorkload(testWorkloadName, testWorkloadNamespace).
PodSets(
*testingutil.MakePodSet("ps1", 3).Obj(),
*testingutil.MakePodSet("ps2", 3).Obj(),
).
AdmissionChecks(kueue.AdmissionCheckState{
PodSetUpdates: []kueue.PodSetUpdate{{Name: "ps1"}, {Name: "ps2"}},
State: kueue.CheckStateReady,
}).
ReclaimablePods(
kueue.ReclaimablePod{Name: "ps1", Count: 0},
kueue.ReclaimablePod{Name: "ps2", Count: 1},
).
Obj(),
wantErr: nil,
},
"priorityClassSource should not be updated": {
before: testingutil.MakeWorkload(testWorkloadName, testWorkloadNamespace).Queue("q").
PriorityClass("test-class").PriorityClassSource(constants.PodPriorityClassSource).
Expand Down

0 comments on commit 1684bf8

Please sign in to comment.