Merge pull request #107432 from denkensk/graduate-nonpreemptingpriority-to-ga

Graduate NonPreemptingPriority to GA
This commit is contained in:
Kubernetes Prow Robot 2022-02-08 11:05:03 -08:00 committed by GitHub
commit 24e5d1fdb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 28 additions and 256 deletions

View File

@ -8667,7 +8667,7 @@
"type": "object"
},
"preemptionPolicy": {
"description": "PreemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset. This field is beta-level, gated by the NonPreemptingPriority feature-gate.",
"description": "PreemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset.",
"type": "string"
},
"priority": {
@ -14629,7 +14629,7 @@
"description": "Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata"
},
"preemptionPolicy": {
"description": "PreemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset. This field is beta-level, gated by the NonPreemptingPriority feature-gate.",
"description": "PreemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset.",
"type": "string"
},
"value": {

View File

@ -4309,7 +4309,7 @@
"type": "object"
},
"preemptionPolicy": {
"description": "PreemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset. This field is beta-level, gated by the NonPreemptingPriority feature-gate.",
"description": "PreemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset.",
"type": "string"
},
"priority": {

View File

@ -2999,7 +2999,7 @@
"type": "object"
},
"preemptionPolicy": {
"description": "PreemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset. This field is beta-level, gated by the NonPreemptingPriority feature-gate.",
"description": "PreemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset.",
"type": "string"
},
"priority": {

View File

@ -2225,7 +2225,7 @@
"type": "object"
},
"preemptionPolicy": {
"description": "PreemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset. This field is beta-level, gated by the NonPreemptingPriority feature-gate.",
"description": "PreemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset.",
"type": "string"
},
"priority": {

View File

@ -2027,7 +2027,7 @@
"type": "object"
},
"preemptionPolicy": {
"description": "PreemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset. This field is beta-level, gated by the NonPreemptingPriority feature-gate.",
"description": "PreemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset.",
"type": "string"
},
"priority": {

View File

@ -26,7 +26,7 @@
"description": "Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata"
},
"preemptionPolicy": {
"description": "PreemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset. This field is beta-level, gated by the NonPreemptingPriority feature-gate.",
"description": "PreemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset.",
"type": "string"
},
"value": {

View File

@ -580,12 +580,6 @@ func dropDisabledFields(
dropDisabledCSIVolumeSourceAlphaFields(podSpec, oldPodSpec)
if !utilfeature.DefaultFeatureGate.Enabled(features.NonPreemptingPriority) &&
!podPriorityInUse(oldPodSpec) {
// Set to nil pod's PreemptionPolicy fields if the feature is disabled and the old pod
// does not specify any values for these fields.
podSpec.PreemptionPolicy = nil
}
if !utilfeature.DefaultFeatureGate.Enabled(features.IdentifyPodOS) && !podOSInUse(oldPodSpec) {
podSpec.OS = nil
}
@ -740,17 +734,6 @@ func appArmorInUse(podAnnotations map[string]string) bool {
return false
}
// podPriorityInUse returns true if the pod spec is non-nil and has Priority or PriorityClassName set.
func podPriorityInUse(podSpec *api.PodSpec) bool {
if podSpec == nil {
return false
}
if podSpec.Priority != nil || podSpec.PriorityClassName != "" {
return true
}
return false
}
// emptyDirSizeLimitInUse returns true if any pod's EmptyDir volumes use SizeLimit.
func emptyDirSizeLimitInUse(podSpec *api.PodSpec) bool {
if podSpec == nil {

View File

@ -2918,7 +2918,6 @@ type PodSpec struct {
// PreemptionPolicy is the Policy for preempting pods with lower priority.
// One of Never, PreemptLowerPriority.
// Defaults to PreemptLowerPriority if unset.
// This field is beta-level, gated by the NonPreemptingPriority feature-gate.
// +optional
PreemptionPolicy *PreemptionPolicy
// Specifies the DNS parameters of a pod.

View File

@ -19,10 +19,8 @@ package fuzzer
import (
"github.com/google/gofuzz"
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/apis/scheduling"
"k8s.io/kubernetes/pkg/features"
)
// Funcs returns the fuzzer functions for the scheduling api group.
@ -30,7 +28,7 @@ var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
return []interface{}{
func(s *scheduling.PriorityClass, c fuzz.Continue) {
c.FuzzNoCustom(s)
if utilfeature.DefaultFeatureGate.Enabled(features.NonPreemptingPriority) && s.PreemptionPolicy == nil {
if s.PreemptionPolicy == nil {
preemptLowerPriority := core.PreemptLowerPriority
s.PreemptionPolicy = &preemptLowerPriority
}

View File

@ -1,40 +0,0 @@
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package util
import (
utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/kubernetes/pkg/apis/scheduling"
"k8s.io/kubernetes/pkg/features"
)
// DropDisabledFields removes disabled fields from the PriorityClass object.
func DropDisabledFields(class, oldClass *scheduling.PriorityClass) {
if !utilfeature.DefaultFeatureGate.Enabled(features.NonPreemptingPriority) && !preemptingPriorityInUse(oldClass) {
class.PreemptionPolicy = nil
}
}
func preemptingPriorityInUse(oldClass *scheduling.PriorityClass) bool {
if oldClass == nil {
return false
}
if oldClass.PreemptionPolicy != nil {
return true
}
return false
}

View File

@ -1,109 +0,0 @@
/*
Copyright 2019 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package util
import (
"fmt"
"reflect"
"testing"
"k8s.io/apimachinery/pkg/util/diff"
utilfeature "k8s.io/apiserver/pkg/util/feature"
featuregatetesting "k8s.io/component-base/featuregate/testing"
"k8s.io/kubernetes/pkg/apis/core"
"k8s.io/kubernetes/pkg/apis/scheduling"
"k8s.io/kubernetes/pkg/features"
)
func TestDropNonPreemptingPriority(t *testing.T) {
pcWithoutNonPreemptingPriority := func() *scheduling.PriorityClass {
return &scheduling.PriorityClass{}
}
pcWithNonPreemptingPriority := func() *scheduling.PriorityClass {
preemptionPolicy := core.PreemptNever
return &scheduling.PriorityClass{
PreemptionPolicy: &preemptionPolicy,
}
}
pcInfo := []struct {
description string
hasNonPreemptingPriority bool
pc func() *scheduling.PriorityClass
}{
{
description: "PriorityClass Without NonPreemptingPriority",
hasNonPreemptingPriority: false,
pc: pcWithoutNonPreemptingPriority,
},
{
description: "PriorityClass With NonPreemptingPriority",
hasNonPreemptingPriority: true,
pc: pcWithNonPreemptingPriority,
},
{
description: "is nil",
hasNonPreemptingPriority: false,
pc: func() *scheduling.PriorityClass { return nil },
},
}
for _, enabled := range []bool{true, false} {
for _, oldPriorityClassInfo := range pcInfo {
for _, newPriorityClassInfo := range pcInfo {
oldPriorityClassHasNonPreemptingPriority, oldPriorityClass := oldPriorityClassInfo.hasNonPreemptingPriority, oldPriorityClassInfo.pc()
newPriorityClassHasNonPreemptingPriority, newPriorityClass := newPriorityClassInfo.hasNonPreemptingPriority, newPriorityClassInfo.pc()
if newPriorityClass == nil {
continue
}
t.Run(fmt.Sprintf("feature enabled=%v, old PriorityClass %v, new PriorityClass %v", enabled, oldPriorityClassInfo.description, newPriorityClassInfo.description), func(t *testing.T) {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.NonPreemptingPriority, enabled)()
DropDisabledFields(newPriorityClass, oldPriorityClass)
// old PriorityClass should never be changed
if !reflect.DeepEqual(oldPriorityClass, oldPriorityClassInfo.pc()) {
t.Errorf("old PriorityClass changed: %v", diff.ObjectReflectDiff(oldPriorityClass, oldPriorityClassInfo.pc()))
}
switch {
case enabled || oldPriorityClassHasNonPreemptingPriority:
// new PriorityClass should not be changed if the feature is enabled, or if the old PriorityClass had NonPreemptingPriority
if !reflect.DeepEqual(newPriorityClass, newPriorityClassInfo.pc()) {
t.Errorf("new PriorityClass changed: %v", diff.ObjectReflectDiff(newPriorityClass, newPriorityClassInfo.pc()))
}
case newPriorityClassHasNonPreemptingPriority:
// new PriorityClass should be changed
if reflect.DeepEqual(newPriorityClass, newPriorityClassInfo.pc()) {
t.Errorf("new PriorityClass was not changed")
}
// new PriorityClass should not have NonPreemptingPriority
if !reflect.DeepEqual(newPriorityClass, pcWithoutNonPreemptingPriority()) {
t.Errorf("new PriorityClass had PriorityClassNonPreemptingPriority: %v", diff.ObjectReflectDiff(newPriorityClass, pcWithoutNonPreemptingPriority()))
}
default:
// new PriorityClass should not need to be changed
if !reflect.DeepEqual(newPriorityClass, newPriorityClassInfo.pc()) {
t.Errorf("new PriorityClass changed: %v", diff.ObjectReflectDiff(newPriorityClass, newPriorityClassInfo.pc()))
}
}
})
}
}
}
}

View File

@ -18,10 +18,8 @@ package v1
import (
apiv1 "k8s.io/api/core/v1"
"k8s.io/api/scheduling/v1"
v1 "k8s.io/api/scheduling/v1"
"k8s.io/apimachinery/pkg/runtime"
utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/kubernetes/pkg/features"
)
func addDefaultingFuncs(scheme *runtime.Scheme) error {
@ -31,7 +29,7 @@ func addDefaultingFuncs(scheme *runtime.Scheme) error {
// SetDefaults_PriorityClass sets additional defaults compared to its counterpart
// in extensions.
func SetDefaults_PriorityClass(obj *v1.PriorityClass) {
if utilfeature.DefaultFeatureGate.Enabled(features.NonPreemptingPriority) && obj.PreemptionPolicy == nil {
if obj.PreemptionPolicy == nil {
preemptLowerPriority := apiv1.PreemptLowerPriority
obj.PreemptionPolicy = &preemptLowerPriority
}

View File

@ -23,10 +23,7 @@ import (
apiv1 "k8s.io/api/core/v1"
v1 "k8s.io/api/scheduling/v1"
"k8s.io/apimachinery/pkg/runtime"
utilfeature "k8s.io/apiserver/pkg/util/feature"
featuregatetesting "k8s.io/component-base/featuregate/testing"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/features"
// ensure types are installed
_ "k8s.io/kubernetes/pkg/apis/scheduling/install"
@ -56,9 +53,6 @@ func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
func TestSetDefaultPreemptionPolicy(t *testing.T) {
priorityClass := &v1.PriorityClass{}
// set NonPreemptingPriority true
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.NonPreemptingPriority, true)()
output := roundTrip(t, runtime.Object(priorityClass)).(*v1.PriorityClass)
if output.PreemptionPolicy == nil || *output.PreemptionPolicy != apiv1.PreemptLowerPriority {
t.Errorf("Expected PriorityClass.PreemptionPolicy value: %+v\ngot: %+v\n", apiv1.PreemptLowerPriority, output.PreemptionPolicy)

View File

@ -20,8 +20,6 @@ import (
apiv1 "k8s.io/api/core/v1"
"k8s.io/api/scheduling/v1alpha1"
runtime "k8s.io/apimachinery/pkg/runtime"
utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/kubernetes/pkg/features"
)
func addDefaultingFuncs(scheme *runtime.Scheme) error {
@ -31,7 +29,7 @@ func addDefaultingFuncs(scheme *runtime.Scheme) error {
// SetDefaults_PriorityClass sets additional defaults compared to its counterpart
// in extensions.
func SetDefaults_PriorityClass(obj *v1alpha1.PriorityClass) {
if utilfeature.DefaultFeatureGate.Enabled(features.NonPreemptingPriority) && obj.PreemptionPolicy == nil {
if obj.PreemptionPolicy == nil {
preemptLowerPriority := apiv1.PreemptLowerPriority
obj.PreemptionPolicy = &preemptLowerPriority
}

View File

@ -23,10 +23,7 @@ import (
apiv1 "k8s.io/api/core/v1"
"k8s.io/api/scheduling/v1alpha1"
"k8s.io/apimachinery/pkg/runtime"
utilfeature "k8s.io/apiserver/pkg/util/feature"
featuregatetesting "k8s.io/component-base/featuregate/testing"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/features"
// ensure types are installed
_ "k8s.io/kubernetes/pkg/apis/scheduling/install"
@ -56,9 +53,6 @@ func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
func TestSetDefaultPreempting(t *testing.T) {
priorityClass := &v1alpha1.PriorityClass{}
// set NonPreemptingPriority true
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.NonPreemptingPriority, true)()
output := roundTrip(t, runtime.Object(priorityClass)).(*v1alpha1.PriorityClass)
if output.PreemptionPolicy == nil || *output.PreemptionPolicy != apiv1.PreemptLowerPriority {
t.Errorf("Expected PriorityClass.Preempting value: %+v\ngot: %+v\n", apiv1.PreemptLowerPriority, output.PreemptionPolicy)

View File

@ -20,8 +20,6 @@ import (
apiv1 "k8s.io/api/core/v1"
"k8s.io/api/scheduling/v1beta1"
runtime "k8s.io/apimachinery/pkg/runtime"
utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/kubernetes/pkg/features"
)
func addDefaultingFuncs(scheme *runtime.Scheme) error {
@ -31,7 +29,7 @@ func addDefaultingFuncs(scheme *runtime.Scheme) error {
// SetDefaults_PriorityClass sets additional defaults compared to its counterpart
// in extensions.
func SetDefaults_PriorityClass(obj *v1beta1.PriorityClass) {
if utilfeature.DefaultFeatureGate.Enabled(features.NonPreemptingPriority) && obj.PreemptionPolicy == nil {
if obj.PreemptionPolicy == nil {
preemptLowerPriority := apiv1.PreemptLowerPriority
obj.PreemptionPolicy = &preemptLowerPriority
}

View File

@ -23,10 +23,7 @@ import (
apiv1 "k8s.io/api/core/v1"
"k8s.io/api/scheduling/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
utilfeature "k8s.io/apiserver/pkg/util/feature"
featuregatetesting "k8s.io/component-base/featuregate/testing"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/features"
// ensure types are installed
_ "k8s.io/kubernetes/pkg/apis/scheduling/install"
@ -56,9 +53,6 @@ func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
func TestSetDefaultPreempting(t *testing.T) {
priorityClass := &v1beta1.PriorityClass{}
// set NonPreemptingPriority true
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.NonPreemptingPriority, true)()
output := roundTrip(t, runtime.Object(priorityClass)).(*v1beta1.PriorityClass)
if output.PreemptionPolicy == nil || *output.PreemptionPolicy != apiv1.PreemptLowerPriority {
t.Errorf("Expected PriorityClass.Preempting value: %+v\ngot: %+v\n", apiv1.PreemptLowerPriority, output.PreemptionPolicy)

View File

@ -381,6 +381,7 @@ const (
// owner: @denkensk
// alpha: v1.15
// beta: v1.19
// ga: v1.24
//
// Enables NonPreempting option for priorityClass and pod.
NonPreemptingPriority featuregate.Feature = "NonPreemptingPriority"
@ -882,7 +883,7 @@ var defaultKubernetesFeatureGates = map[featuregate.Feature]featuregate.FeatureS
JobReadyPods: {Default: false, PreRelease: featuregate.Alpha},
KubeletPodResources: {Default: true, PreRelease: featuregate.Beta},
LocalStorageCapacityIsolationFSQuotaMonitoring: {Default: false, PreRelease: featuregate.Alpha},
NonPreemptingPriority: {Default: true, PreRelease: featuregate.Beta},
NonPreemptingPriority: {Default: true, PreRelease: featuregate.GA, LockToDefault: true}, // remove in 1.25
PodOverhead: {Default: true, PreRelease: featuregate.Beta},
IPv6DualStack: {Default: true, PreRelease: featuregate.GA, LockToDefault: true}, // remove in 1.25
EndpointSlice: {Default: true, PreRelease: featuregate.GA, LockToDefault: true}, // remove in 1.25

View File

@ -24,7 +24,6 @@ import (
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api/legacyscheme"
"k8s.io/kubernetes/pkg/apis/scheduling"
schedulingutil "k8s.io/kubernetes/pkg/apis/scheduling/util"
"k8s.io/kubernetes/pkg/apis/scheduling/validation"
)
@ -46,16 +45,10 @@ func (priorityClassStrategy) NamespaceScoped() bool {
func (priorityClassStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
pc := obj.(*scheduling.PriorityClass)
pc.Generation = 1
schedulingutil.DropDisabledFields(pc, nil)
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
func (priorityClassStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
newClass := obj.(*scheduling.PriorityClass)
oldClass := old.(*scheduling.PriorityClass)
schedulingutil.DropDisabledFields(newClass, oldClass)
}
func (priorityClassStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {}
// Validate validates a new PriorityClass.
func (priorityClassStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {

View File

@ -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

View File

@ -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)

View File

@ -3662,7 +3662,6 @@ message PodSpec {
// PreemptionPolicy is the Policy for preempting pods with lower priority.
// One of Never, PreemptLowerPriority.
// Defaults to PreemptLowerPriority if unset.
// This field is beta-level, gated by the NonPreemptingPriority feature-gate.
// +optional
optional string preemptionPolicy = 31;

View File

@ -3245,7 +3245,6 @@ type PodSpec struct {
// PreemptionPolicy is the Policy for preempting pods with lower priority.
// One of Never, PreemptLowerPriority.
// Defaults to PreemptLowerPriority if unset.
// This field is beta-level, gated by the NonPreemptingPriority feature-gate.
// +optional
PreemptionPolicy *PreemptionPolicy `json:"preemptionPolicy,omitempty" protobuf:"bytes,31,opt,name=preemptionPolicy"`
// Overhead represents the resource overhead associated with running a pod for a given RuntimeClass.

View File

@ -1665,7 +1665,7 @@ var map_PodSpec = map[string]string{
"readinessGates": "If specified, all readiness gates will be evaluated for pod readiness. A pod is ready when all its containers are ready AND all conditions specified in the readiness gates have status equal to \"True\" More info: https://git.k8s.io/enhancements/keps/sig-network/580-pod-readiness-gates",
"runtimeClassName": "RuntimeClassName refers to a RuntimeClass object in the node.k8s.io group, which should be used to run this pod. If no RuntimeClass resource matches the named class, the pod will not be run. If unset or empty, the \"legacy\" RuntimeClass will be used, which is an implicit class with an empty definition that uses the default runtime handler. More info: https://git.k8s.io/enhancements/keps/sig-node/585-runtime-class This is a beta feature as of Kubernetes v1.14.",
"enableServiceLinks": "EnableServiceLinks indicates whether information about services should be injected into pod's environment variables, matching the syntax of Docker links. Optional: Defaults to true.",
"preemptionPolicy": "PreemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset. This field is beta-level, gated by the NonPreemptingPriority feature-gate.",
"preemptionPolicy": "PreemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset.",
"overhead": "Overhead represents the resource overhead associated with running a pod for a given RuntimeClass. This field will be autopopulated at admission time by the RuntimeClass admission controller. If the RuntimeClass admission controller is enabled, overhead must not be set in Pod create requests. The RuntimeClass admission controller will reject Pod create requests which have the overhead already set. If RuntimeClass is configured and selected in the PodSpec, Overhead will be set to the value defined in the corresponding RuntimeClass, otherwise it will remain unset and treated as zero. More info: https://git.k8s.io/enhancements/keps/sig-node/688-pod-overhead/README.md This field is beta-level as of Kubernetes v1.18, and is only honored by servers that enable the PodOverhead feature.",
"topologySpreadConstraints": "TopologySpreadConstraints describes how a group of pods ought to spread across topology domains. Scheduler will schedule pods in a way which abides by the constraints. All topologySpreadConstraints are ANDed.",
"setHostnameAsFQDN": "If true the pod's hostname will be configured as the pod's FQDN, rather than the leaf name (the default). In Linux containers, this means setting the FQDN in the hostname field of the kernel (the nodename field of struct utsname). In Windows containers, this means setting the registry value of hostname for the registry key HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters to FQDN. If a pod does not have FQDN, this has no effect. Default to false.",

View File

@ -57,7 +57,6 @@ message PriorityClass {
// PreemptionPolicy is the Policy for preempting pods with lower priority.
// One of Never, PreemptLowerPriority.
// Defaults to PreemptLowerPriority if unset.
// This field is beta-level, gated by the NonPreemptingPriority feature-gate.
// +optional
optional string preemptionPolicy = 5;
}

View File

@ -54,7 +54,6 @@ type PriorityClass struct {
// PreemptionPolicy is the Policy for preempting pods with lower priority.
// One of Never, PreemptLowerPriority.
// Defaults to PreemptLowerPriority if unset.
// This field is beta-level, gated by the NonPreemptingPriority feature-gate.
// +optional
PreemptionPolicy *apiv1.PreemptionPolicy `json:"preemptionPolicy,omitempty" protobuf:"bytes,5,opt,name=preemptionPolicy"`
}

View File

@ -33,7 +33,7 @@ var map_PriorityClass = map[string]string{
"value": "The value of this priority class. This is the actual priority that pods receive when they have the name of this class in their pod spec.",
"globalDefault": "globalDefault specifies whether this PriorityClass should be considered as the default priority for pods that do not have any priority class. Only one PriorityClass can be marked as `globalDefault`. However, if more than one PriorityClasses exists with their `globalDefault` field set to true, the smallest value of such global default PriorityClasses will be used as the default priority.",
"description": "description is an arbitrary string that usually provides guidelines on when this priority class should be used.",
"preemptionPolicy": "PreemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset. This field is beta-level, gated by the NonPreemptingPriority feature-gate.",
"preemptionPolicy": "PreemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset.",
}
func (PriorityClass) SwaggerDoc() map[string]string {

View File

@ -58,7 +58,6 @@ message PriorityClass {
// PreemptionPolicy is the Policy for preempting pods with lower priority.
// One of Never, PreemptLowerPriority.
// Defaults to PreemptLowerPriority if unset.
// This field is beta-level, gated by the NonPreemptingPriority feature-gate.
// +optional
optional string preemptionPolicy = 5;
}

View File

@ -55,7 +55,6 @@ type PriorityClass struct {
// PreemptionPolicy is the Policy for preempting pods with lower priority.
// One of Never, PreemptLowerPriority.
// Defaults to PreemptLowerPriority if unset.
// This field is beta-level, gated by the NonPreemptingPriority feature-gate.
// +optional
PreemptionPolicy *apiv1.PreemptionPolicy `json:"preemptionPolicy,omitempty" protobuf:"bytes,5,opt,name=preemptionPolicy"`
}

View File

@ -33,7 +33,7 @@ var map_PriorityClass = map[string]string{
"value": "The value of this priority class. This is the actual priority that pods receive when they have the name of this class in their pod spec.",
"globalDefault": "globalDefault specifies whether this PriorityClass should be considered as the default priority for pods that do not have any priority class. Only one PriorityClass can be marked as `globalDefault`. However, if more than one PriorityClasses exists with their `globalDefault` field set to true, the smallest value of such global default PriorityClasses will be used as the default priority.",
"description": "description is an arbitrary string that usually provides guidelines on when this priority class should be used.",
"preemptionPolicy": "PreemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset. This field is beta-level, gated by the NonPreemptingPriority feature-gate.",
"preemptionPolicy": "PreemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset.",
}
func (PriorityClass) SwaggerDoc() map[string]string {

View File

@ -58,7 +58,6 @@ message PriorityClass {
// PreemptionPolicy is the Policy for preempting pods with lower priority.
// One of Never, PreemptLowerPriority.
// Defaults to PreemptLowerPriority if unset.
// This field is beta-level, gated by the NonPreemptingPriority feature-gate.
// +optional
optional string preemptionPolicy = 5;
}

View File

@ -59,7 +59,6 @@ type PriorityClass struct {
// PreemptionPolicy is the Policy for preempting pods with lower priority.
// One of Never, PreemptLowerPriority.
// Defaults to PreemptLowerPriority if unset.
// This field is beta-level, gated by the NonPreemptingPriority feature-gate.
// +optional
PreemptionPolicy *apiv1.PreemptionPolicy `json:"preemptionPolicy,omitempty" protobuf:"bytes,5,opt,name=preemptionPolicy"`
}

View File

@ -33,7 +33,7 @@ var map_PriorityClass = map[string]string{
"value": "The value of this priority class. This is the actual priority that pods receive when they have the name of this class in their pod spec.",
"globalDefault": "globalDefault specifies whether this PriorityClass should be considered as the default priority for pods that do not have any priority class. Only one PriorityClass can be marked as `globalDefault`. However, if more than one PriorityClasses exists with their `globalDefault` field set to true, the smallest value of such global default PriorityClasses will be used as the default priority.",
"description": "description is an arbitrary string that usually provides guidelines on when this priority class should be used.",
"preemptionPolicy": "PreemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset. This field is beta-level, gated by the NonPreemptingPriority feature-gate.",
"preemptionPolicy": "PreemptionPolicy is the Policy for preempting pods with lower priority. One of Never, PreemptLowerPriority. Defaults to PreemptLowerPriority if unset.",
}
func (PriorityClass) SwaggerDoc() map[string]string {

View File

@ -34,17 +34,14 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/wait"
utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
clientset "k8s.io/client-go/kubernetes"
restclient "k8s.io/client-go/rest"
featuregatetesting "k8s.io/component-base/featuregate/testing"
"k8s.io/klog/v2"
"k8s.io/kube-scheduler/config/v1beta3"
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
"k8s.io/kubernetes/pkg/apis/scheduling"
"k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/scheduler"
configtesting "k8s.io/kubernetes/pkg/scheduler/apis/config/testing"
"k8s.io/kubernetes/pkg/scheduler/framework"
@ -439,8 +436,6 @@ func TestPreemption(t *testing.T) {
// TestNonPreemption tests NonPreempt option of PriorityClass of scheduler works as expected.
func TestNonPreemption(t *testing.T) {
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.NonPreemptingPriority, true)()
var preemptNever = v1.PreemptNever
// Initialize scheduler.
testCtx := initTest(t, "non-preemption")