Skip to content

Commit

Permalink
fix priority admission conflict
Browse files Browse the repository at this point in the history
when we set priorityclass koord-xxx with preemptionPolicy=Never,
priority admission refuse to create pod with error like this:
```text
pods "test" is forbidden: the string value of PreemptionPolicy (Never)
must not be provided in pod spec; priority admission controller computed
PreemptLowerPriority from the given PriorityClass name
```

we overwrite PriorityClassName/Priority in cluster_colocation_profile,
so as well PreemptionPolicy.

see
https://github.com/kubernetes/kubernetes/blob/master/plugin/pkg/admission/priority/admission.go#L188

Signed-off-by: j4ckstraw <j4ckstraw@foxmail.com>
  • Loading branch information
j4ckstraw committed Mar 21, 2024
1 parent 0448219 commit 8457454
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/webhook/pod/mutating/cluster_colocation_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 13 additions & 1 deletion pkg/webhook/pod/mutating/cluster_colocation_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -210,6 +211,7 @@ func TestClusterColocationProfileMutatingPod(t *testing.T) {
SchedulerName: "koordinator-scheduler",
Priority: pointer.Int32(extension.PriorityBatchValueMax),
PriorityClassName: "koordinator-batch",
PreemptionPolicy: &preemptionPolicy,
},
},
},
Expand Down Expand Up @@ -304,6 +306,7 @@ func TestClusterColocationProfileMutatingPod(t *testing.T) {
SchedulerName: "koordinator-scheduler",
Priority: pointer.Int32(extension.PriorityBatchValueMax),
PriorityClassName: "koordinator-batch",
PreemptionPolicy: &preemptionPolicy,
},
},
},
Expand Down Expand Up @@ -394,6 +397,7 @@ func TestClusterColocationProfileMutatingPod(t *testing.T) {
SchedulerName: "koordinator-scheduler",
Priority: pointer.Int32(extension.PriorityBatchValueMax),
PriorityClassName: "koordinator-batch",
PreemptionPolicy: &preemptionPolicy,
},
},
},
Expand Down Expand Up @@ -531,6 +535,7 @@ func TestClusterColocationProfileMutatingPod(t *testing.T) {
SchedulerName: "koordinator-scheduler",
Priority: pointer.Int32(extension.PriorityBatchValueMax),
PriorityClassName: "koordinator-batch",
PreemptionPolicy: &preemptionPolicy,
},
},
},
Expand Down Expand Up @@ -930,6 +935,7 @@ func TestClusterColocationProfileMutatingPod(t *testing.T) {
SchedulerName: "koordinator-scheduler",
Priority: pointer.Int32(extension.PriorityBatchValueMax),
PriorityClassName: "koordinator-batch",
PreemptionPolicy: &preemptionPolicy,
},
},
},
Expand Down Expand Up @@ -1069,6 +1075,7 @@ func TestClusterColocationProfileMutatingPod(t *testing.T) {
SchedulerName: "koordinator-scheduler",
Priority: pointer.Int32(extension.PriorityBatchValueMax),
PriorityClassName: "koordinator-batch",
PreemptionPolicy: &preemptionPolicy,
},
},
},
Expand Down Expand Up @@ -1208,6 +1215,7 @@ func TestClusterColocationProfileMutatingPod(t *testing.T) {
SchedulerName: "koordinator-scheduler",
Priority: pointer.Int32(extension.PriorityBatchValueMax),
PriorityClassName: "koordinator-batch",
PreemptionPolicy: &preemptionPolicy,
},
},
},
Expand Down Expand Up @@ -1350,6 +1358,7 @@ func TestClusterColocationProfileMutatingPod(t *testing.T) {
SchedulerName: "koordinator-scheduler",
Priority: pointer.Int32(extension.PriorityBatchValueMax),
PriorityClassName: "koordinator-batch",
PreemptionPolicy: &preemptionPolicy,
},
},
},
Expand Down Expand Up @@ -1494,6 +1503,7 @@ func TestClusterColocationProfileMutatingPod(t *testing.T) {
SchedulerName: "koordinator-scheduler",
Priority: pointer.Int32(extension.PriorityBatchValueMax),
PriorityClassName: "koordinator-batch",
PreemptionPolicy: &preemptionPolicy,
},
},
},
Expand Down Expand Up @@ -1638,6 +1648,7 @@ func TestClusterColocationProfileMutatingPod(t *testing.T) {
SchedulerName: "koordinator-scheduler",
Priority: pointer.Int32(extension.PriorityBatchValueMax),
PriorityClassName: "koordinator-batch",
PreemptionPolicy: &preemptionPolicy,
},
},
},
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8457454

Please sign in to comment.