mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #29912 from wojtek-t/enable_pod_affinity
Automatic merge from submit-queue Enable PodAffinity by default in scheduler Ref #26144 @gmarek - FYI
This commit is contained in:
commit
5273ac9b94
@ -812,7 +812,7 @@ func (c *PodAffinityChecker) InterPodAffinityMatches(pod *api.Pod, meta interfac
|
||||
return false, fmt.Errorf("node not found")
|
||||
}
|
||||
if !c.satisfiesExistingPodsAntiAffinity(pod, meta, node) {
|
||||
return false, nil
|
||||
return false, ErrPodAffinityNotMatch
|
||||
}
|
||||
|
||||
// Now check if <pod> requirements will be satisfied on this node.
|
||||
@ -824,7 +824,7 @@ func (c *PodAffinityChecker) InterPodAffinityMatches(pod *api.Pod, meta interfac
|
||||
return true, nil
|
||||
}
|
||||
if !c.satisfiesPodsAffinityAntiAffinity(pod, node, affinity) {
|
||||
return false, nil
|
||||
return false, ErrPodAffinityNotMatch
|
||||
}
|
||||
|
||||
if glog.V(10) {
|
||||
|
@ -93,24 +93,6 @@ func init() {
|
||||
factory.RegisterFitPredicate("HostName", predicates.PodFitsHost)
|
||||
// Fit is determined by node selector query.
|
||||
factory.RegisterFitPredicate("MatchNodeSelector", predicates.PodSelectorMatches)
|
||||
// Fit is determined by inter-pod affinity.
|
||||
factory.RegisterFitPredicateFactory(
|
||||
"MatchInterPodAffinity",
|
||||
func(args factory.PluginFactoryArgs) algorithm.FitPredicate {
|
||||
return predicates.NewPodAffinityPredicate(args.NodeInfo, args.PodLister, args.FailureDomains)
|
||||
},
|
||||
)
|
||||
//pods should be placed in the same topological domain (e.g. same node, same rack, same zone, same power domain, etc.)
|
||||
//as some other pods, or, conversely, should not be placed in the same topological domain as some other pods.
|
||||
factory.RegisterPriorityConfigFactory(
|
||||
"InterPodAffinityPriority",
|
||||
factory.PriorityConfigFactory{
|
||||
Function: func(args factory.PluginFactoryArgs) algorithm.PriorityFunction {
|
||||
return priorities.NewInterPodAffinityPriority(args.NodeInfo, args.NodeLister, args.PodLister, args.HardPodAffinitySymmetricWeight, args.FailureDomains)
|
||||
},
|
||||
Weight: 1,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func defaultPredicates() sets.String {
|
||||
@ -154,6 +136,14 @@ func defaultPredicates() sets.String {
|
||||
|
||||
// Fit is determined by node disk pressure condition.
|
||||
factory.RegisterFitPredicate("CheckNodeDiskPressure", predicates.CheckNodeDiskPressurePredicate),
|
||||
|
||||
// Fit is determined by inter-pod affinity.
|
||||
factory.RegisterFitPredicateFactory(
|
||||
"MatchInterPodAffinity",
|
||||
func(args factory.PluginFactoryArgs) algorithm.FitPredicate {
|
||||
return predicates.NewPodAffinityPredicate(args.NodeInfo, args.PodLister, args.FailureDomains)
|
||||
},
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@ -186,5 +176,16 @@ func defaultPriorities() sets.String {
|
||||
),
|
||||
factory.RegisterPriorityFunction("NodeAffinityPriority", priorities.CalculateNodeAffinityPriority, 1),
|
||||
factory.RegisterPriorityFunction("TaintTolerationPriority", priorities.ComputeTaintTolerationPriority, 1),
|
||||
// pods should be placed in the same topological domain (e.g. same node, same rack, same zone, same power domain, etc.)
|
||||
// as some other pods, or, conversely, should not be placed in the same topological domain as some other pods.
|
||||
factory.RegisterPriorityConfigFactory(
|
||||
"InterPodAffinityPriority",
|
||||
factory.PriorityConfigFactory{
|
||||
Function: func(args factory.PluginFactoryArgs) algorithm.PriorityFunction {
|
||||
return priorities.NewInterPodAffinityPriority(args.NodeInfo, args.NodeLister, args.PodLister, args.HardPodAffinitySymmetricWeight, args.FailureDomains)
|
||||
},
|
||||
Weight: 1,
|
||||
},
|
||||
),
|
||||
)
|
||||
}
|
||||
|
@ -776,7 +776,7 @@ var _ = framework.KubeDescribe("SchedulerPredicates [Serial]", func() {
|
||||
})
|
||||
|
||||
// Test Nodes does not have any pod, hence it should be impossible to schedule a Pod with pod affinity.
|
||||
It("validates that Inter-pod-Affinity is respected if not matching [Feature:PodAffinity]", func() {
|
||||
It("validates that Inter-pod-Affinity is respected if not matching", func() {
|
||||
By("Trying to schedule Pod with nonempty Pod Affinity.")
|
||||
podName := "without-label-" + string(uuid.NewUUID())
|
||||
|
||||
@ -823,7 +823,7 @@ var _ = framework.KubeDescribe("SchedulerPredicates [Serial]", func() {
|
||||
})
|
||||
|
||||
// test the pod affinity successful matching scenario.
|
||||
It("validates that InterPodAffinity is respected if matching [Feature:PodAffinity]", func() {
|
||||
It("validates that InterPodAffinity is respected if matching", func() {
|
||||
// launch a pod to find a node which can launch a pod. We intentionally do
|
||||
// not just take the node list and choose the first of them. Depending on the
|
||||
// cluster and the scheduler it might be that a "normal" pod cannot be
|
||||
@ -909,7 +909,7 @@ var _ = framework.KubeDescribe("SchedulerPredicates [Serial]", func() {
|
||||
})
|
||||
|
||||
// test when the pod anti affinity rule is not satisfied, the pod would stay pending.
|
||||
It("validates that InterPodAntiAffinity is respected if matching 2 [Feature:PodAffinity]", func() {
|
||||
It("validates that InterPodAntiAffinity is respected if matching 2", func() {
|
||||
// launch a pod to find a node which can launch a pod. We intentionally do
|
||||
// not just take the node list and choose the first of them. Depending on the
|
||||
// cluster and the scheduler it might be that a "normal" pod cannot be
|
||||
@ -989,11 +989,11 @@ var _ = framework.KubeDescribe("SchedulerPredicates [Serial]", func() {
|
||||
framework.Logf("Sleeping 10 seconds and crossing our fingers that scheduler will run in that time.")
|
||||
time.Sleep(10 * time.Second)
|
||||
|
||||
verifyResult(c, labelPodName, 1, 1, ns)
|
||||
verifyResult(c, labelPodName, 1, 0, ns)
|
||||
})
|
||||
|
||||
// test the pod affinity successful matching scenario with multiple Label Operators.
|
||||
It("validates that InterPodAffinity is respected if matching with multiple Affinities [Feature:PodAffinity]", func() {
|
||||
It("validates that InterPodAffinity is respected if matching with multiple Affinities", func() {
|
||||
// launch a pod to find a node which can launch a pod. We intentionally do
|
||||
// not just take the node list and choose the first of them. Depending on the
|
||||
// cluster and the scheduler it might be that a "normal" pod cannot be
|
||||
@ -1087,7 +1087,7 @@ var _ = framework.KubeDescribe("SchedulerPredicates [Serial]", func() {
|
||||
})
|
||||
|
||||
// test the pod affinity and anti affinity successful matching scenario.
|
||||
It("validates that InterPod Affinity and AntiAffinity is respected if matching [Feature:PodAffinity]", func() {
|
||||
It("validates that InterPod Affinity and AntiAffinity is respected if matching", func() {
|
||||
// launch a pod to find a node which can launch a pod. We intentionally do
|
||||
// not just take the node list and choose the first of them. Depending on the
|
||||
// cluster and the scheduler it might be that a "normal" pod cannot be
|
||||
@ -1184,7 +1184,7 @@ var _ = framework.KubeDescribe("SchedulerPredicates [Serial]", func() {
|
||||
})
|
||||
|
||||
// Verify that an escaped JSON string of pod affinity and pod anti affinity in a YAML PodSpec works.
|
||||
It("validates that embedding the JSON PodAffinity and PodAntiAffinity setting as a string in the annotation value work [Feature:PodAffinity]", func() {
|
||||
It("validates that embedding the JSON PodAffinity and PodAntiAffinity setting as a string in the annotation value work", func() {
|
||||
// launch a pod to find a node which can launch a pod. We intentionally do
|
||||
// not just take the node list and choose the first of them. Depending on the
|
||||
// cluster and the scheduler it might be that a "normal" pod cannot be
|
||||
|
Loading…
Reference in New Issue
Block a user