mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Updated priority of mirror pod by PriorityClass.
Signed-off-by: Da K. Ma <madaxa@cn.ibm.com>
This commit is contained in:
parent
40b0c5516a
commit
a7c62eec8f
@ -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"))
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user