mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-12 20:57:20 +00:00
Merge pull request #107432 from denkensk/graduate-nonpreemptingpriority-to-ga
Graduate NonPreemptingPriority to GA
This commit is contained in:
@@ -30,10 +30,8 @@ import (
|
||||
"k8s.io/client-go/informers"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
schedulingv1listers "k8s.io/client-go/listers/scheduling/v1"
|
||||
"k8s.io/component-base/featuregate"
|
||||
"k8s.io/kubernetes/pkg/apis/core"
|
||||
"k8s.io/kubernetes/pkg/apis/scheduling"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -51,14 +49,12 @@ func Register(plugins *admission.Plugins) {
|
||||
// Plugin is an implementation of admission.Interface.
|
||||
type Plugin struct {
|
||||
*admission.Handler
|
||||
client kubernetes.Interface
|
||||
lister schedulingv1listers.PriorityClassLister
|
||||
nonPreemptingPriority bool
|
||||
client kubernetes.Interface
|
||||
lister schedulingv1listers.PriorityClassLister
|
||||
}
|
||||
|
||||
var _ admission.MutationInterface = &Plugin{}
|
||||
var _ admission.ValidationInterface = &Plugin{}
|
||||
var _ genericadmissioninitializers.WantsFeatures = &Plugin{}
|
||||
var _ = genericadmissioninitializers.WantsExternalKubeInformerFactory(&Plugin{})
|
||||
var _ = genericadmissioninitializers.WantsExternalKubeClientSet(&Plugin{})
|
||||
|
||||
@@ -80,11 +76,6 @@ func (p *Plugin) ValidateInitialization() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// InspectFeatureGates allows setting bools without taking a dep on a global variable
|
||||
func (p *Plugin) InspectFeatureGates(featureGates featuregate.FeatureGate) {
|
||||
p.nonPreemptingPriority = featureGates.Enabled(features.NonPreemptingPriority)
|
||||
}
|
||||
|
||||
// SetExternalKubeClientSet implements the WantsInternalKubeClientSet interface.
|
||||
func (p *Plugin) SetExternalKubeClientSet(client kubernetes.Interface) {
|
||||
p.client = client
|
||||
@@ -199,15 +190,13 @@ func (p *Plugin) admitPod(a admission.Attributes) error {
|
||||
}
|
||||
pod.Spec.Priority = &priority
|
||||
|
||||
if p.nonPreemptingPriority {
|
||||
var corePolicy core.PreemptionPolicy
|
||||
if preemptionPolicy != nil {
|
||||
corePolicy = core.PreemptionPolicy(*preemptionPolicy)
|
||||
if pod.Spec.PreemptionPolicy != nil && *pod.Spec.PreemptionPolicy != corePolicy {
|
||||
return admission.NewForbidden(a, fmt.Errorf("the string value of PreemptionPolicy (%s) must not be provided in pod spec; priority admission controller computed %s from the given PriorityClass name", *pod.Spec.PreemptionPolicy, corePolicy))
|
||||
}
|
||||
pod.Spec.PreemptionPolicy = &corePolicy
|
||||
var corePolicy core.PreemptionPolicy
|
||||
if preemptionPolicy != nil {
|
||||
corePolicy = core.PreemptionPolicy(*preemptionPolicy)
|
||||
if pod.Spec.PreemptionPolicy != nil && *pod.Spec.PreemptionPolicy != corePolicy {
|
||||
return admission.NewForbidden(a, fmt.Errorf("the string value of PreemptionPolicy (%s) must not be provided in pod spec; priority admission controller computed %s from the given PriorityClass name", *pod.Spec.PreemptionPolicy, corePolicy))
|
||||
}
|
||||
pod.Spec.PreemptionPolicy = &corePolicy
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@@ -27,14 +27,11 @@ import (
|
||||
"k8s.io/apiserver/pkg/admission"
|
||||
admissiontesting "k8s.io/apiserver/pkg/admission/testing"
|
||||
"k8s.io/apiserver/pkg/authentication/user"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
"k8s.io/client-go/informers"
|
||||
featuregatetesting "k8s.io/component-base/featuregate/testing"
|
||||
api "k8s.io/kubernetes/pkg/apis/core"
|
||||
"k8s.io/kubernetes/pkg/apis/scheduling"
|
||||
v1 "k8s.io/kubernetes/pkg/apis/scheduling/v1"
|
||||
"k8s.io/kubernetes/pkg/controller"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
)
|
||||
|
||||
func addPriorityClasses(ctrl *Plugin, priorityClasses []*scheduling.PriorityClass) error {
|
||||
@@ -536,8 +533,7 @@ func TestPodAdmission(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
// Enable NonPreemptingPriority feature gate.
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.NonPreemptingPriority, true)()
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
existingClasses []*scheduling.PriorityClass
|
||||
@@ -682,7 +678,6 @@ func TestPodAdmission(t *testing.T) {
|
||||
for _, test := range tests {
|
||||
klog.V(4).Infof("starting test %q", test.name)
|
||||
ctrl := NewPlugin()
|
||||
ctrl.nonPreemptingPriority = true
|
||||
// Add existing priority classes.
|
||||
if err := addPriorityClasses(ctrl, test.existingClasses); err != nil {
|
||||
t.Errorf("Test %q: unable to add object to informer: %v", test.name, err)
|
||||
|
Reference in New Issue
Block a user