From 842ae0bc22a5029dfbffe84cb4adeae7e30d447d Mon Sep 17 00:00:00 2001 From: ceshihao Date: Wed, 9 May 2018 13:36:05 +0000 Subject: [PATCH] Make taint behavior consistent, taint node with NotReady:NoSchedule --- .../node_lifecycle_controller.go | 41 +++++++++++++++---- test/integration/scheduler/taint_test.go | 7 +++- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/pkg/controller/nodelifecycle/node_lifecycle_controller.go b/pkg/controller/nodelifecycle/node_lifecycle_controller.go index 81774d19654..412ed5c5262 100644 --- a/pkg/controller/nodelifecycle/node_lifecycle_controller.go +++ b/pkg/controller/nodelifecycle/node_lifecycle_controller.go @@ -80,15 +80,38 @@ var ( Effect: v1.TaintEffectNoExecute, } - nodeConditionToTaintKeyMap = map[v1.NodeConditionType]string{ - v1.NodeMemoryPressure: algorithm.TaintNodeMemoryPressure, - v1.NodeOutOfDisk: algorithm.TaintNodeOutOfDisk, - v1.NodeDiskPressure: algorithm.TaintNodeDiskPressure, - v1.NodeNetworkUnavailable: algorithm.TaintNodeNetworkUnavailable, - v1.NodePIDPressure: algorithm.TaintNodePIDPressure, + nodeConditionToTaintKeyStatusMap = map[v1.NodeConditionType]struct { + TaintKey string + Status v1.ConditionStatus + }{ + v1.NodeReady: { + TaintKey: algorithm.TaintNodeNotReady, + Status: v1.ConditionFalse, + }, + v1.NodeMemoryPressure: { + TaintKey: algorithm.TaintNodeMemoryPressure, + Status: v1.ConditionTrue, + }, + v1.NodeOutOfDisk: { + TaintKey: algorithm.TaintNodeOutOfDisk, + Status: v1.ConditionTrue, + }, + v1.NodeDiskPressure: { + TaintKey: algorithm.TaintNodeDiskPressure, + Status: v1.ConditionTrue, + }, + v1.NodeNetworkUnavailable: { + TaintKey: algorithm.TaintNodeNetworkUnavailable, + Status: v1.ConditionTrue, + }, + v1.NodePIDPressure: { + TaintKey: algorithm.TaintNodePIDPressure, + Status: v1.ConditionTrue, + }, } taintKeyToNodeConditionMap = map[string]v1.NodeConditionType{ + algorithm.TaintNodeNotReady: v1.NodeReady, algorithm.TaintNodeNetworkUnavailable: v1.NodeNetworkUnavailable, algorithm.TaintNodeMemoryPressure: v1.NodeMemoryPressure, algorithm.TaintNodeOutOfDisk: v1.NodeOutOfDisk, @@ -432,10 +455,10 @@ func (nc *Controller) doNoScheduleTaintingPass(node *v1.Node) error { // Map node's condition to Taints. taints := []v1.Taint{} for _, condition := range node.Status.Conditions { - if _, found := nodeConditionToTaintKeyMap[condition.Type]; found { - if condition.Status == v1.ConditionTrue { + if taintKeyStatus, found := nodeConditionToTaintKeyStatusMap[condition.Type]; found { + if condition.Status == taintKeyStatus.Status { taints = append(taints, v1.Taint{ - Key: nodeConditionToTaintKeyMap[condition.Type], + Key: taintKeyStatus.TaintKey, Effect: v1.TaintEffectNoSchedule, }) } diff --git a/test/integration/scheduler/taint_test.go b/test/integration/scheduler/taint_test.go index f7de90706f0..dd4153c5449 100644 --- a/test/integration/scheduler/taint_test.go +++ b/test/integration/scheduler/taint_test.go @@ -229,7 +229,7 @@ func TestTaintNodeByCondition(t *testing.T) { } } - // Case 4: Schedule Pod with NetworkUnavailable toleration. + // Case 4: Schedule Pod with NetworkUnavailable and NotReady toleration. networkDaemonPod := &v1.Pod{ ObjectMeta: metav1.ObjectMeta{ Name: "network-daemon-pod", @@ -248,6 +248,11 @@ func TestTaintNodeByCondition(t *testing.T) { Operator: v1.TolerationOpExists, Effect: v1.TaintEffectNoSchedule, }, + { + Key: algorithm.TaintNodeNotReady, + Operator: v1.TolerationOpExists, + Effect: v1.TaintEffectNoSchedule, + }, }, }, }