Cache node taints in scheduler NodeInfo

pull/6/head
Wojciech Tyczynski 2016-10-21 11:33:09 +02:00
parent be2bb39964
commit 7387bc0572
2 changed files with 18 additions and 6 deletions

View File

@ -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) { func PodToleratesNodeTaints(pod *v1.Pod, meta interface{}, nodeInfo *schedulercache.NodeInfo) (bool, []algorithm.PredicateFailureReason, error) {
node := nodeInfo.Node() taints, err := nodeInfo.Taints()
if node == nil {
return false, nil, fmt.Errorf("node not found")
}
taints, err := v1.GetTaintsFromNodeAnnotations(node.Annotations)
if err != nil { if err != nil {
return false, nil, err return false, nil, err
} }

View File

@ -49,6 +49,10 @@ type NodeInfo struct {
// explicitly as int, to avoid conversions and improve performance. // explicitly as int, to avoid conversions and improve performance.
allowedPodNumber int allowedPodNumber int
// Cached tains of the node for faster lookup.
taints []v1.Taint
taintsErr error
// Cached conditions of node for faster lookup. // Cached conditions of node for faster lookup.
memoryPressureCondition v1.ConditionStatus memoryPressureCondition v1.ConditionStatus
diskPressureCondition v1.ConditionStatus diskPressureCondition v1.ConditionStatus
@ -126,6 +130,13 @@ func (n *NodeInfo) AllowedPodNumber() int {
return n.allowedPodNumber 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 { func (n *NodeInfo) MemoryPressureCondition() v1.ConditionStatus {
if n == nil { if n == nil {
return v1.ConditionUnknown return v1.ConditionUnknown
@ -171,6 +182,7 @@ func (n *NodeInfo) Clone() *NodeInfo {
nonzeroRequest: &(*n.nonzeroRequest), nonzeroRequest: &(*n.nonzeroRequest),
allocatableResource: &(*n.allocatableResource), allocatableResource: &(*n.allocatableResource),
allowedPodNumber: n.allowedPodNumber, allowedPodNumber: n.allowedPodNumber,
taintsErr: n.taintsErr,
memoryPressureCondition: n.memoryPressureCondition, memoryPressureCondition: n.memoryPressureCondition,
diskPressureCondition: n.diskPressureCondition, diskPressureCondition: n.diskPressureCondition,
generation: n.generation, generation: n.generation,
@ -181,6 +193,9 @@ func (n *NodeInfo) Clone() *NodeInfo {
if len(n.podsWithAffinity) > 0 { if len(n.podsWithAffinity) > 0 {
clone.podsWithAffinity = append([]*v1.Pod(nil), n.podsWithAffinity...) clone.podsWithAffinity = append([]*v1.Pod(nil), n.podsWithAffinity...)
} }
if len(n.taints) > 0 {
clone.taints = append([]v1.Taint(nil), n.taints...)
}
return clone 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 { for i := range node.Status.Conditions {
cond := &node.Status.Conditions[i] cond := &node.Status.Conditions[i]
switch cond.Type { switch cond.Type {
@ -350,6 +366,7 @@ func (n *NodeInfo) RemoveNode(node *v1.Node) error {
n.node = nil n.node = nil
n.allocatableResource = &Resource{} n.allocatableResource = &Resource{}
n.allowedPodNumber = 0 n.allowedPodNumber = 0
n.taints, n.taintsErr = nil, nil
n.memoryPressureCondition = v1.ConditionUnknown n.memoryPressureCondition = v1.ConditionUnknown
n.diskPressureCondition = v1.ConditionUnknown n.diskPressureCondition = v1.ConditionUnknown
n.generation++ n.generation++