diff --git a/plugin/pkg/admission/priority/admission.go b/plugin/pkg/admission/priority/admission.go index a06392c4d5c..265f098d25f 100644 --- a/plugin/pkg/admission/priority/admission.go +++ b/plugin/pkg/admission/priority/admission.go @@ -156,9 +156,7 @@ func (p *PriorityPlugin) admitPod(a admission.Attributes) error { if !ok { return errors.NewBadRequest("resource was marked with kind Pod but was unable to be converted") } - if _, isMirrorPod := pod.Annotations[api.MirrorPodAnnotationKey]; isMirrorPod { - return nil - } + // Make sure that the client has not set `priority` at the time of pod creation. if operation == admission.Create && pod.Spec.Priority != nil { return admission.NewForbidden(a, fmt.Errorf("the integer value of priority must not be provided in pod spec. Priority admission controller populates the value from the given PriorityClass name")) diff --git a/plugin/pkg/admission/priority/admission_test.go b/plugin/pkg/admission/priority/admission_test.go index cf159efffdd..c9122ac63f0 100644 --- a/plugin/pkg/admission/priority/admission_test.go +++ b/plugin/pkg/admission/priority/admission_test.go @@ -316,6 +316,39 @@ func TestPodAdmission(t *testing.T) { PriorityClassName: "system-cluster-critical", }, }, + // pod[5]: mirror Pod with a system priority class name + { + ObjectMeta: metav1.ObjectMeta{ + Name: "mirror-pod-w-system-priority", + Namespace: "namespace", + Annotations: map[string]string{api.MirrorPodAnnotationKey: ""}, + }, + Spec: api.PodSpec{ + Containers: []api.Container{ + { + Name: containerName, + }, + }, + PriorityClassName: "system-cluster-critical", + }, + }, + // pod[6]: mirror Pod with integer value of priority + { + ObjectMeta: metav1.ObjectMeta{ + Name: "mirror-pod-w-integer-priority", + Namespace: "namespace", + Annotations: map[string]string{api.MirrorPodAnnotationKey: ""}, + }, + Spec: api.PodSpec{ + Containers: []api.Container{ + { + Name: containerName, + }, + }, + PriorityClassName: "default1", + Priority: &intPriority, + }, + }, } // Enable PodPriority feature gate. utilfeature.DefaultFeatureGate.Set(fmt.Sprintf("%s=true", features.PodPriority)) @@ -378,6 +411,20 @@ func TestPodAdmission(t *testing.T) { 0, true, }, + { + "mirror pod with system priority class", + []*scheduling.PriorityClass{}, + *pods[5], + SystemCriticalPriority, + false, + }, + { + "mirror pod with integer priority", + []*scheduling.PriorityClass{}, + *pods[6], + 0, + true, + }, } for _, test := range tests {