Merge pull request #58485 from k82cn/k8s_58471

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Updated priority of mirror pod by PriorityClass.

Signed-off-by: Da K. Ma <madaxa@cn.ibm.com>

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes #58471 

**Release note**:
```release-note
Updated priority of mirror pod according to PriorityClassName.
```
This commit is contained in:
Kubernetes Submit Queue 2018-01-26 12:23:00 -08:00 committed by GitHub
commit 462d9f223e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 3 deletions

View File

@ -157,9 +157,7 @@ func (p *PriorityPlugin) admitPod(a admission.Attributes) error {
if !ok { if !ok {
return errors.NewBadRequest("resource was marked with kind Pod but was unable to be converted") 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. // Make sure that the client has not set `priority` at the time of pod creation.
if operation == admission.Create && pod.Spec.Priority != nil { 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")) 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"))

View File

@ -316,6 +316,39 @@ func TestPodAdmission(t *testing.T) {
PriorityClassName: "system-cluster-critical", 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. // Enable PodPriority feature gate.
utilfeature.DefaultFeatureGate.Set(fmt.Sprintf("%s=true", features.PodPriority)) utilfeature.DefaultFeatureGate.Set(fmt.Sprintf("%s=true", features.PodPriority))
@ -378,6 +411,20 @@ func TestPodAdmission(t *testing.T) {
0, 0,
true, 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 { for _, test := range tests {