@@ -20,6 +20,8 @@ import (
20
20
"fmt"
21
21
22
22
v1 "k8s.io/api/core/v1"
23
+ schedulingv1 "k8s.io/api/scheduling/v1"
24
+ "k8s.io/apimachinery/pkg/api/errors"
23
25
"k8s.io/apimachinery/pkg/api/resource"
24
26
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25
27
kubeapi "k8s.io/kubernetes/pkg/apis/core"
@@ -34,15 +36,15 @@ import (
34
36
)
35
37
36
38
const (
37
- criticalPodName = "critical-pod"
38
- guaranteedPodName = "guaranteed"
39
- burstablePodName = "burstable"
40
- bestEffortPodName = "best-effort"
39
+ criticalPodName = "critical-pod"
40
+ guaranteedPodName = "guaranteed"
41
+ burstablePodName = "burstable"
42
+ bestEffortPodName = "best-effort"
43
+ systemCriticalPriorityName = "critical-pod-test-high-priority"
41
44
)
42
45
43
46
var _ = framework .KubeDescribe ("CriticalPod [Serial] [Disruptive] [NodeFeature:CriticalPod]" , func () {
44
47
f := framework .NewDefaultFramework ("critical-pod-test" )
45
-
46
48
ginkgo .Context ("when we need to admit a critical pod" , func () {
47
49
tempSetCurrentKubeletConfig (f , func (initialConfig * kubeletconfig.KubeletConfiguration ) {
48
50
if initialConfig .FeatureGates == nil {
@@ -56,6 +58,8 @@ var _ = framework.KubeDescribe("CriticalPod [Serial] [Disruptive] [NodeFeature:C
56
58
if ! configEnabled {
57
59
framework .Skipf ("unable to run test without dynamic kubelet config enabled." )
58
60
}
61
+ // because adminssion Priority enable, If the priority class is not found, the Pod is rejected.
62
+ systemCriticalPriority := & schedulingv1.PriorityClass {ObjectMeta : metav1.ObjectMeta {Name : systemCriticalPriorityName }, Value : scheduling .SystemCriticalPriority }
59
63
60
64
// Define test pods
61
65
nonCriticalGuaranteed := getTestPod (false , guaranteedPodName , v1.ResourceRequirements {
@@ -81,6 +85,9 @@ var _ = framework.KubeDescribe("CriticalPod [Serial] [Disruptive] [NodeFeature:C
81
85
Requests : getNodeCPUAndMemoryCapacity (f ),
82
86
})
83
87
88
+ _ , err = f .ClientSet .SchedulingV1 ().PriorityClasses ().Create (systemCriticalPriority )
89
+ gomega .Expect (err == nil || errors .IsAlreadyExists (err )).To (gomega .BeTrue (), "failed to create PriorityClasses with an error: %v" , err )
90
+
84
91
// Create pods, starting with non-critical so that the critical preempts the other pods.
85
92
f .PodClient ().CreateBatch ([]* v1.Pod {nonCriticalBestEffort , nonCriticalBurstable , nonCriticalGuaranteed })
86
93
f .PodClientNS (kubeapi .NamespaceSystem ).CreateSyncInNamespace (criticalPod , kubeapi .NamespaceSystem )
@@ -102,6 +109,8 @@ var _ = framework.KubeDescribe("CriticalPod [Serial] [Disruptive] [NodeFeature:C
102
109
f .PodClient ().DeleteSync (burstablePodName , & metav1.DeleteOptions {}, framework .DefaultPodDeletionTimeout )
103
110
f .PodClient ().DeleteSync (bestEffortPodName , & metav1.DeleteOptions {}, framework .DefaultPodDeletionTimeout )
104
111
f .PodClientNS (kubeapi .NamespaceSystem ).DeleteSyncInNamespace (criticalPodName , kubeapi .NamespaceSystem , & metav1.DeleteOptions {}, framework .DefaultPodDeletionTimeout )
112
+ err := f .ClientSet .SchedulingV1 ().PriorityClasses ().Delete (systemCriticalPriorityName , & metav1.DeleteOptions {})
113
+ framework .ExpectNoError (err )
105
114
// Log Events
106
115
logPodEvents (f )
107
116
logNodeEvents (f )
@@ -123,6 +132,7 @@ func getNodeCPUAndMemoryCapacity(f *framework.Framework) v1.ResourceList {
123
132
}
124
133
125
134
func getTestPod (critical bool , name string , resources v1.ResourceRequirements ) * v1.Pod {
135
+ value := scheduling .SystemCriticalPriority
126
136
pod := & v1.Pod {
127
137
TypeMeta : metav1.TypeMeta {
128
138
Kind : "Pod" ,
@@ -144,8 +154,8 @@ func getTestPod(critical bool, name string, resources v1.ResourceRequirements) *
144
154
pod .ObjectMeta .Annotations = map [string ]string {
145
155
kubelettypes .ConfigSourceAnnotationKey : kubelettypes .FileSource ,
146
156
}
147
- podPriority := scheduling . SystemCriticalPriority
148
- pod .Spec .Priority = & podPriority
157
+ pod . Spec . PriorityClassName = systemCriticalPriorityName
158
+ pod .Spec .Priority = & value
149
159
150
160
gomega .Expect (kubelettypes .IsCriticalPod (pod )).To (gomega .BeTrue (), "pod should be a critical pod" )
151
161
} else {
0 commit comments