From 79be7c45183feacb9c5817af9f5a8116f46c6e91 Mon Sep 17 00:00:00 2001 From: Traian Schiau Date: Tue, 6 Jun 2023 13:25:51 +0300 Subject: [PATCH] [webhook/workload] Limit the number of variable count podSets --- pkg/webhooks/workload_webhook.go | 11 ++++++++++- pkg/webhooks/workload_webhook_test.go | 11 +++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pkg/webhooks/workload_webhook.go b/pkg/webhooks/workload_webhook.go index bff012c46a..4b6e04551e 100644 --- a/pkg/webhooks/workload_webhook.go +++ b/pkg/webhooks/workload_webhook.go @@ -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 ps.MinCount != nil { + variableCountPosets++ + } + } + + if variableCountPosets > 1 { + allErrs = append(allErrs, field.Invalid(specPath.Child("podSets"), variableCountPosets, "at most one podSet can use minCount")) } if len(obj.Spec.PriorityClassName) > 0 { diff --git a/pkg/webhooks/workload_webhook_test.go b/pkg/webhooks/workload_webhook_test.go index 5c69f4b94e..6112ee8902 100644 --- a/pkg/webhooks/workload_webhook_test.go +++ b/pkg/webhooks/workload_webhook_test.go @@ -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) {