Skip to content

Commit

Permalink
Merge pull request kubernetes#29912 from wojtek-t/enable_pod_affinity
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue

Enable PodAffinity by default in scheduler

Ref kubernetes#26144

@gmarek - FYI
  • Loading branch information
Kubernetes Submit Queue authored Aug 4, 2016
2 parents c8ea7af + b68905b commit 5273ac9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
4 changes: 2 additions & 2 deletions plugin/pkg/scheduler/algorithm/predicates/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) {
Expand Down
37 changes: 19 additions & 18 deletions plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
},
),
)
}

Expand Down Expand Up @@ -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,
},
),
)
}
14 changes: 7 additions & 7 deletions test/e2e/scheduler_predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5273ac9

Please sign in to comment.