Skip to content

Commit

Permalink
Prevent cluster queue webhook from panicking for existing resources (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
astefanutti committed Jan 30, 2024
1 parent 38cedb1 commit f2cba29
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/webhooks/clusterqueue_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ func ValidateClusterQueueUpdate(newObj, oldObj *kueue.ClusterQueue) field.ErrorL

func validatePreemption(preemption *kueue.ClusterQueuePreemption, path *field.Path) field.ErrorList {
var allErrs field.ErrorList
if preemption.ReclaimWithinCohort == kueue.PreemptionPolicyNever && preemption.BorrowWithinCohort.Policy != kueue.BorrowWithinCohortPolicyNever {
if preemption.ReclaimWithinCohort == kueue.PreemptionPolicyNever &&
preemption.BorrowWithinCohort != nil &&
preemption.BorrowWithinCohort.Policy != kueue.BorrowWithinCohortPolicyNever {
allErrs = append(allErrs, field.Invalid(path, preemption, "reclaimWithinCohort=Never and borrowWithinCohort.Policy!=Never"))
}
return allErrs
Expand Down
13 changes: 13 additions & 0 deletions pkg/webhooks/clusterqueue_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,19 @@ func TestValidateClusterQueue(t *testing.T) {
},
},
},
{
name: "existing cluster queue created with older Kueue version that has a nil borrowWithinCohort field",
clusterQueue: &kueue.ClusterQueue{
ObjectMeta: metav1.ObjectMeta{
Name: "cluster-queue",
},
Spec: kueue.ClusterQueueSpec{
Preemption: &kueue.ClusterQueuePreemption{
ReclaimWithinCohort: kueue.PreemptionPolicyNever,
},
},
},
},
}

for _, tc := range testcases {
Expand Down

0 comments on commit f2cba29

Please sign in to comment.