Skip to content

Commit

Permalink
[webhook/workload] Validate minCount
Browse files Browse the repository at this point in the history
  • Loading branch information
trasc committed Jun 7, 2023
1 parent 2844d17 commit 49989ba
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/webhooks/workload_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ func validatePodSet(ps *kueue.PodSet, path *field.Path) field.ErrorList {
for ci := range ps.Template.Spec.Containers {
allErrs = append(allErrs, validateContainer(&ps.Template.Spec.Containers[ci], cPath.Index(ci))...)
}

if min := pointer.Int32Deref(ps.MinCount, ps.Count); min > ps.Count || min < 0 {
allErrs = append(allErrs, field.Forbidden(path.Child("minCount"), fmt.Sprintf("%d should be positive and less or equal to %d", min, ps.Count)))
}

return allErrs
}

Expand Down
20 changes: 20 additions & 0 deletions pkg/webhooks/workload_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,26 @@ func TestValidateWorkload(t *testing.T) {
field.NotSupported(statusPath.Child("reclaimablePods").Key("ps2").Child("name"), nil, nil),
},
},
"invalid podSet minCount (negative)": {
workload: testingutil.MakeWorkload(testWorkloadName, testWorkloadNamespace).
PodSets(
*testingutil.MakePodSet("ps1", 3).SetMinimumCount(-1).Obj(),
).
Obj(),
wantErr: field.ErrorList{
field.Forbidden(podSetsPath.Index(0).Child("minCount"), ""),
},
},
"invalid podSet minCount (too big)": {
workload: testingutil.MakeWorkload(testWorkloadName, testWorkloadNamespace).
PodSets(
*testingutil.MakePodSet("ps1", 3).SetMinimumCount(4).Obj(),
).
Obj(),
wantErr: field.ErrorList{
field.Forbidden(podSetsPath.Index(0).Child("minCount"), ""),
},
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
Expand Down

0 comments on commit 49989ba

Please sign in to comment.