Add types for Scheduler plugin args to kube-scheduler.config.k8s.io

This commit is contained in:
Rafał Wicha
2020-02-26 18:38:06 +00:00
committed by Rafal Wicha
parent 3c3fc800df
commit c4d20ca8a8
29 changed files with 971 additions and 110 deletions

View File

@@ -34,6 +34,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/apiserver/pkg/util/feature:go_default_library",
"//staging/src/k8s.io/kube-scheduler/config/v1alpha2:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
],
)

View File

@@ -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",
],
)

View File

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

View File

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

View File

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

View File

@@ -23,6 +23,7 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/klog"
schedulerv1alpha2 "k8s.io/kube-scheduler/config/v1alpha2"
"k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/scheduler/apis/config"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultpodtopologyspread"
@@ -164,15 +165,15 @@ type ConfigProducerArgs struct {
// Weight used for priority functions.
Weight int32
// NodeLabelArgs is the args for the NodeLabel plugin.
NodeLabelArgs *nodelabel.Args
NodeLabelArgs *schedulerv1alpha2.NodeLabelArgs
// RequestedToCapacityRatioArgs is the args for the RequestedToCapacityRatio plugin.
RequestedToCapacityRatioArgs *noderesources.RequestedToCapacityRatioArgs
RequestedToCapacityRatioArgs *schedulerv1alpha2.RequestedToCapacityRatioArgs
// ServiceAffinityArgs is the args for the ServiceAffinity plugin.
ServiceAffinityArgs *serviceaffinity.Args
ServiceAffinityArgs *schedulerv1alpha2.ServiceAffinityArgs
// NodeResourcesFitArgs is the args for the NodeResources fit filter.
NodeResourcesFitArgs *noderesources.FitArgs
NodeResourcesFitArgs *schedulerv1alpha2.NodeResourcesFitArgs
// InterPodAffinityArgs is the args for InterPodAffinity plugin
InterPodAffinityArgs *interpodaffinity.Args
InterPodAffinityArgs *schedulerv1alpha2.InterPodAffinityArgs
}
// ConfigProducer returns the set of plugins and their configuration for a
@@ -525,7 +526,7 @@ func (lr *LegacyRegistry) ProcessPredicatePolicy(policy config.PredicatePolicy,
if policy.Argument.ServiceAffinity != nil {
// map LabelsPresence policy to ConfigProducerArgs that's used to configure the ServiceAffinity plugin.
if pluginArgs.ServiceAffinityArgs == nil {
pluginArgs.ServiceAffinityArgs = &serviceaffinity.Args{}
pluginArgs.ServiceAffinityArgs = &schedulerv1alpha2.ServiceAffinityArgs{}
}
pluginArgs.ServiceAffinityArgs.AffinityLabels = append(pluginArgs.ServiceAffinityArgs.AffinityLabels, policy.Argument.ServiceAffinity.Labels...)
@@ -538,7 +539,7 @@ func (lr *LegacyRegistry) ProcessPredicatePolicy(policy config.PredicatePolicy,
if policy.Argument.LabelsPresence != nil {
// Map LabelPresence policy to ConfigProducerArgs that's used to configure the NodeLabel plugin.
if pluginArgs.NodeLabelArgs == nil {
pluginArgs.NodeLabelArgs = &nodelabel.Args{}
pluginArgs.NodeLabelArgs = &schedulerv1alpha2.NodeLabelArgs{}
}
if policy.Argument.LabelsPresence.Presence {
pluginArgs.NodeLabelArgs.PresentLabels = append(pluginArgs.NodeLabelArgs.PresentLabels, policy.Argument.LabelsPresence.Labels...)
@@ -586,7 +587,7 @@ func (lr *LegacyRegistry) ProcessPriorityPolicy(policy config.PriorityPolicy, co
// This name is then used to find the registered plugin and run the plugin instead of the priority.
priorityName = serviceaffinity.Name
if configProducerArgs.ServiceAffinityArgs == nil {
configProducerArgs.ServiceAffinityArgs = &serviceaffinity.Args{}
configProducerArgs.ServiceAffinityArgs = &schedulerv1alpha2.ServiceAffinityArgs{}
}
configProducerArgs.ServiceAffinityArgs.AntiAffinityLabelsPreference = append(
configProducerArgs.ServiceAffinityArgs.AntiAffinityLabelsPreference,
@@ -600,7 +601,7 @@ func (lr *LegacyRegistry) ProcessPriorityPolicy(policy config.PriorityPolicy, co
// This name is then used to find the registered plugin and run the plugin instead of the priority.
priorityName = nodelabel.Name
if configProducerArgs.NodeLabelArgs == nil {
configProducerArgs.NodeLabelArgs = &nodelabel.Args{}
configProducerArgs.NodeLabelArgs = &schedulerv1alpha2.NodeLabelArgs{}
}
if policy.Argument.LabelPreference.Presence {
configProducerArgs.NodeLabelArgs.PresentLabelsPreference = append(
@@ -616,9 +617,27 @@ func (lr *LegacyRegistry) ProcessPriorityPolicy(policy config.PriorityPolicy, co
}
if policy.Argument.RequestedToCapacityRatioArguments != nil {
configProducerArgs.RequestedToCapacityRatioArgs = &noderesources.RequestedToCapacityRatioArgs{
RequestedToCapacityRatioArguments: *policy.Argument.RequestedToCapacityRatioArguments,
policyArgs := policy.Argument.RequestedToCapacityRatioArguments
args := &schedulerv1alpha2.RequestedToCapacityRatioArgs{}
args.Shape = make([]schedulerv1alpha2.UtilizationShapePoint, len(policyArgs.Shape))
for i, s := range policyArgs.Shape {
args.Shape[i] = schedulerv1alpha2.UtilizationShapePoint{
Utilization: s.Utilization,
Score: s.Score,
}
}
args.Resources = make([]schedulerv1alpha2.ResourceSpec, len(policyArgs.Resources))
for i, r := range policyArgs.Resources {
args.Resources[i] = schedulerv1alpha2.ResourceSpec{
Name: r.Name,
Weight: r.Weight,
}
}
configProducerArgs.RequestedToCapacityRatioArgs = args
// We do not allow specifying the name for custom plugins, see #83472
priorityName = noderesources.RequestedToCapacityRatioName
}

View File

@@ -10,6 +10,7 @@ go_library(
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/kube-scheduler/config/v1alpha2:go_default_library",
],
)

View File

@@ -23,6 +23,7 @@ import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
schedulerv1alpha2 "k8s.io/kube-scheduler/config/v1alpha2"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
)
@@ -34,18 +35,6 @@ const (
ErrReasonPresenceViolated = "node(s) didn't have the requested labels"
)
// Args holds the args that are used to configure the plugin.
type Args struct {
// PresentLabels should be present for the node to be considered a fit for hosting the pod
PresentLabels []string `json:"presentLabels,omitempty"`
// AbsentLabels should be absent for the node to be considered a fit for hosting the pod
AbsentLabels []string `json:"absentLabels,omitempty"`
// Nodes that have labels in the list will get a higher score.
PresentLabelsPreference []string `json:"presentLabelsPreference,omitempty"`
// Nodes that don't have labels in the list will get a higher score.
AbsentLabelsPreference []string `json:"absentLabelsPreference,omitempty"`
}
// validateArgs validates that presentLabels and absentLabels do not conflict.
func validateNoConflict(presentLabels []string, absentLabels []string) error {
m := make(map[string]struct{}, len(presentLabels))
@@ -62,7 +51,7 @@ func validateNoConflict(presentLabels []string, absentLabels []string) error {
// New initializes a new plugin and returns it.
func New(plArgs *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) {
args := Args{}
args := schedulerv1alpha2.NodeLabelArgs{}
if err := framework.DecodeInto(plArgs, &args); err != nil {
return nil, err
}
@@ -74,14 +63,14 @@ func New(plArgs *runtime.Unknown, handle framework.FrameworkHandle) (framework.P
}
return &NodeLabel{
handle: handle,
Args: args,
args: args,
}, nil
}
// NodeLabel checks whether a pod can fit based on the node labels which match a filter that it requests.
type NodeLabel struct {
handle framework.FrameworkHandle
Args
args schedulerv1alpha2.NodeLabelArgs
}
var _ framework.FilterPlugin = &NodeLabel{}
@@ -116,7 +105,7 @@ func (pl *NodeLabel) Filter(ctx context.Context, _ *framework.CycleState, pod *v
}
return true
}
if check(pl.PresentLabels, true) && check(pl.AbsentLabels, false) {
if check(pl.args.PresentLabels, true) && check(pl.args.AbsentLabels, false) {
return nil
}
@@ -132,18 +121,18 @@ func (pl *NodeLabel) Score(ctx context.Context, state *framework.CycleState, pod
node := nodeInfo.Node()
score := int64(0)
for _, label := range pl.PresentLabelsPreference {
for _, label := range pl.args.PresentLabelsPreference {
if labels.Set(node.Labels).Has(label) {
score += framework.MaxNodeScore
}
}
for _, label := range pl.AbsentLabelsPreference {
for _, label := range pl.args.AbsentLabelsPreference {
if !labels.Set(node.Labels).Has(label) {
score += framework.MaxNodeScore
}
}
// Take average score for each label to ensure the score doesn't exceed MaxNodeScore.
score /= int64(len(pl.PresentLabelsPreference) + len(pl.AbsentLabelsPreference))
score /= int64(len(pl.args.PresentLabelsPreference) + len(pl.args.AbsentLabelsPreference))
return score, nil
}

View File

@@ -26,6 +26,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/apiserver/pkg/util/feature:go_default_library",
"//staging/src/k8s.io/kube-scheduler/config/v1alpha2:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
],
)
@@ -66,6 +67,7 @@ go_test(
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
"//staging/src/k8s.io/component-base/featuregate/testing:go_default_library",
"//staging/src/k8s.io/kube-scheduler/config/v1alpha2:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library",
],
)

View File

@@ -20,10 +20,11 @@ import (
"context"
"fmt"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/sets"
utilfeature "k8s.io/apiserver/pkg/util/feature"
schedulerv1alpha2 "k8s.io/kube-scheduler/config/v1alpha2"
v1helper "k8s.io/kubernetes/pkg/apis/core/v1/helper"
"k8s.io/kubernetes/pkg/features"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
@@ -46,13 +47,6 @@ type Fit struct {
ignoredResources sets.String
}
// FitArgs holds the args that are used to configure the plugin.
type FitArgs struct {
// IgnoredResources is the list of resources that NodeResources fit filter
// should ignore.
IgnoredResources []string `json:"ignoredResources,omitempty"`
}
// preFilterState computed at PreFilter and used at Filter.
type preFilterState struct {
framework.Resource
@@ -68,6 +62,18 @@ func (f *Fit) Name() string {
return FitName
}
// NewFit initializes a new plugin and returns it.
func NewFit(plArgs *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
args := &schedulerv1alpha2.NodeResourcesFitArgs{}
if err := framework.DecodeInto(plArgs, args); err != nil {
return nil, err
}
fit := &Fit{}
fit.ignoredResources = sets.NewString(args.IgnoredResources...)
return fit, nil
}
// computePodResourceRequest returns a framework.Resource that covers the largest
// width in each resource dimension. Because init-containers run sequentially, we collect
// the max in each dimension iteratively. In contrast, we sum the resource vectors for
@@ -252,15 +258,3 @@ func fitsRequest(podRequest *preFilterState, nodeInfo *framework.NodeInfo, ignor
return insufficientResources
}
// NewFit initializes a new plugin and returns it.
func NewFit(plArgs *runtime.Unknown, _ framework.FrameworkHandle) (framework.Plugin, error) {
args := &FitArgs{}
if err := framework.DecodeInto(plArgs, args); err != nil {
return nil, err
}
fit := &Fit{}
fit.ignoredResources = sets.NewString(args.IgnoredResources...)
return fit, nil
}

View File

@@ -24,6 +24,7 @@ import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/klog"
schedulerv1alpha2 "k8s.io/kube-scheduler/config/v1alpha2"
"k8s.io/kubernetes/pkg/scheduler/apis/config"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
)
@@ -37,11 +38,6 @@ const (
maxScore = framework.MaxNodeScore
)
// RequestedToCapacityRatioArgs holds the args that are used to configure the plugin.
type RequestedToCapacityRatioArgs struct {
config.RequestedToCapacityRatioArguments
}
type functionShape []functionShapePoint
type functionShapePoint struct {
@@ -53,7 +49,7 @@ type functionShapePoint struct {
// NewRequestedToCapacityRatio initializes a new plugin and returns it.
func NewRequestedToCapacityRatio(plArgs *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) {
args := &config.RequestedToCapacityRatioArguments{}
args := &schedulerv1alpha2.RequestedToCapacityRatioArgs{}
if err := framework.DecodeInto(plArgs, args); err != nil {
return nil, err
}

View File

@@ -25,6 +25,7 @@ import (
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"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"
)
@@ -607,3 +608,49 @@ func TestResourceBinPackingMultipleExtended(t *testing.T) {
})
}
}
// TODO compatibility test once the plugin args move to v1beta1.
// UtilizationShapePoint and ResourceSpec fields of the plugin args struct are not annotated
// with JSON tags in v1alpha2 to maintain backward compatibility with the args shipped with v1.18.
// See https://github.com/kubernetes/kubernetes/pull/88585#discussion_r405021905
func TestPluginArgsJSONEncodingIsCaseInsensitive(t *testing.T) {
rawArgs := &runtime.Unknown{Raw: []byte(`
{
"shape": [{"Utilization": 1, "Score": 1}, {"utilization": 2, "score": 2}],
"resources": [{"Name":"a","Weight":1},{"name":"b","weight":2}]
}
`)}
args := &schedulerv1alpha2.RequestedToCapacityRatioArgs{}
if err := framework.DecodeInto(rawArgs, args); err != nil {
t.Fatalf("expected no error, got: %v", err)
}
expectedArgs := &schedulerv1alpha2.RequestedToCapacityRatioArgs{
Shape: []schedulerv1alpha2.UtilizationShapePoint{
{
Utilization: 1,
Score: 1,
},
{
Utilization: 2,
Score: 2,
},
},
Resources: []schedulerv1alpha2.ResourceSpec{
{
Name: "a",
Weight: 1,
},
{
Name: "b",
Weight: 2,
},
},
}
if !reflect.DeepEqual(expectedArgs, args) {
t.Errorf("expected: \n\t%#v,\ngot: \n\t%#v", expectedArgs, args)
}
}

View File

@@ -12,6 +12,7 @@ go_library(
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/client-go/listers/core/v1:go_default_library",
"//staging/src/k8s.io/kube-scheduler/config/v1alpha2:go_default_library",
],
)
@@ -25,6 +26,7 @@ go_test(
"//pkg/scheduler/internal/cache:go_default_library",
"//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/kube-scheduler/config/v1alpha2:go_default_library",
],
)

View File

@@ -24,6 +24,7 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
corelisters "k8s.io/client-go/listers/core/v1"
schedulerv1alpha2 "k8s.io/kube-scheduler/config/v1alpha2"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/helper"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
)
@@ -40,16 +41,6 @@ const (
ErrReason = "node(s) didn't match service affinity"
)
// Args holds the args that are used to configure the plugin.
type Args struct {
// Labels are homogeneous for pods that are scheduled to a node.
// (i.e. it returns true IFF this pod can be added to this node such that all other pods in
// the same service are running on nodes with the exact same values for Labels).
AffinityLabels []string `json:"affinityLabels,omitempty"`
// AntiAffinityLabelsPreference are the labels to consider for service anti affinity scoring.
AntiAffinityLabelsPreference []string `json:"antiAffinityLabelsPreference,omitempty"`
}
// preFilterState computed at PreFilter and used at Filter.
type preFilterState struct {
matchingPodList []*v1.Pod
@@ -73,7 +64,7 @@ func (s *preFilterState) Clone() framework.StateData {
// New initializes a new plugin and returns it.
func New(plArgs *runtime.Unknown, handle framework.FrameworkHandle) (framework.Plugin, error) {
args := Args{}
args := schedulerv1alpha2.ServiceAffinityArgs{}
if err := framework.DecodeInto(plArgs, &args); err != nil {
return nil, err
}
@@ -89,7 +80,7 @@ func New(plArgs *runtime.Unknown, handle framework.FrameworkHandle) (framework.P
// ServiceAffinity is a plugin that checks service affinity.
type ServiceAffinity struct {
args Args
args schedulerv1alpha2.ServiceAffinityArgs
sharedLister framework.SharedLister
serviceLister corelisters.ServiceLister
}

View File

@@ -24,6 +24,7 @@ import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
schedulerv1alpha2 "k8s.io/kube-scheduler/config/v1alpha2"
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
fakeframework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1/fake"
"k8s.io/kubernetes/pkg/scheduler/internal/cache"
@@ -164,7 +165,7 @@ func TestServiceAffinity(t *testing.T) {
p := &ServiceAffinity{
sharedLister: snapshot,
serviceLister: fakeframework.ServiceLister(test.services),
args: Args{
args: schedulerv1alpha2.ServiceAffinityArgs{
AffinityLabels: test.labels,
},
}
@@ -388,7 +389,7 @@ func TestServiceAffinityScore(t *testing.T) {
p := &ServiceAffinity{
sharedLister: snapshot,
serviceLister: serviceLister,
args: Args{
args: schedulerv1alpha2.ServiceAffinityArgs{
AntiAffinityLabelsPreference: test.labels,
},
}
@@ -605,7 +606,7 @@ func TestPreFilterDisabled(t *testing.T) {
node := v1.Node{}
nodeInfo.SetNode(&node)
p := &ServiceAffinity{
args: Args{
args: schedulerv1alpha2.ServiceAffinityArgs{
AffinityLabels: []string{"region"},
},
}