mirror of https://github.com/k3s-io/k3s
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. ```pull/6/head
commit
462d9f223e
|
@ -157,9 +157,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