mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Merge pull request #88030 from alculquicondor/ipa_build_args
Exposing InterPodAffinity build args
This commit is contained in:
commit
fc573f98fb
@ -22,6 +22,7 @@ go_library(
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/util/workqueue: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/apimachinery/pkg/apis/meta/v1: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"
|
||||
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
||||
schedulerlisters "k8s.io/kubernetes/pkg/scheduler/listers"
|
||||
"k8s.io/utils/pointer"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -52,8 +53,8 @@ var _ framework.ScorePlugin = &InterPodAffinity{}
|
||||
|
||||
// InterPodAffinity is a plugin that checks inter pod affinity
|
||||
type InterPodAffinity struct {
|
||||
sharedLister schedulerlisters.SharedLister
|
||||
hardPodAffinityWeight int32
|
||||
Args
|
||||
sharedLister schedulerlisters.SharedLister
|
||||
sync.Mutex
|
||||
}
|
||||
|
||||
@ -62,24 +63,27 @@ func (pl *InterPodAffinity) Name() string {
|
||||
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.
|
||||
func New(plArgs *runtime.Unknown, h framework.FrameworkHandle) (framework.Plugin, error) {
|
||||
if h.SnapshotSharedLister() == 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{
|
||||
sharedLister: h.SnapshotSharedLister(),
|
||||
hardPodAffinityWeight: DefaultHardPodAffinityWeight,
|
||||
sharedLister: h.SnapshotSharedLister(),
|
||||
}
|
||||
if args.HardPodAffinityWeight != nil {
|
||||
pl.hardPodAffinityWeight = *args.HardPodAffinityWeight
|
||||
if err := framework.DecodeInto(plArgs, &pl.Args); err != nil {
|
||||
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
|
||||
}
|
||||
|
@ -127,7 +127,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.HardPodAffinityWeight > 0 {
|
||||
terms := existingPodAffinity.PodAffinity.RequiredDuringSchedulingIgnoredDuringExecution
|
||||
// TODO: Uncomment this block when implement RequiredDuringSchedulingRequiredDuringExecution.
|
||||
//if len(existingPodAffinity.PodAffinity.RequiredDuringSchedulingRequiredDuringExecution) != 0 {
|
||||
@ -135,7 +135,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.HardPodAffinityWeight)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
framework "k8s.io/kubernetes/pkg/scheduler/framework/v1alpha1"
|
||||
"k8s.io/kubernetes/pkg/scheduler/internal/cache"
|
||||
"k8s.io/utils/pointer"
|
||||
)
|
||||
|
||||
func TestPreferredAffinity(t *testing.T) {
|
||||
@ -519,8 +520,10 @@ func TestPreferredAffinity(t *testing.T) {
|
||||
state := framework.NewCycleState()
|
||||
snapshot := cache.NewSnapshot(test.pods, test.nodes)
|
||||
p := &InterPodAffinity{
|
||||
sharedLister: snapshot,
|
||||
hardPodAffinityWeight: 1,
|
||||
Args: Args{
|
||||
HardPodAffinityWeight: pointer.Int32Ptr(DefaultHardPodAffinityWeight),
|
||||
},
|
||||
sharedLister: snapshot,
|
||||
}
|
||||
|
||||
status := p.PreScore(context.Background(), state, test.pod, test.nodes)
|
||||
|
Loading…
Reference in New Issue
Block a user