non-preempting-priorityclass

Co-authored-by: Vallery Lancey <vallery@zeitgeistlabs.io>
Co-authored-by: Tan shanshan <tan.shanshan@zte.com.cn>
k3s-v1.15.3
wangqingcan 2019-04-03 01:34:51 +08:00
parent cf76868b34
commit 5c9438c691
77 changed files with 1541 additions and 896 deletions

View File

@ -9328,6 +9328,10 @@
"description": "NodeSelector is a selector which must be true for the pod to fit on a node. Selector which must match a node's labels for the pod to be scheduled on that node. More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/",
"type": "object"
},
"preempting": {
"description": "Preempting specifies whether a pod with this PriorityClass could start a preemption process. If this field is missing, the PriorityClass is considered a Preempting class by default.",
"type": "boolean"
},
"priority": {
"description": "The priority value. Various system components use this field to find the priority of the pod. When Priority Admission Controller is enabled, it prevents users from setting this field. The admission controller populates this field from PriorityClassName. The higher the value, the higher the priority.",
"format": "int32",
@ -15159,6 +15163,10 @@
"$ref": "#/definitions/io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta",
"description": "Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata"
},
"preempting": {
"description": "Preempting specifies whether a pod with this PriorityClass could trigger a preemption process. If this field is unset, the PriorityClass is considered a Preempting class by default.",
"type": "boolean"
},
"value": {
"description": "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.",
"format": "int32",

View File

@ -172,6 +172,7 @@ func Run(cc schedulerserverconfig.CompletedConfig, stopCh <-chan struct{}) error
cc.InformerFactory.Core().V1().Services(),
cc.InformerFactory.Policy().V1beta1().PodDisruptionBudgets(),
cc.InformerFactory.Storage().V1().StorageClasses(),
cc.InformerFactory.Scheduling().V1().PriorityClasses(),
cc.Recorder,
cc.ComponentConfig.AlgorithmSource,
stopCh,

View File

@ -45,6 +45,11 @@ pkg/apis/rbac/v1
pkg/apis/rbac/v1alpha1
pkg/apis/rbac/v1beta1
pkg/apis/rbac/validation
pkg/apis/scheduling
pkg/apis/scheduling/v1
pkg/apis/scheduling/v1alpha1
pkg/apis/scheduling/v1beta1
pkg/apis/settings
pkg/apis/storage
pkg/apis/storage/v1
pkg/apis/storage/v1beta1
@ -525,6 +530,7 @@ staging/src/k8s.io/client-go/scale/scheme/extensionsv1beta1
staging/src/k8s.io/client-go/testing
staging/src/k8s.io/client-go/tools/cache
staging/src/k8s.io/client-go/tools/cache/testing
staging/src/k8s.io/client-go/tools/cacheck/.golint_failures
staging/src/k8s.io/client-go/tools/clientcmd
staging/src/k8s.io/client-go/tools/clientcmd/api
staging/src/k8s.io/client-go/tools/clientcmd/api/latest

View File

@ -30,6 +30,7 @@ go_library(
"//pkg/apis/networking/fuzzer:go_default_library",
"//pkg/apis/policy/fuzzer:go_default_library",
"//pkg/apis/rbac/fuzzer:go_default_library",
"//pkg/apis/scheduling/fuzzer:go_default_library",
"//pkg/apis/storage/fuzzer:go_default_library",
"//staging/src/k8s.io/api/apps/v1:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",

View File

@ -147,6 +147,8 @@ func TestDefaulting(t *testing.T) {
{Group: "storage.k8s.io", Version: "v1", Kind: "StorageClass"}: {},
{Group: "storage.k8s.io", Version: "v1", Kind: "StorageClassList"}: {},
{Group: "authentication.k8s.io", Version: "v1", Kind: "TokenRequest"}: {},
{Group: "scheduling.k8s.io", Version: "v1", Kind: "PriorityClass"}: {},
{Group: "scheduling.k8s.io", Version: "v1", Kind: "PriorityClassList"}: {},
}
f := fuzz.New().NilChance(.5).NumElements(1, 1).RandSource(rand.NewSource(1))

View File

@ -41,6 +41,7 @@ import (
networkingfuzzer "k8s.io/kubernetes/pkg/apis/networking/fuzzer"
policyfuzzer "k8s.io/kubernetes/pkg/apis/policy/fuzzer"
rbacfuzzer "k8s.io/kubernetes/pkg/apis/rbac/fuzzer"
schedulingfuzzer "k8s.io/kubernetes/pkg/apis/scheduling/fuzzer"
storagefuzzer "k8s.io/kubernetes/pkg/apis/storage/fuzzer"
)
@ -105,4 +106,5 @@ var FuzzerFuncs = fuzzer.MergeFuzzerFuncs(
storagefuzzer.Funcs,
networkingfuzzer.Funcs,
metafuzzer.Funcs,
schedulingfuzzer.Funcs,
)

View File

@ -217,6 +217,7 @@ func TestRoundTripTypes(t *testing.T) {
func TestEncodePtr(t *testing.T) {
grace := int64(30)
enableServiceLinks := v1.DefaultEnableServiceLinks
preempting := v1.DefaultPreempting
pod := &api.Pod{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{"name": "foo"},
@ -230,6 +231,7 @@ func TestEncodePtr(t *testing.T) {
SecurityContext: &api.PodSecurityContext{},
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
Preempting: &preempting,
},
}
obj := runtime.Object(pod)

View File

@ -89,6 +89,10 @@ var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
enableServiceLinks := corev1.DefaultEnableServiceLinks
s.EnableServiceLinks = &enableServiceLinks
}
if s.Preempting == nil {
preempting := corev1.DefaultPreempting
s.Preempting = &preempting
}
},
func(j *core.PodPhase, c fuzz.Continue) {
statuses := []core.PodPhase{core.PodPending, core.PodRunning, core.PodFailed, core.PodUnknown}

View File

@ -2662,6 +2662,10 @@ type PodSpec struct {
// The higher the value, the higher the priority.
// +optional
Priority *int32
// Preempting specifies whether a pod with this PriorityClass could start a preemption process.
// If not specified, the default is true.
// +optional
Preempting *bool
// Specifies the DNS parameters of a pod.
// Parameters specified here will be merged to the generated DNS
// configuration based on DNSPolicy.

View File

@ -162,6 +162,11 @@ func SetDefaults_Pod(obj *v1.Pod) {
enableServiceLinks := v1.DefaultEnableServiceLinks
obj.Spec.EnableServiceLinks = &enableServiceLinks
}
if obj.Spec.Preempting == nil {
// Set Preempting as true by default.
Preempting := v1.DefaultPreempting
obj.Spec.Preempting = &Preempting
}
}
func SetDefaults_PodSpec(obj *v1.PodSpec) {
// New fields added here will break upgrade tests:

View File

@ -1390,3 +1390,11 @@ func TestSetDefaultEnableServiceLinks(t *testing.T) {
t.Errorf("Expected enableServiceLinks value: %+v\ngot: %+v\n", v1.DefaultEnableServiceLinks, *output.Spec.EnableServiceLinks)
}
}
func TestSetDefaultPreempting(t *testing.T) {
pod := &v1.Pod{}
output := roundTrip(t, runtime.Object(pod)).(*v1.Pod)
if output.Spec.Preempting == nil || *output.Spec.Preempting != v1.DefaultPreempting {
t.Errorf("Expected enableServiceLinks value: %+v\ngot: %+v\n", v1.DefaultPreempting, *output.Spec.Preempting)
}
}

View File

@ -5594,6 +5594,7 @@ func autoConvert_v1_PodSpec_To_core_PodSpec(in *v1.PodSpec, out *core.PodSpec, s
out.HostAliases = *(*[]core.HostAlias)(unsafe.Pointer(&in.HostAliases))
out.PriorityClassName = in.PriorityClassName
out.Priority = (*int32)(unsafe.Pointer(in.Priority))
out.Preempting = (*bool)(unsafe.Pointer(in.Preempting))
out.DNSConfig = (*core.PodDNSConfig)(unsafe.Pointer(in.DNSConfig))
out.ReadinessGates = *(*[]core.PodReadinessGate)(unsafe.Pointer(&in.ReadinessGates))
out.RuntimeClassName = (*string)(unsafe.Pointer(in.RuntimeClassName))
@ -5641,6 +5642,7 @@ func autoConvert_core_PodSpec_To_v1_PodSpec(in *core.PodSpec, out *v1.PodSpec, s
out.HostAliases = *(*[]v1.HostAlias)(unsafe.Pointer(&in.HostAliases))
out.PriorityClassName = in.PriorityClassName
out.Priority = (*int32)(unsafe.Pointer(in.Priority))
out.Preempting = (*bool)(unsafe.Pointer(in.Preempting))
out.DNSConfig = (*v1.PodDNSConfig)(unsafe.Pointer(in.DNSConfig))
out.ReadinessGates = *(*[]v1.PodReadinessGate)(unsafe.Pointer(&in.ReadinessGates))
out.RuntimeClassName = (*string)(unsafe.Pointer(in.RuntimeClassName))

View File

@ -3610,6 +3610,11 @@ func (in *PodSpec) DeepCopyInto(out *PodSpec) {
*out = new(int32)
**out = **in
}
if in.Preempting != nil {
in, out := &in.Preempting, &out.Preempting
*out = new(bool)
**out = **in
}
if in.DNSConfig != nil {
in, out := &in.DNSConfig, &out.DNSConfig
*out = new(PodDNSConfig)

View File

@ -9,6 +9,7 @@ load(
go_library(
name = "go_default_library",
srcs = [
"annotations.go",
"doc.go",
"helpers.go",
"register.go",

View File

@ -0,0 +1,21 @@
/*
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 scheduling
// PreemptingAnnotation is the annotation which holds preempting
// when converting the `Preempting` field from scheduling/v1
const PreemptingAnnotation = "scheduling.k8s.io/preempting"

View File

@ -9,7 +9,11 @@ go_library(
name = "go_default_library",
srcs = ["fuzzer.go"],
importpath = "k8s.io/kubernetes/pkg/apis/scheduling/fuzzer",
deps = ["//staging/src/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library"],
deps = [
"//pkg/apis/scheduling:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
"//vendor/github.com/google/gofuzz:go_default_library",
],
)
filegroup(

View File

@ -17,10 +17,20 @@ limitations under the License.
package fuzzer
import (
"github.com/google/gofuzz"
runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/kubernetes/pkg/apis/scheduling"
)
// Funcs returns the fuzzer functions for the scheduling api group.
var Funcs = func(codecs runtimeserializer.CodecFactory) []interface{} {
return []interface{}{}
return []interface{}{
func(s *scheduling.PriorityClass, c fuzz.Continue) {
c.FuzzNoCustom(s)
if s.Preempting == nil {
preempting := scheduling.DefaultPreempting
s.Preempting = &preempting
}
},
}
}

View File

@ -36,6 +36,8 @@ const (
SystemClusterCritical = SystemPriorityClassPrefix + "cluster-critical"
// SystemNodeCritical is the system priority class name that represents node-critical.
SystemNodeCritical = SystemPriorityClassPrefix + "node-critical"
// The default value for preempting attribute.
DefaultPreempting = true
)
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
@ -64,6 +66,11 @@ type PriorityClass struct {
// when this priority class should be used.
// +optional
Description string
// Preempting specifies whether a pod with this PriorityClass could start a preemption process.
// If this field is missing, the PriorityClass is considered a preempting class by default.
// +optional
Preempting *bool
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

View File

@ -1,8 +1,9 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = [
"defaults.go",
"doc.go",
"register.go",
"zz_generated.conversion.go",
@ -32,3 +33,16 @@ filegroup(
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
go_test(
name = "go_default_test",
srcs = ["defaults_test.go"],
embed = [":go_default_library"],
deps = [
"//pkg/api/legacyscheme:go_default_library",
"//pkg/api/testapi:go_default_library",
"//pkg/apis/scheduling:go_default_library",
"//staging/src/k8s.io/api/scheduling/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
],
)

View File

@ -0,0 +1,37 @@
/*
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 v1
import (
"k8s.io/api/scheduling/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/kubernetes/pkg/apis/scheduling"
)
func addDefaultingFuncs(scheme *runtime.Scheme) error {
return RegisterDefaults(scheme)
}
// SetDefaults_PriorityClass sets additional defaults compared to its counterpart
// in extensions.
func SetDefaults_PriorityClass(obj *v1.PriorityClass) {
if obj.Preempting == nil {
// Set Preempting as true by default.
Preempting := scheduling.DefaultPreempting
obj.Preempting = &Preempting
}
}

View File

@ -0,0 +1,59 @@
/*
Copyright 2015 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 v1_test
import (
"reflect"
"testing"
"k8s.io/api/scheduling/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/kubernetes/pkg/api/legacyscheme"
// enforce that all types are installed
_ "k8s.io/kubernetes/pkg/api/testapi"
"k8s.io/kubernetes/pkg/apis/scheduling"
)
func roundTrip(t *testing.T, obj runtime.Object) runtime.Object {
codec := legacyscheme.Codecs.LegacyCodec(v1.SchemeGroupVersion)
data, err := runtime.Encode(codec, obj)
if err != nil {
t.Errorf("%v\n %#v", err, obj)
return nil
}
obj2, err := runtime.Decode(codec, data)
if err != nil {
t.Errorf("%v\nData: %s\nSource: %#v", err, string(data), obj)
return nil
}
obj3 := reflect.New(reflect.TypeOf(obj).Elem()).Interface().(runtime.Object)
err = legacyscheme.Scheme.Convert(obj2, obj3, nil)
if err != nil {
t.Errorf("%v\nSource: %#v", err, obj2)
return nil
}
return obj3
}
func TestSetDefaultPreempting(t *testing.T) {
priorityClass := &v1.PriorityClass{}
output := roundTrip(t, runtime.Object(priorityClass)).(*v1.PriorityClass)
if output.Preempting == nil || *output.Preempting != scheduling.DefaultPreempting {
t.Errorf("Expected enableServiceLinks value: %+v\ngot: %+v\n", scheduling.DefaultPreempting, *output.Preempting)
}
}

View File

@ -42,5 +42,5 @@ func init() {
// We only register manually written functions here. The registration of the
// generated functions takes place in the generated files. The separation
// makes the code compile even when the generated files are missing.
localSchemeBuilder.Register(RegisterDefaults)
localSchemeBuilder.Register(addDefaultingFuncs)
}

View File

@ -64,6 +64,7 @@ func autoConvert_v1_PriorityClass_To_scheduling_PriorityClass(in *v1.PriorityCla
out.Value = in.Value
out.GlobalDefault = in.GlobalDefault
out.Description = in.Description
out.Preempting = (*bool)(unsafe.Pointer(in.Preempting))
return nil
}
@ -77,6 +78,7 @@ func autoConvert_scheduling_PriorityClass_To_v1_PriorityClass(in *scheduling.Pri
out.Value = in.Value
out.GlobalDefault = in.GlobalDefault
out.Description = in.Description
out.Preempting = (*bool)(unsafe.Pointer(in.Preempting))
return nil
}

View File

@ -21,6 +21,7 @@ limitations under the License.
package v1
import (
v1 "k8s.io/api/scheduling/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
)
@ -28,5 +29,18 @@ import (
// Public to allow building arbitrary schemes.
// All generated defaulters are covering - they call all nested defaulters.
func RegisterDefaults(scheme *runtime.Scheme) error {
scheme.AddTypeDefaultingFunc(&v1.PriorityClass{}, func(obj interface{}) { SetObjectDefaults_PriorityClass(obj.(*v1.PriorityClass)) })
scheme.AddTypeDefaultingFunc(&v1.PriorityClassList{}, func(obj interface{}) { SetObjectDefaults_PriorityClassList(obj.(*v1.PriorityClassList)) })
return nil
}
func SetObjectDefaults_PriorityClass(in *v1.PriorityClass) {
SetDefaults_PriorityClass(in)
}
func SetObjectDefaults_PriorityClassList(in *v1.PriorityClassList) {
for i := range in.Items {
a := &in.Items[i]
SetObjectDefaults_PriorityClass(a)
}
}

View File

@ -8,6 +8,7 @@ load(
go_library(
name = "go_default_library",
srcs = [
"conversion.go",
"doc.go",
"register.go",
"zz_generated.conversion.go",

View File

@ -0,0 +1,70 @@
/*
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 v1alpha1
import (
"k8s.io/api/scheduling/v1alpha1"
"k8s.io/apimachinery/pkg/conversion"
"k8s.io/kubernetes/pkg/apis/scheduling"
"strconv"
)
func Convert_scheduling_PriorityClass_To_v1alpha1_PriorityClass(in *scheduling.PriorityClass, out *v1alpha1.PriorityClass, s conversion.Scope) error {
if err := autoConvert_scheduling_PriorityClass_To_v1alpha1_PriorityClass(in, out, s); err != nil {
return err
}
out.ObjectMeta.Annotations = deepCopyStringMap(out.Annotations)
if in.Preempting != nil {
if out.ObjectMeta.Annotations == nil {
out.ObjectMeta.Annotations = make(map[string]string)
}
out.ObjectMeta.Annotations[scheduling.PreemptingAnnotation] = strconv.FormatBool(*(in.Preempting))
}
return nil
}
func Convert_v1alpha1_PriorityClass_To_scheduling_PriorityClass(in *v1alpha1.PriorityClass, out *scheduling.PriorityClass, s conversion.Scope) error {
if err := autoConvert_v1alpha1_PriorityClass_To_scheduling_PriorityClass(in, out, s); err != nil {
return err
}
out.ObjectMeta.Annotations = deepCopyStringMap(out.Annotations)
if in.ObjectMeta.Annotations != nil {
if _, ok := in.ObjectMeta.Annotations[scheduling.PreemptingAnnotation]; ok {
preempting, err := strconv.ParseBool(in.ObjectMeta.Annotations[scheduling.PreemptingAnnotation])
if err != nil {
return err
}
out.Preempting = &preempting
delete(out.ObjectMeta.Annotations, scheduling.PreemptingAnnotation)
}
} else {
preempting := scheduling.DefaultPreempting
out.Preempting = &preempting
}
return nil
}
func deepCopyStringMap(m map[string]string) map[string]string {
ret := make(map[string]string, len(m))
for k, v := range m {
ret[k] = v
}
return ret
}

View File

@ -21,8 +21,6 @@ limitations under the License.
package v1alpha1
import (
unsafe "unsafe"
v1alpha1 "k8s.io/api/scheduling/v1alpha1"
conversion "k8s.io/apimachinery/pkg/conversion"
runtime "k8s.io/apimachinery/pkg/runtime"
@ -56,6 +54,16 @@ func RegisterConversions(s *runtime.Scheme) error {
}); err != nil {
return err
}
if err := s.AddConversionFunc((*scheduling.PriorityClass)(nil), (*v1alpha1.PriorityClass)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_scheduling_PriorityClass_To_v1alpha1_PriorityClass(a.(*scheduling.PriorityClass), b.(*v1alpha1.PriorityClass), scope)
}); err != nil {
return err
}
if err := s.AddConversionFunc((*v1alpha1.PriorityClass)(nil), (*scheduling.PriorityClass)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_v1alpha1_PriorityClass_To_scheduling_PriorityClass(a.(*v1alpha1.PriorityClass), b.(*scheduling.PriorityClass), scope)
}); err != nil {
return err
}
return nil
}
@ -67,27 +75,28 @@ func autoConvert_v1alpha1_PriorityClass_To_scheduling_PriorityClass(in *v1alpha1
return nil
}
// Convert_v1alpha1_PriorityClass_To_scheduling_PriorityClass is an autogenerated conversion function.
func Convert_v1alpha1_PriorityClass_To_scheduling_PriorityClass(in *v1alpha1.PriorityClass, out *scheduling.PriorityClass, s conversion.Scope) error {
return autoConvert_v1alpha1_PriorityClass_To_scheduling_PriorityClass(in, out, s)
}
func autoConvert_scheduling_PriorityClass_To_v1alpha1_PriorityClass(in *scheduling.PriorityClass, out *v1alpha1.PriorityClass, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.Value = in.Value
out.GlobalDefault = in.GlobalDefault
out.Description = in.Description
// WARNING: in.Preempting requires manual conversion: does not exist in peer-type
return nil
}
// Convert_scheduling_PriorityClass_To_v1alpha1_PriorityClass is an autogenerated conversion function.
func Convert_scheduling_PriorityClass_To_v1alpha1_PriorityClass(in *scheduling.PriorityClass, out *v1alpha1.PriorityClass, s conversion.Scope) error {
return autoConvert_scheduling_PriorityClass_To_v1alpha1_PriorityClass(in, out, s)
}
func autoConvert_v1alpha1_PriorityClassList_To_scheduling_PriorityClassList(in *v1alpha1.PriorityClassList, out *scheduling.PriorityClassList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]scheduling.PriorityClass)(unsafe.Pointer(&in.Items))
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]scheduling.PriorityClass, len(*in))
for i := range *in {
if err := Convert_v1alpha1_PriorityClass_To_scheduling_PriorityClass(&(*in)[i], &(*out)[i], s); err != nil {
return err
}
}
} else {
out.Items = nil
}
return nil
}
@ -98,7 +107,17 @@ func Convert_v1alpha1_PriorityClassList_To_scheduling_PriorityClassList(in *v1al
func autoConvert_scheduling_PriorityClassList_To_v1alpha1_PriorityClassList(in *scheduling.PriorityClassList, out *v1alpha1.PriorityClassList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]v1alpha1.PriorityClass)(unsafe.Pointer(&in.Items))
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]v1alpha1.PriorityClass, len(*in))
for i := range *in {
if err := Convert_scheduling_PriorityClass_To_v1alpha1_PriorityClass(&(*in)[i], &(*out)[i], s); err != nil {
return err
}
}
} else {
out.Items = nil
}
return nil
}

View File

@ -8,6 +8,7 @@ load(
go_library(
name = "go_default_library",
srcs = [
"conversion.go",
"doc.go",
"register.go",
"zz_generated.conversion.go",

View File

@ -0,0 +1,67 @@
/*
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 v1beta1
import (
"k8s.io/api/scheduling/v1beta1"
"k8s.io/apimachinery/pkg/conversion"
"k8s.io/kubernetes/pkg/apis/scheduling"
"strconv"
)
func Convert_scheduling_PriorityClass_To_v1beta1_PriorityClass(in *scheduling.PriorityClass, out *v1beta1.PriorityClass, s conversion.Scope) error {
if err := autoConvert_scheduling_PriorityClass_To_v1beta1_PriorityClass(in, out, s); err != nil {
return err
}
out.ObjectMeta.Annotations = deepCopyStringMap(out.Annotations)
if in.Preempting != nil {
if out.ObjectMeta.Annotations == nil {
out.ObjectMeta.Annotations = make(map[string]string)
}
out.ObjectMeta.Annotations[scheduling.PreemptingAnnotation] = strconv.FormatBool(*(in.Preempting))
}
return nil
}
func Convert_v1beta1_PriorityClass_To_scheduling_PriorityClass(in *v1beta1.PriorityClass, out *scheduling.PriorityClass, s conversion.Scope) error {
if err := autoConvert_v1beta1_PriorityClass_To_scheduling_PriorityClass(in, out, s); err != nil {
return err
}
out.ObjectMeta.Annotations = deepCopyStringMap(out.Annotations)
if out.ObjectMeta.Annotations != nil {
if _, ok := out.ObjectMeta.Annotations[scheduling.PreemptingAnnotation]; ok {
preempting, err := strconv.ParseBool(out.ObjectMeta.Annotations[scheduling.PreemptingAnnotation])
if err != nil {
return err
}
out.Preempting = &preempting
delete(out.ObjectMeta.Annotations, scheduling.PreemptingAnnotation)
}
} else {
preempting := scheduling.DefaultPreempting
out.Preempting = &preempting
}
return nil
}
func deepCopyStringMap(m map[string]string) map[string]string {
ret := make(map[string]string, len(m))
for k, v := range m {
ret[k] = v
}
return ret
}

View File

@ -21,8 +21,6 @@ limitations under the License.
package v1beta1
import (
unsafe "unsafe"
v1beta1 "k8s.io/api/scheduling/v1beta1"
conversion "k8s.io/apimachinery/pkg/conversion"
runtime "k8s.io/apimachinery/pkg/runtime"
@ -56,6 +54,16 @@ func RegisterConversions(s *runtime.Scheme) error {
}); err != nil {
return err
}
if err := s.AddConversionFunc((*scheduling.PriorityClass)(nil), (*v1beta1.PriorityClass)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_scheduling_PriorityClass_To_v1beta1_PriorityClass(a.(*scheduling.PriorityClass), b.(*v1beta1.PriorityClass), scope)
}); err != nil {
return err
}
if err := s.AddConversionFunc((*v1beta1.PriorityClass)(nil), (*scheduling.PriorityClass)(nil), func(a, b interface{}, scope conversion.Scope) error {
return Convert_v1beta1_PriorityClass_To_scheduling_PriorityClass(a.(*v1beta1.PriorityClass), b.(*scheduling.PriorityClass), scope)
}); err != nil {
return err
}
return nil
}
@ -67,27 +75,28 @@ func autoConvert_v1beta1_PriorityClass_To_scheduling_PriorityClass(in *v1beta1.P
return nil
}
// Convert_v1beta1_PriorityClass_To_scheduling_PriorityClass is an autogenerated conversion function.
func Convert_v1beta1_PriorityClass_To_scheduling_PriorityClass(in *v1beta1.PriorityClass, out *scheduling.PriorityClass, s conversion.Scope) error {
return autoConvert_v1beta1_PriorityClass_To_scheduling_PriorityClass(in, out, s)
}
func autoConvert_scheduling_PriorityClass_To_v1beta1_PriorityClass(in *scheduling.PriorityClass, out *v1beta1.PriorityClass, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.Value = in.Value
out.GlobalDefault = in.GlobalDefault
out.Description = in.Description
// WARNING: in.Preempting requires manual conversion: does not exist in peer-type
return nil
}
// Convert_scheduling_PriorityClass_To_v1beta1_PriorityClass is an autogenerated conversion function.
func Convert_scheduling_PriorityClass_To_v1beta1_PriorityClass(in *scheduling.PriorityClass, out *v1beta1.PriorityClass, s conversion.Scope) error {
return autoConvert_scheduling_PriorityClass_To_v1beta1_PriorityClass(in, out, s)
}
func autoConvert_v1beta1_PriorityClassList_To_scheduling_PriorityClassList(in *v1beta1.PriorityClassList, out *scheduling.PriorityClassList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]scheduling.PriorityClass)(unsafe.Pointer(&in.Items))
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]scheduling.PriorityClass, len(*in))
for i := range *in {
if err := Convert_v1beta1_PriorityClass_To_scheduling_PriorityClass(&(*in)[i], &(*out)[i], s); err != nil {
return err
}
}
} else {
out.Items = nil
}
return nil
}
@ -98,7 +107,17 @@ func Convert_v1beta1_PriorityClassList_To_scheduling_PriorityClassList(in *v1bet
func autoConvert_scheduling_PriorityClassList_To_v1beta1_PriorityClassList(in *scheduling.PriorityClassList, out *v1beta1.PriorityClassList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]v1beta1.PriorityClass)(unsafe.Pointer(&in.Items))
if in.Items != nil {
in, out := &in.Items, &out.Items
*out = make([]v1beta1.PriorityClass, len(*in))
for i := range *in {
if err := Convert_scheduling_PriorityClass_To_v1beta1_PriorityClass(&(*in)[i], &(*out)[i], s); err != nil {
return err
}
}
} else {
out.Items = nil
}
return nil
}

View File

@ -29,6 +29,11 @@ func (in *PriorityClass) DeepCopyInto(out *PriorityClass) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
if in.Preempting != nil {
in, out := &in.Preempting, &out.Preempting
*out = new(bool)
**out = **in
}
return
}

View File

@ -83,7 +83,8 @@
"k8s.io/api/admission/v1beta1",
"k8s.io/api/networking/v1",
"k8s.io/component-base/config",
"k8s.io/component-base/config/v1alpha1"
"k8s.io/component-base/config/v1alpha1",
"k8s.io/api/scheduling/v1beta1"
]
},
{

View File

@ -152,6 +152,7 @@ func generateDeployment(image string) apps.Deployment {
podLabels := map[string]string{"name": image}
terminationSec := int64(30)
enableServiceLinks := v1.DefaultEnableServiceLinks
preempting := v1.DefaultPreempting
return apps.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: image,
@ -178,6 +179,7 @@ func generateDeployment(image string) apps.Deployment {
RestartPolicy: v1.RestartPolicyAlways,
SecurityContext: &v1.PodSecurityContext{},
EnableServiceLinks: &enableServiceLinks,
Preempting: &preempting,
},
},
},

View File

@ -29,7 +29,7 @@ import (
var (
pcLong = templates.LongDesc(i18n.T(`
Create a priorityclass with the specified name, value, globalDefault and description`))
Create a priorityclass with the specified name, value, globalDefaultpreempting and description`))
pcExample = templates.Examples(i18n.T(`
# Create a priorityclass named high-priority
@ -67,11 +67,13 @@ func NewCmdCreatePriorityClass(f cmdutil.Factory, ioStreams genericclioptions.IO
cmdutil.AddApplyAnnotationFlags(cmd)
cmdutil.AddValidateFlags(cmd)
cmdutil.AddGeneratorFlags(cmd, generateversioned.PriorityClassV1Alpha1GeneratorName)
cmdutil.AddGeneratorFlags(cmd, generateversioned.PriorityClassV1GeneratorName)
cmd.Flags().Int32("value", 0, i18n.T("the value of this priority class."))
cmd.Flags().Bool("global-default", false, i18n.T("global-default specifies whether this PriorityClass should be considered as the default priority."))
cmd.Flags().String("description", "", i18n.T("description is an arbitrary string that usually provides guidelines on when this priority class should be used."))
cmd.Flags().Bool("preempting", false, i18n.T("preempting specifies whether a pod with this PriorityClass could trigger a preemption process."))
return cmd
}
@ -84,12 +86,13 @@ func (o *PriorityClassOpts) Complete(f cmdutil.Factory, cmd *cobra.Command, args
var generator generate.StructuredGenerator
switch generatorName := cmdutil.GetFlagString(cmd, "generator"); generatorName {
case generateversioned.PriorityClassV1Alpha1GeneratorName:
case generateversioned.PriorityClassV1GeneratorName:
generator = &generateversioned.PriorityClassV1Generator{
Name: name,
Value: cmdutil.GetFlagInt32(cmd, "value"),
GlobalDefault: cmdutil.GetFlagBool(cmd, "global-default"),
Description: cmdutil.GetFlagString(cmd, "description"),
Preempting: cmdutil.GetFlagBool(cmd, "preempting"),
}
default:
return errUnsupportedGenerator(cmd, generatorName)

View File

@ -56,6 +56,7 @@ func TestCreatePriorityClass(t *testing.T) {
cmd.Flags().Set("value", "1000")
cmd.Flags().Set("global-default", "true")
cmd.Flags().Set("description", "my priority")
cmd.Flags().Set("preempting", "true")
cmd.Flags().Set("dry-run", "true")
cmd.Flags().Set("output", outputFormat)

View File

@ -69,6 +69,8 @@ const (
PodDisruptionBudgetV1GeneratorName = "poddisruptionbudget/v1beta1"
PodDisruptionBudgetV2GeneratorName = "poddisruptionbudget/v1beta1/v2"
PriorityClassV1Alpha1GeneratorName = "priorityclass/v1alpha1"
PriorityClassV1Beta1GeneratorName = "priorityclass/v1beta1"
PriorityClassV1GeneratorName = "priorityclass/v1"
)
// DefaultGenerators returns the set of default generators for use in Factory instances

View File

@ -31,6 +31,7 @@ type PriorityClassV1Generator struct {
Value int32
GlobalDefault bool
Description string
Preempting bool
}
// Ensure it supports the generator pattern that uses parameters specified during construction.
@ -42,9 +43,9 @@ func (PriorityClassV1Generator) ParamNames() []generate.GeneratorParam {
{Name: "value", Required: true},
{Name: "global-default", Required: false},
{Name: "description", Required: false},
{Name: "preempting", Required: false},
}
}
func (s PriorityClassV1Generator) Generate(params map[string]interface{}) (runtime.Object, error) {
if err := generate.ValidateParams(s.ParamNames(), params); err != nil {
return nil, err
@ -69,7 +70,13 @@ func (s PriorityClassV1Generator) Generate(params map[string]interface{}) (runti
if !found {
return nil, fmt.Errorf("expected string, found %v", description)
}
delegate := &PriorityClassV1Generator{Name: name, Value: value, GlobalDefault: globalDefault, Description: description}
Preempting, found := params["preempting"].(bool)
if !found {
return nil, fmt.Errorf("expected bool, found %v", Preempting)
}
delegate := &PriorityClassV1Generator{Name: name, Value: value, GlobalDefault: globalDefault, Description: description, Preempting: Preempting}
return delegate.StructuredGenerate()
}
@ -82,5 +89,6 @@ func (s *PriorityClassV1Generator) StructuredGenerate() (runtime.Object, error)
Value: s.Value,
GlobalDefault: s.GlobalDefault,
Description: s.Description,
Preempting: &s.Preempting,
}, nil
}

View File

@ -25,6 +25,8 @@ import (
)
func TestPriorityClassV1Generator(t *testing.T) {
true := true
false := false
tests := []struct {
name string
params map[string]interface{}
@ -38,6 +40,7 @@ func TestPriorityClassV1Generator(t *testing.T) {
"value": int32(1000),
"global-default": false,
"description": "high priority class",
"preempting": false,
},
expected: &scheduling.PriorityClass{
ObjectMeta: metav1.ObjectMeta{
@ -46,6 +49,27 @@ func TestPriorityClassV1Generator(t *testing.T) {
Value: int32(1000),
GlobalDefault: false,
Description: "high priority class",
Preempting: &false,
},
expectErr: false,
},
{
name: "test valid case that field non-preempting is set",
params: map[string]interface{}{
"name": "foo",
"value": int32(1000),
"global-default": false,
"description": "high priority class",
"preempting": true,
},
expected: &scheduling.PriorityClass{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
},
Value: int32(1000),
GlobalDefault: false,
Description: "high priority class",
Preempting: &true,
},
expectErr: false,
},
@ -56,6 +80,7 @@ func TestPriorityClassV1Generator(t *testing.T) {
"value": int32(1000),
"global-default": true,
"description": "high priority class",
"preempting": false,
},
expected: &scheduling.PriorityClass{
ObjectMeta: metav1.ObjectMeta{
@ -64,6 +89,7 @@ func TestPriorityClassV1Generator(t *testing.T) {
Value: int32(1000),
GlobalDefault: true,
Description: "high priority class",
Preempting: &false,
},
expectErr: false,
},
@ -73,6 +99,7 @@ func TestPriorityClassV1Generator(t *testing.T) {
"name": "foo",
"global-default": true,
"description": "high priority class",
"preempting": false,
},
expectErr: true,
},

View File

@ -1444,6 +1444,7 @@ func TestUpdateRcWithRetries(t *testing.T) {
one := int32(1)
grace := int64(30)
enableServiceLinks := corev1.DefaultEnableServiceLinks
preempting := corev1.DefaultPreempting
rc := &corev1.ReplicationController{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
@ -1471,6 +1472,7 @@ func TestUpdateRcWithRetries(t *testing.T) {
TerminationGracePeriodSeconds: &grace,
SecurityContext: &corev1.PodSecurityContext{},
EnableServiceLinks: &enableServiceLinks,
Preempting: &preempting,
},
},
},

View File

@ -38,6 +38,7 @@ func noDefault(*core.Pod) error { return nil }
func TestDecodeSinglePod(t *testing.T) {
grace := int64(30)
enableServiceLinks := v1.DefaultEnableServiceLinks
preempting := v1.DefaultPreempting
pod := &v1.Pod{
TypeMeta: metav1.TypeMeta{
APIVersion: "",
@ -62,6 +63,7 @@ func TestDecodeSinglePod(t *testing.T) {
SecurityContext: &v1.PodSecurityContext{},
SchedulerName: core.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
Preempting: &preempting,
},
}
json, err := runtime.Encode(testapi.Default.Codec(), pod)
@ -102,6 +104,7 @@ func TestDecodeSinglePod(t *testing.T) {
func TestDecodePodList(t *testing.T) {
grace := int64(30)
enableServiceLinks := v1.DefaultEnableServiceLinks
preempting := v1.DefaultPreempting
pod := &v1.Pod{
TypeMeta: metav1.TypeMeta{
APIVersion: "",
@ -127,6 +130,7 @@ func TestDecodePodList(t *testing.T) {
SecurityContext: &v1.PodSecurityContext{},
SchedulerName: core.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
Preempting: &preempting,
},
}
podList := &v1.PodList{

View File

@ -140,6 +140,7 @@ type testCase struct {
func getTestCases(hostname types.NodeName) []*testCase {
grace := int64(30)
enableServiceLinks := v1.DefaultEnableServiceLinks
preempting := v1.DefaultPreempting
return []*testCase{
{
lock: &sync.Mutex{},
@ -191,6 +192,7 @@ func getTestCases(hostname types.NodeName) []*testCase {
SecurityContext: &v1.PodSecurityContext{},
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
Preempting: &preempting,
},
Status: v1.PodStatus{
Phase: v1.PodPending,

View File

@ -130,6 +130,7 @@ func TestExtractPodsFromHTTP(t *testing.T) {
grace := int64(30)
enableServiceLinks := v1.DefaultEnableServiceLinks
preempting := v1.DefaultPreempting
var testCases = []struct {
desc string
pods runtime.Object
@ -175,6 +176,7 @@ func TestExtractPodsFromHTTP(t *testing.T) {
TerminationGracePeriodSeconds: &grace,
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
Preempting: &preempting,
Containers: []v1.Container{{
Name: "1",
@ -247,6 +249,7 @@ func TestExtractPodsFromHTTP(t *testing.T) {
SecurityContext: &v1.PodSecurityContext{},
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
Preempting: &preempting,
Containers: []v1.Container{{
Name: "1",
@ -276,6 +279,7 @@ func TestExtractPodsFromHTTP(t *testing.T) {
SecurityContext: &v1.PodSecurityContext{},
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
Preempting: &preempting,
Containers: []v1.Container{{
Name: "2",

View File

@ -59,6 +59,7 @@ func newStorage(t *testing.T) (*REST, *BindingREST, *StatusREST, *etcdtesting.Et
func validNewPod() *api.Pod {
grace := int64(30)
enableServiceLinks := v1.DefaultEnableServiceLinks
preempting := v1.DefaultPreempting
return &api.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
@ -83,6 +84,7 @@ func validNewPod() *api.Pod {
SecurityContext: &api.PodSecurityContext{},
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
Preempting: &preempting,
},
}
}
@ -783,6 +785,7 @@ func TestEtcdUpdateScheduled(t *testing.T) {
grace := int64(30)
enableServiceLinks := v1.DefaultEnableServiceLinks
preempting := v1.DefaultPreempting
podIn := api.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
@ -807,6 +810,7 @@ func TestEtcdUpdateScheduled(t *testing.T) {
SecurityContext: &api.PodSecurityContext{},
SchedulerName: api.DefaultSchedulerName,
EnableServiceLinks: &enableServiceLinks,
Preempting: &preempting,
},
}
_, _, err = storage.Update(ctx, podIn.Name, rest.DefaultUpdatedObjectInfo(&podIn), rest.ValidateAllObjectFunc, rest.ValidateAllObjectUpdateFunc, false, &metav1.UpdateOptions{})
@ -885,10 +889,12 @@ func TestEtcdUpdateStatus(t *testing.T) {
expected.ResourceVersion = "2"
grace := int64(30)
enableServiceLinks := v1.DefaultEnableServiceLinks
preempting := v1.DefaultPreempting
expected.Spec.TerminationGracePeriodSeconds = &grace
expected.Spec.RestartPolicy = api.RestartPolicyAlways
expected.Spec.DNSPolicy = api.DNSClusterFirst
expected.Spec.EnableServiceLinks = &enableServiceLinks
expected.Spec.Preempting = &preempting
expected.Spec.Containers[0].ImagePullPolicy = api.PullIfNotPresent
expected.Spec.Containers[0].TerminationMessagePath = api.TerminationMessagePathDefault
expected.Spec.Containers[0].TerminationMessagePolicy = api.TerminationMessageReadFile

View File

@ -32,6 +32,7 @@ go_library(
"//staging/src/k8s.io/client-go/informers/apps/v1:go_default_library",
"//staging/src/k8s.io/client-go/informers/core/v1:go_default_library",
"//staging/src/k8s.io/client-go/informers/policy/v1beta1:go_default_library",
"//staging/src/k8s.io/client-go/informers/scheduling/v1:go_default_library",
"//staging/src/k8s.io/client-go/informers/storage/v1:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
"//staging/src/k8s.io/client-go/listers/core/v1:go_default_library",

View File

@ -16,6 +16,7 @@ go_library(
"//staging/src/k8s.io/api/apps/v1:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/api/policy/v1beta1:go_default_library",
"//staging/src/k8s.io/api/scheduling/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
],
)

View File

@ -20,10 +20,17 @@ import (
apps "k8s.io/api/apps/v1"
"k8s.io/api/core/v1"
policyv1beta1 "k8s.io/api/policy/v1beta1"
scheduling "k8s.io/api/scheduling/v1"
"k8s.io/apimachinery/pkg/labels"
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
)
// PriorityClassLister represents anything that can get PriorityClass object
type PriorityClassLister interface {
// Get retrieves the PriorityClass from the index for a given name.
Get(name string) (*scheduling.PriorityClass, error)
}
// NodeFieldSelectorKeys is a map that: the key are node field selector keys; the values are
// the functions to get the value of the node field.
var NodeFieldSelectorKeys = map[string]func(*v1.Node) string{

View File

@ -1109,6 +1109,7 @@ func TestCompatibility_v1_Scheduler(t *testing.T) {
ServiceInformer: informerFactory.Core().V1().Services(),
PdbInformer: informerFactory.Policy().V1beta1().PodDisruptionBudgets(),
StorageClassInformer: informerFactory.Storage().V1().StorageClasses(),
PriorityClassInformer: informerFactory.Scheduling().V1().PriorityClasses(),
HardPodAffinitySymmetricWeight: v1.DefaultHardPodAffinitySymmetricWeight,
DisablePreemption: false,
PercentageOfNodesToScore: schedulerapi.DefaultPercentageOfNodesToScore,

View File

@ -547,6 +547,7 @@ func TestGenericSchedulerWithExtenders(t *testing.T) {
nil,
schedulertesting.FakePersistentVolumeClaimLister{},
schedulertesting.FakePDBLister{},
schedulertesting.FakePriorityClassLister{},
false,
false,
schedulerapi.DefaultPercentageOfNodesToScore)

View File

@ -166,6 +166,7 @@ type genericScheduler struct {
volumeBinder *volumebinder.VolumeBinder
pvcLister corelisters.PersistentVolumeClaimLister
pdbLister algorithm.PDBLister
priorityClassLister algorithm.PriorityClassLister
disablePreemption bool
lastIndex int
percentageOfNodesToScore int32
@ -1163,6 +1164,10 @@ func nodesWherePreemptionMightHelp(nodes []*v1.Node, failedPredicatesMap FailedP
// We look at the node that is nominated for this pod and as long as there are
// terminating pods on the node, we don't consider this for preempting more pods.
func podEligibleToPreemptOthers(pod *v1.Pod, nodeNameToInfo map[string]*schedulernodeinfo.NodeInfo) bool {
if pod.Spec.Preempting != nil && !*(pod.Spec.Preempting) {
klog.V(5).Infof("Pod %v/%v with this Preempting could not start a preemption process.", pod.Namespace, pod.Name)
return false
}
nomNodeName := pod.Status.NominatedNodeName
if len(nomNodeName) > 0 {
if nodeInfo, found := nodeNameToInfo[nomNodeName]; found {
@ -1217,6 +1222,7 @@ func NewGenericScheduler(
volumeBinder *volumebinder.VolumeBinder,
pvcLister corelisters.PersistentVolumeClaimLister,
pdbLister algorithm.PDBLister,
priorityClassLister algorithm.PriorityClassLister,
alwaysCheckAllPredicates bool,
disablePreemption bool,
percentageOfNodesToScore int32,
@ -1234,6 +1240,7 @@ func NewGenericScheduler(
volumeBinder: volumeBinder,
pvcLister: pvcLister,
pdbLister: pdbLister,
priorityClassLister: priorityClassLister,
alwaysCheckAllPredicates: alwaysCheckAllPredicates,
disablePreemption: disablePreemption,
percentageOfNodesToScore: percentageOfNodesToScore,

View File

@ -416,9 +416,9 @@ func TestGenericScheduler(t *testing.T) {
predicates: map[string]algorithmpredicates.FitPredicate{"true": truePredicate, "matches": matchesPredicate, "false": falsePredicate},
prioritizers: []priorities.PriorityConfig{{Map: EqualPriorityMap, Weight: 1}},
alwaysCheckAllPredicates: true,
nodes: []string{"1"},
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "2", UID: types.UID("2")}},
name: "test alwaysCheckAllPredicates is true",
nodes: []string{"1"},
pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "2", UID: types.UID("2")}},
name: "test alwaysCheckAllPredicates is true",
wErr: &FitError{
Pod: &v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: "2", UID: types.UID("2")}},
NumAllNodes: 1,
@ -462,6 +462,7 @@ func TestGenericScheduler(t *testing.T) {
nil,
pvcLister,
schedulertesting.FakePDBLister{},
schedulertesting.FakePriorityClassLister{},
test.alwaysCheckAllPredicates,
false,
schedulerapi.DefaultPercentageOfNodesToScore)
@ -493,7 +494,7 @@ func makeScheduler(predicates map[string]algorithmpredicates.FitPredicate, nodes
prioritizers,
priorities.EmptyPriorityMetadataProducer,
emptyFramework,
nil, nil, nil, nil, false, false,
nil, nil, nil, nil, nil, false, false,
schedulerapi.DefaultPercentageOfNodesToScore)
cache.UpdateNodeInfoSnapshot(s.(*genericScheduler).nodeInfoSnapshot)
return s.(*genericScheduler)
@ -1499,6 +1500,7 @@ func TestPreempt(t *testing.T) {
nil,
schedulertesting.FakePersistentVolumeClaimLister{},
schedulertesting.FakePDBLister{},
schedulertesting.FakePriorityClassLister{},
false,
false,
schedulerapi.DefaultPercentageOfNodesToScore)
@ -1559,7 +1561,7 @@ func TestNumFeasibleNodesToFind(t *testing.T) {
wantNumNodes: 10,
},
{
name: "set percentageOfNodesToScore and nodes number not more than 50",
name: "set percentageOfNodesToScore and nodes number not more than 50",
percentageOfNodesToScore: 40,
numAllNodes: 10,
wantNumNodes: 10,
@ -1570,7 +1572,7 @@ func TestNumFeasibleNodesToFind(t *testing.T) {
wantNumNodes: 420,
},
{
name: "set percentageOfNodesToScore and nodes number more than 50",
name: "set percentageOfNodesToScore and nodes number more than 50",
percentageOfNodesToScore: 40,
numAllNodes: 1000,
wantNumNodes: 400,
@ -1581,12 +1583,13 @@ func TestNumFeasibleNodesToFind(t *testing.T) {
wantNumNodes: 300,
},
{
name: "set percentageOfNodesToScore and nodes number more than 50*125",
name: "set percentageOfNodesToScore and nodes number more than 50*125",
percentageOfNodesToScore: 40,
numAllNodes: 6000,
wantNumNodes: 2400,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g := &genericScheduler{

View File

@ -35,11 +35,13 @@ go_library(
"//staging/src/k8s.io/client-go/informers/apps/v1:go_default_library",
"//staging/src/k8s.io/client-go/informers/core/v1:go_default_library",
"//staging/src/k8s.io/client-go/informers/policy/v1beta1:go_default_library",
"//staging/src/k8s.io/client-go/informers/scheduling/v1:go_default_library",
"//staging/src/k8s.io/client-go/informers/storage/v1:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
"//staging/src/k8s.io/client-go/listers/apps/v1:go_default_library",
"//staging/src/k8s.io/client-go/listers/core/v1:go_default_library",
"//staging/src/k8s.io/client-go/listers/policy/v1beta1:go_default_library",
"//staging/src/k8s.io/client-go/listers/scheduling/v1:go_default_library",
"//staging/src/k8s.io/client-go/listers/storage/v1:go_default_library",
"//staging/src/k8s.io/client-go/tools/cache:go_default_library",
"//staging/src/k8s.io/client-go/tools/record:go_default_library",

View File

@ -35,11 +35,13 @@ import (
appsinformers "k8s.io/client-go/informers/apps/v1"
coreinformers "k8s.io/client-go/informers/core/v1"
policyinformers "k8s.io/client-go/informers/policy/v1beta1"
schedulinginformers "k8s.io/client-go/informers/scheduling/v1"
storageinformers "k8s.io/client-go/informers/storage/v1"
clientset "k8s.io/client-go/kubernetes"
appslisters "k8s.io/client-go/listers/apps/v1"
corelisters "k8s.io/client-go/listers/core/v1"
policylisters "k8s.io/client-go/listers/policy/v1beta1"
schedulinglister "k8s.io/client-go/listers/scheduling/v1"
storagelisters "k8s.io/client-go/listers/storage/v1"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/record"
@ -185,6 +187,8 @@ type configFactory struct {
storageClassLister storagelisters.StorageClassLister
// framework has a set of plugins and the context used for running them.
framework framework.Framework
// a means to list all PriorityClass
priorityClassLister schedulinglister.PriorityClassLister
// Close this to stop all reflectors
StopEverything <-chan struct{}
@ -233,6 +237,7 @@ type ConfigFactoryArgs struct {
ServiceInformer coreinformers.ServiceInformer
PdbInformer policyinformers.PodDisruptionBudgetInformer
StorageClassInformer storageinformers.StorageClassInformer
PriorityClassInformer schedulinginformers.PriorityClassInformer
HardPodAffinitySymmetricWeight int32
DisablePreemption bool
PercentageOfNodesToScore int32
@ -276,6 +281,7 @@ func NewConfigFactory(args *ConfigFactoryArgs) Configurator {
pdbLister: args.PdbInformer.Lister(),
storageClassLister: storageClassLister,
framework: framework,
priorityClassLister: args.PriorityClassInformer.Lister(),
schedulerCache: schedulerCache,
StopEverything: stopEverything,
schedulerName: args.SchedulerName,
@ -463,6 +469,7 @@ func (c *configFactory) CreateFromKeys(predicateKeys, priorityKeys sets.String,
c.volumeBinder,
c.pVCLister,
c.pdbLister,
c.priorityClassLister,
c.alwaysCheckAllPredicates,
c.disablePreemption,
c.percentageOfNodesToScore,
@ -564,6 +571,7 @@ func (c *configFactory) getPluginArgs() (*PluginFactoryArgs, error) {
StorageClassInfo: &predicates.CachedStorageClassInfo{StorageClassLister: c.storageClassLister},
VolumeBinder: c.volumeBinder,
HardPodAffinitySymmetricWeight: c.hardPodAffinitySymmetricWeight,
PriorityLister: c.priorityClassLister,
}, nil
}

View File

@ -491,6 +491,7 @@ func newConfigFactory(client clientset.Interface, hardPodAffinitySymmetricWeight
informerFactory.Core().V1().Services(),
informerFactory.Policy().V1beta1().PodDisruptionBudgets(),
informerFactory.Storage().V1().StorageClasses(),
informerFactory.Scheduling().V1().PriorityClasses(),
hardPodAffinitySymmetricWeight,
disablePodPreemption,
schedulerapi.DefaultPercentageOfNodesToScore,

View File

@ -40,6 +40,7 @@ type PluginFactoryArgs struct {
ControllerLister algorithm.ControllerLister
ReplicaSetLister algorithm.ReplicaSetLister
StatefulSetLister algorithm.StatefulSetLister
PriorityLister algorithm.PriorityClassLister
NodeLister algorithm.NodeLister
PDBLister algorithm.PDBLister
NodeInfo predicates.NodeInfo

View File

@ -31,6 +31,7 @@ import (
appsinformers "k8s.io/client-go/informers/apps/v1"
coreinformers "k8s.io/client-go/informers/core/v1"
policyinformers "k8s.io/client-go/informers/policy/v1beta1"
schedulinginformers "k8s.io/client-go/informers/scheduling/v1"
storageinformers "k8s.io/client-go/informers/storage/v1"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/record"
@ -129,6 +130,7 @@ func New(client clientset.Interface,
serviceInformer coreinformers.ServiceInformer,
pdbInformer policyinformers.PodDisruptionBudgetInformer,
storageClassInformer storageinformers.StorageClassInformer,
priorityClassInformer schedulinginformers.PriorityClassInformer,
recorder record.EventRecorder,
schedulerAlgorithmSource kubeschedulerconfig.SchedulerAlgorithmSource,
stopCh <-chan struct{},
@ -155,6 +157,7 @@ func New(client clientset.Interface,
ServiceInformer: serviceInformer,
PdbInformer: pdbInformer,
StorageClassInformer: storageClassInformer,
PriorityClassInformer: priorityClassInformer,
HardPodAffinitySymmetricWeight: options.hardPodAffinitySymmetricWeight,
DisablePreemption: options.disablePreemption,
PercentageOfNodesToScore: options.percentageOfNodesToScore,

View File

@ -103,6 +103,7 @@ func (n *nodeLister) List() ([]*v1.Node, error) {
}
func podWithID(id, desiredHost string) *v1.Pod {
Preempting := true
return &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: id,
@ -110,7 +111,8 @@ func podWithID(id, desiredHost string) *v1.Pod {
SelfLink: fmt.Sprintf("/api/v1/%s/%s", string(v1.ResourcePods), id),
},
Spec: v1.PodSpec{
NodeName: desiredHost,
NodeName: desiredHost,
Preempting: &Preempting,
},
}
}
@ -200,6 +202,7 @@ func TestSchedulerCreation(t *testing.T) {
informerFactory.Core().V1().Services(),
informerFactory.Policy().V1beta1().PodDisruptionBudgets(),
informerFactory.Storage().V1().StorageClasses(),
informerFactory.Scheduling().V1().PriorityClasses(),
eventBroadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "scheduler"}),
kubeschedulerconfig.SchedulerAlgorithmSource{Provider: &testSource},
stopCh,
@ -658,6 +661,7 @@ func setupTestScheduler(queuedPodStore *clientcache.FIFO, scache internalcache.C
nil,
informerFactory.Core().V1().PersistentVolumeClaims().Lister(),
informerFactory.Policy().V1beta1().PodDisruptionBudgets().Lister(),
informerFactory.Scheduling().V1().PriorityClasses().Lister(),
false,
false,
schedulerapi.DefaultPercentageOfNodesToScore,
@ -711,6 +715,7 @@ func setupTestSchedulerLongBindingWithRetry(queuedPodStore *clientcache.FIFO, sc
nil,
informerFactory.Core().V1().PersistentVolumeClaims().Lister(),
informerFactory.Policy().V1beta1().PodDisruptionBudgets().Lister(),
informerFactory.Scheduling().V1().PriorityClasses().Lister(),
false,
false,
schedulerapi.DefaultPercentageOfNodesToScore,

View File

@ -11,6 +11,7 @@ go_library(
"//staging/src/k8s.io/api/apps/v1:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/api/policy/v1beta1:go_default_library",
"//staging/src/k8s.io/api/scheduling/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
"//staging/src/k8s.io/client-go/listers/core/v1:go_default_library",

View File

@ -22,6 +22,7 @@ import (
apps "k8s.io/api/apps/v1"
"k8s.io/api/core/v1"
policy "k8s.io/api/policy/v1beta1"
schedulingv1 "k8s.io/api/scheduling/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
corelisters "k8s.io/client-go/listers/core/v1"
@ -222,3 +223,12 @@ type FakePDBLister []*policy.PodDisruptionBudget
func (f FakePDBLister) List(labels.Selector) ([]*policy.PodDisruptionBudget, error) {
return f, nil
}
// FakePriorityClassLister implements PriorityClassLister on a slice of Priority for test purposes.
type FakePriorityClassLister schedulingv1.PriorityClass
// Get returns a PriorityClass by name.
func (f FakePriorityClassLister) Get(name string) (*schedulingv1.PriorityClass, error) {
pc := schedulingv1.PriorityClass(f)
return &pc, nil
}

View File

@ -179,6 +179,7 @@ func (p *priorityPlugin) admitPod(a admission.Attributes) error {
if operation == admission.Create {
var priority int32
var preempting *bool
// TODO: @ravig - This is for backwards compatibility to ensure that critical pods with annotations just work fine.
// Remove when no longer needed.
if len(pod.Spec.PriorityClassName) == 0 &&
@ -189,7 +190,7 @@ func (p *priorityPlugin) admitPod(a admission.Attributes) error {
if len(pod.Spec.PriorityClassName) == 0 {
var err error
var pcName string
pcName, priority, err = p.getDefaultPriority()
pcName, priority, preempting, err = p.getDefaultPriority()
if err != nil {
return fmt.Errorf("failed to get default priority class: %v", err)
}
@ -211,12 +212,14 @@ func (p *priorityPlugin) admitPod(a admission.Attributes) error {
}
priority = pc.Value
preempting = pc.Preempting
}
// if the pod contained a priority that differs from the one computed from the priority class, error
if pod.Spec.Priority != nil && *pod.Spec.Priority != priority {
return admission.NewForbidden(a, fmt.Errorf("the integer value of priority (%d) must not be provided in pod spec; priority admission controller computed %d from the given PriorityClass name", *pod.Spec.Priority, priority))
}
pod.Spec.Priority = &priority
pod.Spec.Preempting = preempting
}
return nil
}
@ -262,14 +265,15 @@ func (p *priorityPlugin) getDefaultPriorityClass() (*schedulingv1.PriorityClass,
return defaultPC, nil
}
func (p *priorityPlugin) getDefaultPriority() (string, int32, error) {
func (p *priorityPlugin) getDefaultPriority() (string, int32, *bool, error) {
dpc, err := p.getDefaultPriorityClass()
if err != nil {
return "", 0, err
return "", 0, nil, err
}
if dpc != nil {
return dpc.Name, dpc.Value, nil
return dpc.Name, dpc.Value, dpc.Preempting, nil
}
preempting := true
return "", int32(scheduling.DefaultPriorityWhenNoDefaultClassExists), nil
return "", int32(scheduling.DefaultPriorityWhenNoDefaultClassExists), &preempting, nil
}

View File

@ -246,7 +246,7 @@ func TestDefaultPriority(t *testing.T) {
if err := addPriorityClasses(ctrl, test.classesBefore); err != nil {
t.Errorf("Test %q: unable to add object to informer: %v", test.name, err)
}
pcName, defaultPriority, err := ctrl.getDefaultPriority()
pcName, defaultPriority, _, err := ctrl.getDefaultPriority()
if err != nil {
t.Errorf("Test %q: unexpected error while getting default priority: %v", test.name, err)
}
@ -264,7 +264,7 @@ func TestDefaultPriority(t *testing.T) {
if err := addPriorityClasses(ctrl, test.classesAfter); err != nil {
t.Errorf("Test %q: unable to add object to informer: %v", test.name, err)
}
pcName, defaultPriority, err = ctrl.getDefaultPriority()
pcName, defaultPriority, _, err = ctrl.getDefaultPriority()
if err != nil {
t.Errorf("Test %q: unexpected error while getting default priority: %v", test.name, err)
}

View File

@ -48,6 +48,7 @@ const (
extensionsGroup = "extensions"
policyGroup = "policy"
rbacGroup = "rbac.authorization.k8s.io"
schedulingGroup = "scheduling.k8s.io"
storageGroup = "storage.k8s.io"
resMetricsGroup = "metrics.k8s.io"
customMetricsGroup = "custom.metrics.k8s.io"
@ -442,6 +443,7 @@ func ClusterRoles() []rbacv1.ClusterRole {
// Needed to check API access. These creates are non-mutating
rbacv1helpers.NewRule("create").Groups(authenticationGroup).Resources("tokenreviews").RuleOrDie(),
rbacv1helpers.NewRule("create").Groups(authorizationGroup).Resources("subjectaccessreviews").RuleOrDie(),
rbacv1helpers.NewRule(Read...).Groups(schedulingGroup).Resources("priorityclasses").RuleOrDie(),
},
},
{

View File

@ -801,6 +801,14 @@ items:
- subjectaccessreviews
verbs:
- create
- apiGroups:
- scheduling.k8s.io
resources:
- priorityclasses
verbs:
- get
- list
- watch
- apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:

File diff suppressed because it is too large Load Diff

View File

@ -3181,6 +3181,11 @@ message PodSpec {
// +optional
optional int32 priority = 25;
// Preempting specifies whether a pod with this PriorityClass could start a preemption process.
// If this field is missing, the PriorityClass is considered a Preempting class by default.
// +optional
optional bool preempting = 31;
// Specifies the DNS parameters of a pod.
// Parameters specified here will be merged to the generated DNS
// configuration based on DNSPolicy.

View File

@ -2961,6 +2961,10 @@ type PodSpec struct {
// The higher the value, the higher the priority.
// +optional
Priority *int32 `json:"priority,omitempty" protobuf:"bytes,25,opt,name=priority"`
// Preempting specifies whether a pod with this PriorityClass could start a preemption process.
// If this field is missing, the PriorityClass is considered a Preempting class by default.
// +optional
Preempting *bool `json:"preempting,omitempty" protobuf:"bytes,31,opt,name=preempting"`
// Specifies the DNS parameters of a pod.
// Parameters specified here will be merged to the generated DNS
// configuration based on DNSPolicy.
@ -2991,6 +2995,9 @@ type PodSpec struct {
const (
// The default value for enableServiceLinks attribute.
DefaultEnableServiceLinks = true
// The default value for preempting attribute.
DefaultPreempting = true
)
// HostAlias holds the mapping between IP and hostnames that will be injected as an entry in the

View File

@ -1552,6 +1552,7 @@ var map_PodSpec = map[string]string{
"hostAliases": "HostAliases is an optional list of hosts and IPs that will be injected into the pod's hosts file if specified. This is only valid for non-hostNetwork pods.",
"priorityClassName": "If specified, indicates the pod's priority. \"system-node-critical\" and \"system-cluster-critical\" are two special keywords which indicate the highest priorities with the former being the highest priority. Any other name must be defined by creating a PriorityClass object with that name. If not specified, the pod priority will be default or zero if there is no default.",
"priority": "The priority value. Various system components use this field to find the priority of the pod. When Priority Admission Controller is enabled, it prevents users from setting this field. The admission controller populates this field from PriorityClassName. The higher the value, the higher the priority.",
"preempting": "Preempting specifies whether a pod with this PriorityClass could start a preemption process. If this field is missing, the PriorityClass is considered a Preempting class by default.",
"dnsConfig": "Specifies the DNS parameters of a pod. Parameters specified here will be merged to the generated DNS configuration based on DNSPolicy.",
"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/0007-pod-ready%2B%2B.md",
"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/runtime-class.md This is a beta feature as of Kubernetes v1.14.",

View File

@ -3608,6 +3608,11 @@ func (in *PodSpec) DeepCopyInto(out *PodSpec) {
*out = new(int32)
**out = **in
}
if in.Preempting != nil {
in, out := &in.Preempting, &out.Preempting
*out = new(bool)
**out = **in
}
if in.DNSConfig != nil {
in, out := &in.DNSConfig, &out.DNSConfig
*out = new(PodDNSConfig)

View File

@ -99,6 +99,16 @@ func (m *PriorityClass) MarshalTo(dAtA []byte) (int, error) {
i++
i = encodeVarintGenerated(dAtA, i, uint64(len(m.Description)))
i += copy(dAtA[i:], m.Description)
if m.Preempting != nil {
dAtA[i] = 0x28
i++
if *m.Preempting {
dAtA[i] = 1
} else {
dAtA[i] = 0
}
i++
}
return i, nil
}
@ -158,6 +168,9 @@ func (m *PriorityClass) Size() (n int) {
n += 2
l = len(m.Description)
n += 1 + l + sovGenerated(uint64(l))
if m.Preempting != nil {
n += 2
}
return n
}
@ -197,6 +210,7 @@ func (this *PriorityClass) String() string {
`Value:` + fmt.Sprintf("%v", this.Value) + `,`,
`GlobalDefault:` + fmt.Sprintf("%v", this.GlobalDefault) + `,`,
`Description:` + fmt.Sprintf("%v", this.Description) + `,`,
`Preempting:` + valueToStringGenerated(this.Preempting) + `,`,
`}`,
}, "")
return s
@ -347,6 +361,27 @@ func (m *PriorityClass) Unmarshal(dAtA []byte) error {
}
m.Description = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 5:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Preempting", wireType)
}
var v int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowGenerated
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
v |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
b := bool(v != 0)
m.Preempting = &b
default:
iNdEx = preIndex
skippy, err := skipGenerated(dAtA[iNdEx:])
@ -589,33 +624,34 @@ func init() {
}
var fileDescriptorGenerated = []byte{
// 442 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x3f, 0x8b, 0xd4, 0x40,
0x18, 0xc6, 0x33, 0x7b, 0x2e, 0xac, 0xb3, 0x2c, 0x68, 0x44, 0x08, 0x5b, 0xcc, 0x85, 0xb3, 0x30,
0x8d, 0x33, 0xee, 0xa1, 0x22, 0x58, 0x19, 0x0f, 0x44, 0x38, 0x51, 0x52, 0x58, 0x88, 0x85, 0x93,
0xe4, 0xbd, 0xec, 0xb8, 0x49, 0x26, 0xcc, 0x4c, 0x02, 0xd7, 0x59, 0x5b, 0xf9, 0x8d, 0x6c, 0xb7,
0xbc, 0xf2, 0xaa, 0xc3, 0x8d, 0x5f, 0x44, 0xf2, 0xc7, 0xcb, 0xae, 0xe7, 0xe1, 0x75, 0x99, 0xe7,
0x7d, 0x7e, 0xcf, 0x3b, 0x79, 0x18, 0xfc, 0x72, 0xf5, 0x5c, 0x53, 0x21, 0xd9, 0xaa, 0x0c, 0x41,
0xe5, 0x60, 0x40, 0xb3, 0x0a, 0xf2, 0x58, 0x2a, 0xd6, 0x0f, 0x78, 0x21, 0x98, 0x8e, 0x96, 0x10,
0x97, 0xa9, 0xc8, 0x13, 0x56, 0x2d, 0x58, 0x02, 0x39, 0x28, 0x6e, 0x20, 0xa6, 0x85, 0x92, 0x46,
0xda, 0x4e, 0xe7, 0xa4, 0xbc, 0x10, 0x74, 0x70, 0xd2, 0x6a, 0x31, 0x7f, 0x94, 0x08, 0xb3, 0x2c,
0x43, 0x1a, 0xc9, 0x8c, 0x25, 0x32, 0x91, 0xac, 0x05, 0xc2, 0xf2, 0xa4, 0x3d, 0xb5, 0x87, 0xf6,
0xab, 0x0b, 0x9a, 0x3f, 0x19, 0x56, 0x66, 0x3c, 0x5a, 0x8a, 0x1c, 0xd4, 0x29, 0x2b, 0x56, 0x49,
0x23, 0x68, 0x96, 0x81, 0xe1, 0xff, 0x58, 0x3f, 0x67, 0xd7, 0x51, 0xaa, 0xcc, 0x8d, 0xc8, 0xe0,
0x0a, 0xf0, 0xec, 0x7f, 0x40, 0xf3, 0x13, 0x19, 0xff, 0x9b, 0x3b, 0xf8, 0x36, 0xc2, 0xb3, 0xf7,
0x4a, 0x48, 0x25, 0xcc, 0xe9, 0xab, 0x94, 0x6b, 0x6d, 0x7f, 0xc6, 0x93, 0xe6, 0x56, 0x31, 0x37,
0xdc, 0x41, 0x2e, 0xf2, 0xa6, 0x87, 0x8f, 0xe9, 0x50, 0xc6, 0x65, 0x38, 0x2d, 0x56, 0x49, 0x23,
0x68, 0xda, 0xb8, 0x69, 0xb5, 0xa0, 0xef, 0xc2, 0x2f, 0x10, 0x99, 0xb7, 0x60, 0xb8, 0x6f, 0xaf,
0x2f, 0xf6, 0xad, 0xfa, 0x62, 0x1f, 0x0f, 0x5a, 0x70, 0x99, 0x6a, 0x3f, 0xc0, 0xe3, 0x8a, 0xa7,
0x25, 0x38, 0x23, 0x17, 0x79, 0x63, 0x7f, 0xd6, 0x9b, 0xc7, 0x1f, 0x1a, 0x31, 0xe8, 0x66, 0xf6,
0x0b, 0x3c, 0x4b, 0x52, 0x19, 0xf2, 0xf4, 0x08, 0x4e, 0x78, 0x99, 0x1a, 0x67, 0xcf, 0x45, 0xde,
0xc4, 0xbf, 0xdf, 0x9b, 0x67, 0xaf, 0xb7, 0x87, 0xc1, 0xae, 0xd7, 0x7e, 0x8a, 0xa7, 0x31, 0xe8,
0x48, 0x89, 0xc2, 0x08, 0x99, 0x3b, 0xb7, 0x5c, 0xe4, 0xdd, 0xf6, 0xef, 0xf5, 0xe8, 0xf4, 0x68,
0x18, 0x05, 0xdb, 0xbe, 0x83, 0x1f, 0x08, 0xdf, 0xdd, 0x29, 0xe3, 0x58, 0x68, 0x63, 0x7f, 0xba,
0x52, 0x08, 0xbd, 0x59, 0x21, 0x0d, 0xdd, 0xd6, 0x71, 0xa7, 0xdf, 0x3c, 0xf9, 0xa3, 0x6c, 0x95,
0x71, 0x8c, 0xc7, 0xc2, 0x40, 0xa6, 0x9d, 0x91, 0xbb, 0xe7, 0x4d, 0x0f, 0x1f, 0xd2, 0xeb, 0x1e,
0x1e, 0xdd, 0xb9, 0xd9, 0xd0, 0xda, 0x9b, 0x86, 0x0e, 0xba, 0x10, 0xdf, 0x5b, 0x6f, 0x88, 0x75,
0xb6, 0x21, 0xd6, 0xf9, 0x86, 0x58, 0x5f, 0x6b, 0x82, 0xd6, 0x35, 0x41, 0x67, 0x35, 0x41, 0xe7,
0x35, 0x41, 0x3f, 0x6b, 0x82, 0xbe, 0xff, 0x22, 0xd6, 0xc7, 0x51, 0xb5, 0xf8, 0x1d, 0x00, 0x00,
0xff, 0xff, 0x32, 0xe8, 0x23, 0x88, 0x24, 0x03, 0x00, 0x00,
// 464 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0x3f, 0x6f, 0xd3, 0x40,
0x18, 0xc6, 0x73, 0x29, 0x96, 0xc2, 0x45, 0x41, 0x60, 0x84, 0x64, 0x65, 0x70, 0xad, 0x32, 0xe0,
0x85, 0x3b, 0x52, 0x01, 0x42, 0x62, 0xc2, 0x54, 0x42, 0x48, 0x45, 0x54, 0x1e, 0x18, 0x10, 0x03,
0x67, 0xfb, 0xad, 0x73, 0xc4, 0xf6, 0x59, 0x77, 0x67, 0x4b, 0xdd, 0xf8, 0x08, 0x7c, 0x1e, 0x16,
0xd6, 0x8c, 0x1d, 0x3b, 0x55, 0xc4, 0x7c, 0x11, 0x74, 0x8e, 0x89, 0x13, 0x4a, 0x45, 0x37, 0xdf,
0xf3, 0x3e, 0xbf, 0xf7, 0xcf, 0x23, 0xe3, 0x57, 0x8b, 0x17, 0x8a, 0x70, 0x41, 0x17, 0x55, 0x04,
0xb2, 0x00, 0x0d, 0x8a, 0xd6, 0x50, 0x24, 0x42, 0xd2, 0xae, 0xc0, 0x4a, 0x4e, 0x55, 0x3c, 0x87,
0xa4, 0xca, 0x78, 0x91, 0xd2, 0x7a, 0x46, 0x53, 0x28, 0x40, 0x32, 0x0d, 0x09, 0x29, 0xa5, 0xd0,
0xc2, 0x76, 0xd6, 0x4e, 0xc2, 0x4a, 0x4e, 0x7a, 0x27, 0xa9, 0x67, 0xd3, 0xc7, 0x29, 0xd7, 0xf3,
0x2a, 0x22, 0xb1, 0xc8, 0x69, 0x2a, 0x52, 0x41, 0x5b, 0x20, 0xaa, 0x4e, 0xdb, 0x57, 0xfb, 0x68,
0xbf, 0xd6, 0x8d, 0xa6, 0x4f, 0xfb, 0x91, 0x39, 0x8b, 0xe7, 0xbc, 0x00, 0x79, 0x46, 0xcb, 0x45,
0x6a, 0x04, 0x45, 0x73, 0xd0, 0xec, 0x1f, 0xe3, 0xa7, 0xf4, 0x3a, 0x4a, 0x56, 0x85, 0xe6, 0x39,
0x5c, 0x01, 0x9e, 0xff, 0x0f, 0x30, 0x47, 0xe4, 0xec, 0x6f, 0xee, 0xe0, 0xfb, 0x10, 0x4f, 0x4e,
0x24, 0x17, 0x92, 0xeb, 0xb3, 0xd7, 0x19, 0x53, 0xca, 0xfe, 0x8c, 0x47, 0x66, 0xab, 0x84, 0x69,
0xe6, 0x20, 0x0f, 0xf9, 0xe3, 0xc3, 0x27, 0xa4, 0x0f, 0x63, 0xd3, 0x9c, 0x94, 0x8b, 0xd4, 0x08,
0x8a, 0x18, 0x37, 0xa9, 0x67, 0xe4, 0x7d, 0xf4, 0x05, 0x62, 0xfd, 0x0e, 0x34, 0x0b, 0xec, 0xe5,
0xe5, 0xfe, 0xa0, 0xb9, 0xdc, 0xc7, 0xbd, 0x16, 0x6e, 0xba, 0xda, 0x0f, 0xb1, 0x55, 0xb3, 0xac,
0x02, 0x67, 0xe8, 0x21, 0xdf, 0x0a, 0x26, 0x9d, 0xd9, 0xfa, 0x60, 0xc4, 0x70, 0x5d, 0xb3, 0x5f,
0xe2, 0x49, 0x9a, 0x89, 0x88, 0x65, 0x47, 0x70, 0xca, 0xaa, 0x4c, 0x3b, 0x7b, 0x1e, 0xf2, 0x47,
0xc1, 0x83, 0xce, 0x3c, 0x79, 0xb3, 0x5d, 0x0c, 0x77, 0xbd, 0xf6, 0x33, 0x3c, 0x4e, 0x40, 0xc5,
0x92, 0x97, 0x9a, 0x8b, 0xc2, 0xb9, 0xe5, 0x21, 0xff, 0x76, 0x70, 0xbf, 0x43, 0xc7, 0x47, 0x7d,
0x29, 0xdc, 0xf6, 0xd9, 0x04, 0xe3, 0x52, 0x02, 0xe4, 0xa5, 0xe6, 0x45, 0xea, 0x58, 0xed, 0xc0,
0x3b, 0xe6, 0x8c, 0x93, 0x8d, 0x1a, 0x6e, 0x39, 0x0e, 0x7e, 0x20, 0x7c, 0x6f, 0x27, 0xbc, 0x63,
0xae, 0xb4, 0xfd, 0xe9, 0x4a, 0x80, 0xe4, 0x66, 0x01, 0x1a, 0xba, 0x8d, 0xef, 0x6e, 0xb7, 0xe9,
0xe8, 0x8f, 0xb2, 0x15, 0xde, 0x31, 0xb6, 0xb8, 0x86, 0x5c, 0x39, 0x43, 0x6f, 0xcf, 0x1f, 0x1f,
0x3e, 0x22, 0xd7, 0xfd, 0xa8, 0x64, 0x67, 0xb3, 0x3e, 0xe5, 0xb7, 0x86, 0x0e, 0xd7, 0x4d, 0x02,
0x7f, 0xb9, 0x72, 0x07, 0xe7, 0x2b, 0x77, 0x70, 0xb1, 0x72, 0x07, 0x5f, 0x1b, 0x17, 0x2d, 0x1b,
0x17, 0x9d, 0x37, 0x2e, 0xba, 0x68, 0x5c, 0xf4, 0xb3, 0x71, 0xd1, 0xb7, 0x5f, 0xee, 0xe0, 0xe3,
0xb0, 0x9e, 0xfd, 0x0e, 0x00, 0x00, 0xff, 0xff, 0xd0, 0xe3, 0x15, 0x16, 0x54, 0x03, 0x00, 0x00,
}

View File

@ -52,6 +52,11 @@ message PriorityClass {
// when this priority class should be used.
// +optional
optional string description = 4;
// Preempting specifies whether a pod with this PriorityClass could trigger a preemption process.
// If this field is unset, the PriorityClass is considered a Preempting class by default.
// +optional
optional bool preempting = 5;
}
// PriorityClassList is a collection of priority classes.

View File

@ -49,6 +49,11 @@ type PriorityClass struct {
// when this priority class should be used.
// +optional
Description string `json:"description,omitempty" protobuf:"bytes,4,opt,name=description"`
// Preempting specifies whether a pod with this PriorityClass could trigger a preemption process.
// If this field is unset, the PriorityClass is considered a Preempting class by default.
// +optional
Preempting *bool `json:"preempting,omitempty" protobuf:"bytes,5,opt,name=preempting"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

View File

@ -33,6 +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.",
"preempting": "Preempting specifies whether a pod with this PriorityClass could trigger a preemption process. If this field is unset, the PriorityClass is considered a Preempting class by default.",
}
func (PriorityClass) SwaggerDoc() map[string]string {

View File

@ -29,6 +29,11 @@ func (in *PriorityClass) DeepCopyInto(out *PriorityClass) {
*out = *in
out.TypeMeta = in.TypeMeta
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
if in.Preempting != nil {
in, out := &in.Preempting, &out.Preempting
*out = new(bool)
**out = **in
}
return
}

View File

@ -120,6 +120,9 @@ func roundTripTypes(t *testing.T, scheme *runtime.Scheme, codecFactory runtimese
internalKindToGoType := scheme.KnownTypes(internalVersion)
for kind := range internalKindToGoType {
if kind != "PriorityClassList" {
continue
}
if globalNonRoundTrippableTypes.Has(kind) {
continue
}

View File

@ -110,6 +110,7 @@ func setupScheduler(
ServiceInformer: informerFactory.Core().V1().Services(),
PdbInformer: informerFactory.Policy().V1beta1().PodDisruptionBudgets(),
StorageClassInformer: informerFactory.Storage().V1().StorageClasses(),
PriorityClassInformer: informerFactory.Scheduling().V1().PriorityClasses(),
HardPodAffinitySymmetricWeight: v1.DefaultHardPodAffinitySymmetricWeight,
DisablePreemption: false,
PercentageOfNodesToScore: 100,

View File

@ -254,6 +254,7 @@ priorities: []
informerFactory.Core().V1().Services(),
informerFactory.Policy().V1beta1().PodDisruptionBudgets(),
informerFactory.Storage().V1().StorageClasses(),
informerFactory.Scheduling().V1().PriorityClasses(),
eventBroadcaster.NewRecorder(legacyscheme.Scheme, v1.EventSource{Component: v1.DefaultSchedulerName}),
kubeschedulerconfig.SchedulerAlgorithmSource{
Policy: &kubeschedulerconfig.SchedulerPolicySource{
@ -325,6 +326,7 @@ func TestSchedulerCreationFromNonExistentConfigMap(t *testing.T) {
informerFactory.Core().V1().Services(),
informerFactory.Policy().V1beta1().PodDisruptionBudgets(),
informerFactory.Storage().V1().StorageClasses(),
informerFactory.Scheduling().V1().PriorityClasses(),
eventBroadcaster.NewRecorder(legacyscheme.Scheme, v1.EventSource{Component: v1.DefaultSchedulerName}),
kubeschedulerconfig.SchedulerAlgorithmSource{
Policy: &kubeschedulerconfig.SchedulerPolicySource{

View File

@ -97,6 +97,7 @@ func createConfiguratorWithPodInformer(
ServiceInformer: informerFactory.Core().V1().Services(),
PdbInformer: informerFactory.Policy().V1beta1().PodDisruptionBudgets(),
StorageClassInformer: informerFactory.Storage().V1().StorageClasses(),
PriorityClassInformer: informerFactory.Scheduling().V1().PriorityClasses(),
Registry: pluginRegistry,
Plugins: plugins,
PluginConfig: pluginConfig,

View File

@ -118,6 +118,7 @@ func createSchedulerConfigurator(
ServiceInformer: informerFactory.Core().V1().Services(),
PdbInformer: informerFactory.Policy().V1beta1().PodDisruptionBudgets(),
StorageClassInformer: informerFactory.Storage().V1().StorageClasses(),
PriorityClassInformer: informerFactory.Scheduling().V1().PriorityClasses(),
HardPodAffinitySymmetricWeight: v1.DefaultHardPodAffinitySymmetricWeight,
DisablePreemption: false,
PercentageOfNodesToScore: schedulerapi.DefaultPercentageOfNodesToScore,