diff --git a/api/openapi-spec/swagger.json b/api/openapi-spec/swagger.json index b9055c2fa087..67962e486f0c 100644 --- a/api/openapi-spec/swagger.json +++ b/api/openapi-spec/swagger.json @@ -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": { diff --git a/api/openapi-spec/v3/api__v1_openapi.json b/api/openapi-spec/v3/api__v1_openapi.json index 5ccfc06d65e9..ee2d1f29c761 100644 --- a/api/openapi-spec/v3/api__v1_openapi.json +++ b/api/openapi-spec/v3/api__v1_openapi.json @@ -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": { diff --git a/api/openapi-spec/v3/apis__apps__v1_openapi.json b/api/openapi-spec/v3/apis__apps__v1_openapi.json index 6da90ef7a179..0635ae5be3d5 100644 --- a/api/openapi-spec/v3/apis__apps__v1_openapi.json +++ b/api/openapi-spec/v3/apis__apps__v1_openapi.json @@ -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": { diff --git a/api/openapi-spec/v3/apis__batch__v1_openapi.json b/api/openapi-spec/v3/apis__batch__v1_openapi.json index 8123ce6c649f..666aff35beea 100644 --- a/api/openapi-spec/v3/apis__batch__v1_openapi.json +++ b/api/openapi-spec/v3/apis__batch__v1_openapi.json @@ -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": { diff --git a/api/openapi-spec/v3/apis__batch__v1beta1_openapi.json b/api/openapi-spec/v3/apis__batch__v1beta1_openapi.json index dc86b3926d9d..dbf8dbca1db9 100644 --- a/api/openapi-spec/v3/apis__batch__v1beta1_openapi.json +++ b/api/openapi-spec/v3/apis__batch__v1beta1_openapi.json @@ -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": { diff --git a/api/openapi-spec/v3/apis__scheduling.k8s.io__v1_openapi.json b/api/openapi-spec/v3/apis__scheduling.k8s.io__v1_openapi.json index e0b2ca4ee895..a664f382115d 100644 --- a/api/openapi-spec/v3/apis__scheduling.k8s.io__v1_openapi.json +++ b/api/openapi-spec/v3/apis__scheduling.k8s.io__v1_openapi.json @@ -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": { diff --git a/pkg/api/pod/util.go b/pkg/api/pod/util.go index 34fed8c806f8..deeab5f135f0 100644 --- a/pkg/api/pod/util.go +++ b/pkg/api/pod/util.go @@ -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 { diff --git a/pkg/apis/core/types.go b/pkg/apis/core/types.go index 26aff9f8b45e..0fd23f7d381e 100644 --- a/pkg/apis/core/types.go +++ b/pkg/apis/core/types.go @@ -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. diff --git a/pkg/apis/scheduling/fuzzer/fuzzer.go b/pkg/apis/scheduling/fuzzer/fuzzer.go index 5e5d146e44cd..f2cb549d3015 100644 --- a/pkg/apis/scheduling/fuzzer/fuzzer.go +++ b/pkg/apis/scheduling/fuzzer/fuzzer.go @@ -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 } diff --git a/pkg/apis/scheduling/util/util.go b/pkg/apis/scheduling/util/util.go deleted file mode 100644 index 82fd50b03deb..000000000000 --- a/pkg/apis/scheduling/util/util.go +++ /dev/null @@ -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 -} diff --git a/pkg/apis/scheduling/util/util_test.go b/pkg/apis/scheduling/util/util_test.go deleted file mode 100644 index 6c6bbabdbd6c..000000000000 --- a/pkg/apis/scheduling/util/util_test.go +++ /dev/null @@ -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())) - } - } - }) - } - } - } -} diff --git a/pkg/apis/scheduling/v1/defaults.go b/pkg/apis/scheduling/v1/defaults.go index 5da20cd3cd18..fe4e9b77dd85 100644 --- a/pkg/apis/scheduling/v1/defaults.go +++ b/pkg/apis/scheduling/v1/defaults.go @@ -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 } diff --git a/pkg/apis/scheduling/v1/defaults_test.go b/pkg/apis/scheduling/v1/defaults_test.go index aa11406e7594..418e6dbb9ed9 100644 --- a/pkg/apis/scheduling/v1/defaults_test.go +++ b/pkg/apis/scheduling/v1/defaults_test.go @@ -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) diff --git a/pkg/apis/scheduling/v1alpha1/defaults.go b/pkg/apis/scheduling/v1alpha1/defaults.go index 016407c532d9..5340007a5efd 100644 --- a/pkg/apis/scheduling/v1alpha1/defaults.go +++ b/pkg/apis/scheduling/v1alpha1/defaults.go @@ -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 } diff --git a/pkg/apis/scheduling/v1alpha1/defaults_test.go b/pkg/apis/scheduling/v1alpha1/defaults_test.go index ce62c585977c..95d0301a83b2 100644 --- a/pkg/apis/scheduling/v1alpha1/defaults_test.go +++ b/pkg/apis/scheduling/v1alpha1/defaults_test.go @@ -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) diff --git a/pkg/apis/scheduling/v1beta1/defaults.go b/pkg/apis/scheduling/v1beta1/defaults.go index 6ffb8a669ece..dc9db335e6d7 100644 --- a/pkg/apis/scheduling/v1beta1/defaults.go +++ b/pkg/apis/scheduling/v1beta1/defaults.go @@ -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 } diff --git a/pkg/apis/scheduling/v1beta1/defaults_test.go b/pkg/apis/scheduling/v1beta1/defaults_test.go index d1166c141d38..18fe4843e1de 100644 --- a/pkg/apis/scheduling/v1beta1/defaults_test.go +++ b/pkg/apis/scheduling/v1beta1/defaults_test.go @@ -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) diff --git a/pkg/features/kube_features.go b/pkg/features/kube_features.go index 433cf48939c1..872863c74af4 100644 --- a/pkg/features/kube_features.go +++ b/pkg/features/kube_features.go @@ -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" @@ -890,7 +891,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 diff --git a/pkg/registry/scheduling/priorityclass/strategy.go b/pkg/registry/scheduling/priorityclass/strategy.go index 36fb1d1a0d55..462a5c2f346e 100644 --- a/pkg/registry/scheduling/priorityclass/strategy.go +++ b/pkg/registry/scheduling/priorityclass/strategy.go @@ -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 { diff --git a/plugin/pkg/admission/priority/admission.go b/plugin/pkg/admission/priority/admission.go index e997226456ad..866fbf64516b 100644 --- a/plugin/pkg/admission/priority/admission.go +++ b/plugin/pkg/admission/priority/admission.go @@ -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 diff --git a/plugin/pkg/admission/priority/admission_test.go b/plugin/pkg/admission/priority/admission_test.go index 628de4290044..d8ade19fb348 100644 --- a/plugin/pkg/admission/priority/admission_test.go +++ b/plugin/pkg/admission/priority/admission_test.go @@ -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) diff --git a/staging/src/k8s.io/api/core/v1/generated.proto b/staging/src/k8s.io/api/core/v1/generated.proto index e80d9ce19ae0..61d217c49252 100644 --- a/staging/src/k8s.io/api/core/v1/generated.proto +++ b/staging/src/k8s.io/api/core/v1/generated.proto @@ -3666,7 +3666,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; diff --git a/staging/src/k8s.io/api/core/v1/types.go b/staging/src/k8s.io/api/core/v1/types.go index 72f288cbf51d..175b64ed2c6a 100644 --- a/staging/src/k8s.io/api/core/v1/types.go +++ b/staging/src/k8s.io/api/core/v1/types.go @@ -3247,7 +3247,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. diff --git a/staging/src/k8s.io/api/core/v1/types_swagger_doc_generated.go b/staging/src/k8s.io/api/core/v1/types_swagger_doc_generated.go index dce630fee1ed..cc9a96335b15 100644 --- a/staging/src/k8s.io/api/core/v1/types_swagger_doc_generated.go +++ b/staging/src/k8s.io/api/core/v1/types_swagger_doc_generated.go @@ -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.", diff --git a/staging/src/k8s.io/api/scheduling/v1/generated.proto b/staging/src/k8s.io/api/scheduling/v1/generated.proto index 1f9a7474a0ac..af2f8d031c69 100644 --- a/staging/src/k8s.io/api/scheduling/v1/generated.proto +++ b/staging/src/k8s.io/api/scheduling/v1/generated.proto @@ -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; } diff --git a/staging/src/k8s.io/api/scheduling/v1/types.go b/staging/src/k8s.io/api/scheduling/v1/types.go index b4ff34767cc4..0f2989424efa 100644 --- a/staging/src/k8s.io/api/scheduling/v1/types.go +++ b/staging/src/k8s.io/api/scheduling/v1/types.go @@ -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"` } diff --git a/staging/src/k8s.io/api/scheduling/v1/types_swagger_doc_generated.go b/staging/src/k8s.io/api/scheduling/v1/types_swagger_doc_generated.go index 7524adf9a840..ac34c531fb9d 100644 --- a/staging/src/k8s.io/api/scheduling/v1/types_swagger_doc_generated.go +++ b/staging/src/k8s.io/api/scheduling/v1/types_swagger_doc_generated.go @@ -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 { diff --git a/staging/src/k8s.io/api/scheduling/v1alpha1/generated.proto b/staging/src/k8s.io/api/scheduling/v1alpha1/generated.proto index da27a13e7510..1c1070b76090 100644 --- a/staging/src/k8s.io/api/scheduling/v1alpha1/generated.proto +++ b/staging/src/k8s.io/api/scheduling/v1alpha1/generated.proto @@ -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; } diff --git a/staging/src/k8s.io/api/scheduling/v1alpha1/types.go b/staging/src/k8s.io/api/scheduling/v1alpha1/types.go index 4d8462c7c5cd..7b0df4864600 100644 --- a/staging/src/k8s.io/api/scheduling/v1alpha1/types.go +++ b/staging/src/k8s.io/api/scheduling/v1alpha1/types.go @@ -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"` } diff --git a/staging/src/k8s.io/api/scheduling/v1alpha1/types_swagger_doc_generated.go b/staging/src/k8s.io/api/scheduling/v1alpha1/types_swagger_doc_generated.go index 940c39a083bf..fa25f969c437 100644 --- a/staging/src/k8s.io/api/scheduling/v1alpha1/types_swagger_doc_generated.go +++ b/staging/src/k8s.io/api/scheduling/v1alpha1/types_swagger_doc_generated.go @@ -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 { diff --git a/staging/src/k8s.io/api/scheduling/v1beta1/generated.proto b/staging/src/k8s.io/api/scheduling/v1beta1/generated.proto index 99bdaabee1e2..8fc1eba5bf22 100644 --- a/staging/src/k8s.io/api/scheduling/v1beta1/generated.proto +++ b/staging/src/k8s.io/api/scheduling/v1beta1/generated.proto @@ -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; } diff --git a/staging/src/k8s.io/api/scheduling/v1beta1/types.go b/staging/src/k8s.io/api/scheduling/v1beta1/types.go index d68b4b318791..e315e1b35949 100644 --- a/staging/src/k8s.io/api/scheduling/v1beta1/types.go +++ b/staging/src/k8s.io/api/scheduling/v1beta1/types.go @@ -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"` } diff --git a/staging/src/k8s.io/api/scheduling/v1beta1/types_swagger_doc_generated.go b/staging/src/k8s.io/api/scheduling/v1beta1/types_swagger_doc_generated.go index d576c8401362..cbc140f446bc 100644 --- a/staging/src/k8s.io/api/scheduling/v1beta1/types_swagger_doc_generated.go +++ b/staging/src/k8s.io/api/scheduling/v1beta1/types_swagger_doc_generated.go @@ -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 { diff --git a/test/integration/scheduler/preemption_test.go b/test/integration/scheduler/preemption_test.go index c42308ace779..e942bb77f3cd 100644 --- a/test/integration/scheduler/preemption_test.go +++ b/test/integration/scheduler/preemption_test.go @@ -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")