From 7387bc05723452ff8dd342c7b20aa409ea5fc5c0 Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Fri, 21 Oct 2016 11:33:09 +0200 Subject: [PATCH] Cache node taints in scheduler NodeInfo --- .../algorithm/predicates/predicates.go | 7 +------ .../pkg/scheduler/schedulercache/node_info.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/plugin/pkg/scheduler/algorithm/predicates/predicates.go b/plugin/pkg/scheduler/algorithm/predicates/predicates.go index a50a51ae9b..ee102d8d96 100644 --- a/plugin/pkg/scheduler/algorithm/predicates/predicates.go +++ b/plugin/pkg/scheduler/algorithm/predicates/predicates.go @@ -1119,12 +1119,7 @@ func (c *PodAffinityChecker) satisfiesPodsAffinityAntiAffinity(pod *v1.Pod, node } func PodToleratesNodeTaints(pod *v1.Pod, meta interface{}, nodeInfo *schedulercache.NodeInfo) (bool, []algorithm.PredicateFailureReason, error) { - node := nodeInfo.Node() - if node == nil { - return false, nil, fmt.Errorf("node not found") - } - - taints, err := v1.GetTaintsFromNodeAnnotations(node.Annotations) + taints, err := nodeInfo.Taints() if err != nil { return false, nil, err } diff --git a/plugin/pkg/scheduler/schedulercache/node_info.go b/plugin/pkg/scheduler/schedulercache/node_info.go index 4fceb567f2..a3e816ae71 100644 --- a/plugin/pkg/scheduler/schedulercache/node_info.go +++ b/plugin/pkg/scheduler/schedulercache/node_info.go @@ -49,6 +49,10 @@ type NodeInfo struct { // explicitly as int, to avoid conversions and improve performance. allowedPodNumber int + // Cached tains of the node for faster lookup. + taints []v1.Taint + taintsErr error + // Cached conditions of node for faster lookup. memoryPressureCondition v1.ConditionStatus diskPressureCondition v1.ConditionStatus @@ -126,6 +130,13 @@ func (n *NodeInfo) AllowedPodNumber() int { return n.allowedPodNumber } +func (n *NodeInfo) Taints() ([]v1.Taint, error) { + if n == nil { + return nil, nil + } + return n.taints, n.taintsErr +} + func (n *NodeInfo) MemoryPressureCondition() v1.ConditionStatus { if n == nil { return v1.ConditionUnknown @@ -171,6 +182,7 @@ func (n *NodeInfo) Clone() *NodeInfo { nonzeroRequest: &(*n.nonzeroRequest), allocatableResource: &(*n.allocatableResource), allowedPodNumber: n.allowedPodNumber, + taintsErr: n.taintsErr, memoryPressureCondition: n.memoryPressureCondition, diskPressureCondition: n.diskPressureCondition, generation: n.generation, @@ -181,6 +193,9 @@ func (n *NodeInfo) Clone() *NodeInfo { if len(n.podsWithAffinity) > 0 { clone.podsWithAffinity = append([]*v1.Pod(nil), n.podsWithAffinity...) } + if len(n.taints) > 0 { + clone.taints = append([]v1.Taint(nil), n.taints...) + } return clone } @@ -326,6 +341,7 @@ func (n *NodeInfo) SetNode(node *v1.Node) error { } } } + n.taints, n.taintsErr = v1.GetTaintsFromNodeAnnotations(node.Annotations) for i := range node.Status.Conditions { cond := &node.Status.Conditions[i] switch cond.Type { @@ -350,6 +366,7 @@ func (n *NodeInfo) RemoveNode(node *v1.Node) error { n.node = nil n.allocatableResource = &Resource{} n.allowedPodNumber = 0 + n.taints, n.taintsErr = nil, nil n.memoryPressureCondition = v1.ConditionUnknown n.diskPressureCondition = v1.ConditionUnknown n.generation++