@@ -28,10 +28,10 @@ import (
28
28
"k8s.io/apimachinery/pkg/labels"
29
29
"k8s.io/apiserver/pkg/admission"
30
30
genericadmissioninitializers "k8s.io/apiserver/pkg/admission/initializer"
31
- utilfeature "k8s.io/apiserver/pkg/util/feature"
32
31
"k8s.io/client-go/informers"
33
32
"k8s.io/client-go/kubernetes"
34
33
schedulingv1listers "k8s.io/client-go/listers/scheduling/v1"
34
+ "k8s.io/component-base/featuregate"
35
35
"k8s.io/kubernetes/pkg/apis/core"
36
36
api "k8s.io/kubernetes/pkg/apis/core"
37
37
"k8s.io/kubernetes/pkg/apis/scheduling"
@@ -54,12 +54,15 @@ func Register(plugins *admission.Plugins) {
54
54
// Plugin is an implementation of admission.Interface.
55
55
type Plugin struct {
56
56
* admission.Handler
57
- client kubernetes.Interface
58
- lister schedulingv1listers.PriorityClassLister
57
+ client kubernetes.Interface
58
+ lister schedulingv1listers.PriorityClassLister
59
+ resourceQuotaFeatureGateEnabled bool
60
+ nonPreemptingPriority bool
59
61
}
60
62
61
63
var _ admission.MutationInterface = & Plugin {}
62
64
var _ admission.ValidationInterface = & Plugin {}
65
+ var _ genericadmissioninitializers.WantsFeatures = & Plugin {}
63
66
var _ = genericadmissioninitializers .WantsExternalKubeInformerFactory (& Plugin {})
64
67
var _ = genericadmissioninitializers .WantsExternalKubeClientSet (& Plugin {})
65
68
@@ -81,6 +84,12 @@ func (p *Plugin) ValidateInitialization() error {
81
84
return nil
82
85
}
83
86
87
+ // InspectFeatureGates allows setting bools without taking a dep on a global variable
88
+ func (p * Plugin ) InspectFeatureGates (featureGates featuregate.FeatureGate ) {
89
+ p .nonPreemptingPriority = featureGates .Enabled (features .NonPreemptingPriority )
90
+ p .resourceQuotaFeatureGateEnabled = featureGates .Enabled (features .ResourceQuotaScopeSelectors )
91
+ }
92
+
84
93
// SetExternalKubeClientSet implements the WantsInternalKubeClientSet interface.
85
94
func (p * Plugin ) SetExternalKubeClientSet (client kubernetes.Interface ) {
86
95
p .client = client
@@ -106,7 +115,6 @@ func (p *Plugin) Admit(ctx context.Context, a admission.Attributes, o admission.
106
115
if len (a .GetSubresource ()) != 0 {
107
116
return nil
108
117
}
109
-
110
118
switch a .GetResource ().GroupResource () {
111
119
case podResource :
112
120
if operation == admission .Create || operation == admission .Update {
@@ -189,8 +197,12 @@ func (p *Plugin) admitPod(a admission.Attributes) error {
189
197
pod .Spec .PriorityClassName = pcName
190
198
} else {
191
199
pcName := pod .Spec .PriorityClassName
192
- if ! priorityClassPermittedInNamespace (pcName , a .GetNamespace ()) {
193
- return admission .NewForbidden (a , fmt .Errorf ("pods with %v priorityClass is not permitted in %v namespace" , pcName , a .GetNamespace ()))
200
+ // If ResourceQuotaScopeSelectors is enabled, we should let pods with critical priorityClass to be created
201
+ // any namespace where administrator wants it to be created.
202
+ if ! p .resourceQuotaFeatureGateEnabled {
203
+ if ! priorityClassPermittedInNamespace (pcName , a .GetNamespace ()) {
204
+ return admission .NewForbidden (a , fmt .Errorf ("pods with %v priorityClass is not permitted in %v namespace" , pcName , a .GetNamespace ()))
205
+ }
194
206
}
195
207
196
208
// Try resolving the priority class name.
@@ -212,7 +224,7 @@ func (p *Plugin) admitPod(a admission.Attributes) error {
212
224
}
213
225
pod .Spec .Priority = & priority
214
226
215
- if utilfeature . DefaultFeatureGate . Enabled ( features . NonPreemptingPriority ) {
227
+ if p . nonPreemptingPriority {
216
228
var corePolicy core.PreemptionPolicy
217
229
if preemptionPolicy != nil {
218
230
corePolicy = core .PreemptionPolicy (* preemptionPolicy )
0 commit comments