mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-19 17:16:12 +00:00
Merge pull request #107432 from denkensk/graduate-nonpreemptingpriority-to-ga
Graduate NonPreemptingPriority to GA
This commit is contained in:
@@ -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.
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
@@ -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()))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -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
|
||||
}
|
||||
|
@@ -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)
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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)
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user