Skip to content

Commit

Permalink
[webhook/workload] Limit the number of variable count podSets
Browse files Browse the repository at this point in the history
  • Loading branch information
trasc committed Jun 6, 2023
1 parent 880d057 commit 9d0a2be
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/webhooks/workload_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,17 @@ func ValidateWorkload(obj *kueue.Workload) field.ErrorList {
var allErrs field.ErrorList
specPath := field.NewPath("spec")

variableCountPosets := 0
for i := range obj.Spec.PodSets {
allErrs = append(allErrs, validatePodSet(&obj.Spec.PodSets[i], specPath.Child("podSets").Index(i))...)
ps := &obj.Spec.PodSets[i]
allErrs = append(allErrs, validatePodSet(ps, specPath.Child("podSets").Index(i))...)
if pointer.Int32Deref(ps.MinCount, ps.Count) != ps.Count {
variableCountPosets++
}
}

if variableCountPosets > 1 {
allErrs = append(allErrs, field.Invalid(specPath.Child("podSets"), variableCountPosets, "at most one podSet can have variable count"))
}

if len(obj.Spec.PriorityClassName) > 0 {
Expand Down
11 changes: 11 additions & 0 deletions pkg/webhooks/workload_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,17 @@ func TestValidateWorkload(t *testing.T) {
field.Forbidden(podSetsPath.Index(0).Child("minCount"), ""),
},
},
"too many variable count podSets": {
workload: testingutil.MakeWorkload(testWorkloadName, testWorkloadNamespace).
PodSets(
*testingutil.MakePodSet("ps1", 3).SetMinimumCount(2).Obj(),
*testingutil.MakePodSet("ps2", 3).SetMinimumCount(1).Obj(),
).
Obj(),
wantErr: field.ErrorList{
field.Invalid(podSetsPath, nil, ""),
},
},
}
for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
Expand Down

0 comments on commit 9d0a2be

Please sign in to comment.