diff --git a/pkg/webhook/pod/mutating/cluster_colocation_profile.go b/pkg/webhook/pod/mutating/cluster_colocation_profile.go index f709d482f..cf05d78a2 100644 --- a/pkg/webhook/pod/mutating/cluster_colocation_profile.go +++ b/pkg/webhook/pod/mutating/cluster_colocation_profile.go @@ -210,6 +210,7 @@ func (h *PodMutatingHandler) doMutateByColocationProfile(ctx context.Context, po } pod.Spec.PriorityClassName = profile.Spec.PriorityClassName pod.Spec.Priority = pointer.Int32(priorityClass.Value) + pod.Spec.PreemptionPolicy = priorityClass.PreemptionPolicy } if profile.Spec.KoordinatorPriority != nil { diff --git a/pkg/webhook/pod/mutating/cluster_colocation_profile_test.go b/pkg/webhook/pod/mutating/cluster_colocation_profile_test.go index 7121d7fc1..b17a76572 100644 --- a/pkg/webhook/pod/mutating/cluster_colocation_profile_test.go +++ b/pkg/webhook/pod/mutating/cluster_colocation_profile_test.go @@ -68,6 +68,7 @@ func newAdmissionRequest(op admissionv1.Operation, object, oldObject runtime.Raw } func TestClusterColocationProfileMutatingPod(t *testing.T) { + preemptionPolicy := corev1.PreemptionPolicy("fakePreemptionPolicy") testCases := []struct { name string pod *corev1.Pod @@ -210,6 +211,7 @@ func TestClusterColocationProfileMutatingPod(t *testing.T) { SchedulerName: "koordinator-scheduler", Priority: pointer.Int32(extension.PriorityBatchValueMax), PriorityClassName: "koordinator-batch", + PreemptionPolicy: &preemptionPolicy, }, }, }, @@ -304,6 +306,7 @@ func TestClusterColocationProfileMutatingPod(t *testing.T) { SchedulerName: "koordinator-scheduler", Priority: pointer.Int32(extension.PriorityBatchValueMax), PriorityClassName: "koordinator-batch", + PreemptionPolicy: &preemptionPolicy, }, }, }, @@ -394,6 +397,7 @@ func TestClusterColocationProfileMutatingPod(t *testing.T) { SchedulerName: "koordinator-scheduler", Priority: pointer.Int32(extension.PriorityBatchValueMax), PriorityClassName: "koordinator-batch", + PreemptionPolicy: &preemptionPolicy, }, }, }, @@ -531,6 +535,7 @@ func TestClusterColocationProfileMutatingPod(t *testing.T) { SchedulerName: "koordinator-scheduler", Priority: pointer.Int32(extension.PriorityBatchValueMax), PriorityClassName: "koordinator-batch", + PreemptionPolicy: &preemptionPolicy, }, }, }, @@ -930,6 +935,7 @@ func TestClusterColocationProfileMutatingPod(t *testing.T) { SchedulerName: "koordinator-scheduler", Priority: pointer.Int32(extension.PriorityBatchValueMax), PriorityClassName: "koordinator-batch", + PreemptionPolicy: &preemptionPolicy, }, }, }, @@ -1069,6 +1075,7 @@ func TestClusterColocationProfileMutatingPod(t *testing.T) { SchedulerName: "koordinator-scheduler", Priority: pointer.Int32(extension.PriorityBatchValueMax), PriorityClassName: "koordinator-batch", + PreemptionPolicy: &preemptionPolicy, }, }, }, @@ -1208,6 +1215,7 @@ func TestClusterColocationProfileMutatingPod(t *testing.T) { SchedulerName: "koordinator-scheduler", Priority: pointer.Int32(extension.PriorityBatchValueMax), PriorityClassName: "koordinator-batch", + PreemptionPolicy: &preemptionPolicy, }, }, }, @@ -1350,6 +1358,7 @@ func TestClusterColocationProfileMutatingPod(t *testing.T) { SchedulerName: "koordinator-scheduler", Priority: pointer.Int32(extension.PriorityBatchValueMax), PriorityClassName: "koordinator-batch", + PreemptionPolicy: &preemptionPolicy, }, }, }, @@ -1494,6 +1503,7 @@ func TestClusterColocationProfileMutatingPod(t *testing.T) { SchedulerName: "koordinator-scheduler", Priority: pointer.Int32(extension.PriorityBatchValueMax), PriorityClassName: "koordinator-batch", + PreemptionPolicy: &preemptionPolicy, }, }, }, @@ -1638,6 +1648,7 @@ func TestClusterColocationProfileMutatingPod(t *testing.T) { SchedulerName: "koordinator-scheduler", Priority: pointer.Int32(extension.PriorityBatchValueMax), PriorityClassName: "koordinator-batch", + PreemptionPolicy: &preemptionPolicy, }, }, }, @@ -1670,7 +1681,8 @@ func TestClusterColocationProfileMutatingPod(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "koordinator-batch", }, - Value: extension.PriorityBatchValueMax, + Value: extension.PriorityBatchValueMax, + PreemptionPolicy: &preemptionPolicy, } err = client.Create(context.TODO(), batchPriorityClass) assert.NoError(err)