mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Add BuildArgs to interpodaffinity plugin
Signed-off-by: Aldo Culquicondor <acondor@google.com>
This commit is contained in:
parent
2e5d5ebf59
commit
c8377ef7db
@ -22,6 +22,7 @@ go_library(
|
|||||||
"//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/util/workqueue:go_default_library",
|
"//staging/src/k8s.io/client-go/util/workqueue:go_default_library",
|
||||||
"//vendor/k8s.io/klog:go_default_library",
|
"//vendor/k8s.io/klog:go_default_library",
|
||||||
|
"//vendor/k8s.io/utils/pointer:go_default_library",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -39,6 +40,7 @@ go_test(
|
|||||||
"//staging/src/k8s.io/api/core/v1: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/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||||
|
"//vendor/k8s.io/utils/pointer:go_default_library",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||||
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
||||||
schedulerlisters "k8s.io/kubernetes/pkg/scheduler/listers"
|
schedulerlisters "k8s.io/kubernetes/pkg/scheduler/listers"
|
||||||
|
"k8s.io/utils/pointer"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -52,8 +53,8 @@ var _ framework.ScorePlugin = &InterPodAffinity{}
|
|||||||
|
|
||||||
// InterPodAffinity is a plugin that checks inter pod affinity
|
// InterPodAffinity is a plugin that checks inter pod affinity
|
||||||
type InterPodAffinity struct {
|
type InterPodAffinity struct {
|
||||||
sharedLister schedulerlisters.SharedLister
|
Args
|
||||||
hardPodAffinityWeight int32
|
sharedLister schedulerlisters.SharedLister
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,24 +63,27 @@ func (pl *InterPodAffinity) Name() string {
|
|||||||
return Name
|
return Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BuildArgs returns the args that were used to build the plugin.
|
||||||
|
func (pl *InterPodAffinity) BuildArgs() interface{} {
|
||||||
|
return pl.Args
|
||||||
|
}
|
||||||
|
|
||||||
// New initializes a new plugin and returns it.
|
// New initializes a new plugin and returns it.
|
||||||
func New(plArgs *runtime.Unknown, h framework.FrameworkHandle) (framework.Plugin, error) {
|
func New(plArgs *runtime.Unknown, h framework.FrameworkHandle) (framework.Plugin, error) {
|
||||||
if h.SnapshotSharedLister() == nil {
|
if h.SnapshotSharedLister() == nil {
|
||||||
return nil, fmt.Errorf("SnapshotSharedlister is nil")
|
return nil, fmt.Errorf("SnapshotSharedlister is nil")
|
||||||
}
|
}
|
||||||
args := &Args{}
|
|
||||||
if err := framework.DecodeInto(plArgs, args); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := validateArgs(args); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
pl := &InterPodAffinity{
|
pl := &InterPodAffinity{
|
||||||
sharedLister: h.SnapshotSharedLister(),
|
sharedLister: h.SnapshotSharedLister(),
|
||||||
hardPodAffinityWeight: DefaultHardPodAffinityWeight,
|
|
||||||
}
|
}
|
||||||
if args.HardPodAffinityWeight != nil {
|
if err := framework.DecodeInto(plArgs, &pl.Args); err != nil {
|
||||||
pl.hardPodAffinityWeight = *args.HardPodAffinityWeight
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := validateArgs(&pl.Args); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if pl.HardPodAffinityWeight == nil {
|
||||||
|
pl.HardPodAffinityWeight = pointer.Int32Ptr(DefaultHardPodAffinityWeight)
|
||||||
}
|
}
|
||||||
return pl, nil
|
return pl, nil
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ func (pl *InterPodAffinity) processExistingPod(state *preScoreState, existingPod
|
|||||||
// For every hard pod affinity term of <existingPod>, if <pod> matches the term,
|
// 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>
|
// 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>
|
// value as that of <existingPod>'s node by the constant <ipa.hardPodAffinityWeight>
|
||||||
if pl.hardPodAffinityWeight > 0 {
|
if *pl.HardPodAffinityWeight > 0 {
|
||||||
terms := existingPodAffinity.PodAffinity.RequiredDuringSchedulingIgnoredDuringExecution
|
terms := existingPodAffinity.PodAffinity.RequiredDuringSchedulingIgnoredDuringExecution
|
||||||
// TODO: Uncomment this block when implement RequiredDuringSchedulingRequiredDuringExecution.
|
// TODO: Uncomment this block when implement RequiredDuringSchedulingRequiredDuringExecution.
|
||||||
//if len(existingPodAffinity.PodAffinity.RequiredDuringSchedulingRequiredDuringExecution) != 0 {
|
//if len(existingPodAffinity.PodAffinity.RequiredDuringSchedulingRequiredDuringExecution) != 0 {
|
||||||
@ -135,7 +135,7 @@ func (pl *InterPodAffinity) processExistingPod(state *preScoreState, existingPod
|
|||||||
//}
|
//}
|
||||||
for i := range terms {
|
for i := range terms {
|
||||||
term := &terms[i]
|
term := &terms[i]
|
||||||
processedTerm, err := newWeightedAffinityTerm(existingPod, term, pl.hardPodAffinityWeight)
|
processedTerm, err := newWeightedAffinityTerm(existingPod, term, *pl.HardPodAffinityWeight)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/internal/cache"
|
"k8s.io/kubernetes/pkg/scheduler/internal/cache"
|
||||||
|
"k8s.io/utils/pointer"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPreferredAffinity(t *testing.T) {
|
func TestPreferredAffinity(t *testing.T) {
|
||||||
@ -519,8 +520,10 @@ func TestPreferredAffinity(t *testing.T) {
|
|||||||
state := framework.NewCycleState()
|
state := framework.NewCycleState()
|
||||||
snapshot := cache.NewSnapshot(test.pods, test.nodes)
|
snapshot := cache.NewSnapshot(test.pods, test.nodes)
|
||||||
p := &InterPodAffinity{
|
p := &InterPodAffinity{
|
||||||
sharedLister: snapshot,
|
Args: Args{
|
||||||
hardPodAffinityWeight: 1,
|
HardPodAffinityWeight: pointer.Int32Ptr(DefaultHardPodAffinityWeight),
|
||||||
|
},
|
||||||
|
sharedLister: snapshot,
|
||||||
}
|
}
|
||||||
|
|
||||||
status := p.PreScore(context.Background(), state, test.pod, test.nodes)
|
status := p.PreScore(context.Background(), state, test.pod, test.nodes)
|
||||||
|
Loading…
Reference in New Issue
Block a user