mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-12-03 21:04:47 +00:00
Add types for Scheduler plugin args to kube-scheduler.config.k8s.io
This commit is contained in:
@@ -19,6 +19,7 @@ go_library(
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
|
||||
"//staging/src/k8s.io/kube-scheduler/config/v1alpha2:go_default_library",
|
||||
"//vendor/k8s.io/klog:go_default_library",
|
||||
"//vendor/k8s.io/utils/pointer:go_default_library",
|
||||
],
|
||||
@@ -37,6 +38,7 @@ go_test(
|
||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
"//staging/src/k8s.io/kube-scheduler/config/v1alpha2:go_default_library",
|
||||
"//vendor/k8s.io/utils/pointer:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||
schedulerv1alpha2 "k8s.io/kube-scheduler/config/v1alpha2"
|
||||
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
||||
"k8s.io/utils/pointer"
|
||||
)
|
||||
@@ -38,13 +39,6 @@ const (
|
||||
MaxHardPodAffinityWeight int32 = 100
|
||||
)
|
||||
|
||||
// Args holds the args that are used to configure the plugin.
|
||||
type Args struct {
|
||||
// HardPodAffinityWeight is the scoring weight for existing pods with a
|
||||
// matching hard affinity to the incoming pod.
|
||||
HardPodAffinityWeight *int32 `json:"hardPodAffinityWeight,omitempty"`
|
||||
}
|
||||
|
||||
var _ framework.PreFilterPlugin = &InterPodAffinity{}
|
||||
var _ framework.FilterPlugin = &InterPodAffinity{}
|
||||
var _ framework.PreScorePlugin = &InterPodAffinity{}
|
||||
@@ -52,7 +46,7 @@ var _ framework.ScorePlugin = &InterPodAffinity{}
|
||||
|
||||
// InterPodAffinity is a plugin that checks inter pod affinity
|
||||
type InterPodAffinity struct {
|
||||
Args
|
||||
args schedulerv1alpha2.InterPodAffinityArgs
|
||||
sharedLister framework.SharedLister
|
||||
sync.Mutex
|
||||
}
|
||||
@@ -64,7 +58,7 @@ func (pl *InterPodAffinity) Name() string {
|
||||
|
||||
// BuildArgs returns the args that were used to build the plugin.
|
||||
func (pl *InterPodAffinity) BuildArgs() interface{} {
|
||||
return pl.Args
|
||||
return pl.args
|
||||
}
|
||||
|
||||
// New initializes a new plugin and returns it.
|
||||
@@ -75,19 +69,19 @@ func New(plArgs *runtime.Unknown, h framework.FrameworkHandle) (framework.Plugin
|
||||
pl := &InterPodAffinity{
|
||||
sharedLister: h.SnapshotSharedLister(),
|
||||
}
|
||||
if err := framework.DecodeInto(plArgs, &pl.Args); err != nil {
|
||||
if err := framework.DecodeInto(plArgs, &pl.args); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := validateArgs(&pl.Args); err != nil {
|
||||
if err := validateArgs(&pl.args); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if pl.HardPodAffinityWeight == nil {
|
||||
pl.HardPodAffinityWeight = pointer.Int32Ptr(DefaultHardPodAffinityWeight)
|
||||
if pl.args.HardPodAffinityWeight == nil {
|
||||
pl.args.HardPodAffinityWeight = pointer.Int32Ptr(DefaultHardPodAffinityWeight)
|
||||
}
|
||||
return pl, nil
|
||||
}
|
||||
|
||||
func validateArgs(args *Args) error {
|
||||
func validateArgs(args *schedulerv1alpha2.InterPodAffinityArgs) error {
|
||||
if args.HardPodAffinityWeight == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ func (pl *InterPodAffinity) processExistingPod(state *preScoreState, existingPod
|
||||
// For every hard pod affinity term of <existingPod>, if <pod> matches the term,
|
||||
// increment <p.counts> for every node in the cluster with the same <term.TopologyKey>
|
||||
// value as that of <existingPod>'s node by the constant <ipa.hardPodAffinityWeight>
|
||||
if *pl.HardPodAffinityWeight > 0 {
|
||||
if *pl.args.HardPodAffinityWeight > 0 {
|
||||
terms := existingPodAffinity.PodAffinity.RequiredDuringSchedulingIgnoredDuringExecution
|
||||
// TODO: Uncomment this block when implement RequiredDuringSchedulingRequiredDuringExecution.
|
||||
//if len(existingPodAffinity.PodAffinity.RequiredDuringSchedulingRequiredDuringExecution) != 0 {
|
||||
@@ -145,7 +145,7 @@ func (pl *InterPodAffinity) processExistingPod(state *preScoreState, existingPod
|
||||
//}
|
||||
for i := range terms {
|
||||
term := &terms[i]
|
||||
processedTerm, err := newWeightedAffinityTerm(existingPod, term, *pl.HardPodAffinityWeight)
|
||||
processedTerm, err := newWeightedAffinityTerm(existingPod, term, *pl.args.HardPodAffinityWeight)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import (
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
schedulerv1alpha2 "k8s.io/kube-scheduler/config/v1alpha2"
|
||||
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
||||
"k8s.io/kubernetes/pkg/scheduler/internal/cache"
|
||||
"k8s.io/utils/pointer"
|
||||
@@ -520,7 +521,7 @@ func TestPreferredAffinity(t *testing.T) {
|
||||
state := framework.NewCycleState()
|
||||
snapshot := cache.NewSnapshot(test.pods, test.nodes)
|
||||
p := &InterPodAffinity{
|
||||
Args: Args{
|
||||
args: schedulerv1alpha2.InterPodAffinityArgs{
|
||||
HardPodAffinityWeight: pointer.Int32Ptr(DefaultHardPodAffinityWeight),
|
||||
},
|
||||
sharedLister: snapshot,
|
||||
|
||||
Reference in New Issue
Block a user