From 842ae0bc22a5029dfbffe84cb4adeae7e30d447d Mon Sep 17 00:00:00 2001 From: ceshihao Date: Wed, 9 May 2018 13:36:05 +0000 Subject: [PATCH 1/2] 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, + }, }, }, } From 4eb72d7bcd59fd853a3acc100c59534e3e3d709b Mon Sep 17 00:00:00 2001 From: ceshihao Date: Mon, 14 May 2018 06:55:42 +0000 Subject: [PATCH 2/2] simplify code and add unit test for NotReady taint --- .../node_lifecycle_controller.go | 38 ++++++++++--------- .../node_lifecycle_controller_test.go | 28 ++++++++++++++ 2 files changed, 48 insertions(+), 18 deletions(-) diff --git a/pkg/controller/nodelifecycle/node_lifecycle_controller.go b/pkg/controller/nodelifecycle/node_lifecycle_controller.go index 412ed5c5262..d5615f65cd5 100644 --- a/pkg/controller/nodelifecycle/node_lifecycle_controller.go +++ b/pkg/controller/nodelifecycle/node_lifecycle_controller.go @@ -81,32 +81,34 @@ var ( } nodeConditionToTaintKeyStatusMap = map[v1.NodeConditionType]struct { - TaintKey string - Status v1.ConditionStatus + taintKey string + // noScheduleStatus is the condition under which the node should be tainted as not schedulable for this + // NodeConditionType + noScheduleStatus v1.ConditionStatus }{ v1.NodeReady: { - TaintKey: algorithm.TaintNodeNotReady, - Status: v1.ConditionFalse, + taintKey: algorithm.TaintNodeNotReady, + noScheduleStatus: v1.ConditionFalse, }, v1.NodeMemoryPressure: { - TaintKey: algorithm.TaintNodeMemoryPressure, - Status: v1.ConditionTrue, + taintKey: algorithm.TaintNodeMemoryPressure, + noScheduleStatus: v1.ConditionTrue, }, v1.NodeOutOfDisk: { - TaintKey: algorithm.TaintNodeOutOfDisk, - Status: v1.ConditionTrue, + taintKey: algorithm.TaintNodeOutOfDisk, + noScheduleStatus: v1.ConditionTrue, }, v1.NodeDiskPressure: { - TaintKey: algorithm.TaintNodeDiskPressure, - Status: v1.ConditionTrue, + taintKey: algorithm.TaintNodeDiskPressure, + noScheduleStatus: v1.ConditionTrue, }, v1.NodeNetworkUnavailable: { - TaintKey: algorithm.TaintNodeNetworkUnavailable, - Status: v1.ConditionTrue, + taintKey: algorithm.TaintNodeNetworkUnavailable, + noScheduleStatus: v1.ConditionTrue, }, v1.NodePIDPressure: { - TaintKey: algorithm.TaintNodePIDPressure, - Status: v1.ConditionTrue, + taintKey: algorithm.TaintNodePIDPressure, + noScheduleStatus: v1.ConditionTrue, }, } @@ -453,12 +455,12 @@ func (nc *Controller) doFixDeprecatedTaintKeyPass(node *v1.Node) error { func (nc *Controller) doNoScheduleTaintingPass(node *v1.Node) error { // Map node's condition to Taints. - taints := []v1.Taint{} + var taints []v1.Taint for _, condition := range node.Status.Conditions { - if taintKeyStatus, found := nodeConditionToTaintKeyStatusMap[condition.Type]; found { - if condition.Status == taintKeyStatus.Status { + if taint, found := nodeConditionToTaintKeyStatusMap[condition.Type]; found { + if condition.Status == taint.noScheduleStatus { taints = append(taints, v1.Taint{ - Key: taintKeyStatus.TaintKey, + Key: taint.taintKey, Effect: v1.TaintEffectNoSchedule, }) } diff --git a/pkg/controller/nodelifecycle/node_lifecycle_controller_test.go b/pkg/controller/nodelifecycle/node_lifecycle_controller_test.go index 35f37e2ba37..099ddedd013 100644 --- a/pkg/controller/nodelifecycle/node_lifecycle_controller_test.go +++ b/pkg/controller/nodelifecycle/node_lifecycle_controller_test.go @@ -2163,6 +2163,10 @@ func TestTaintsNodeByCondition(t *testing.T) { Key: algorithm.TaintNodeNetworkUnavailable, Effect: v1.TaintEffectNoSchedule, } + notReadyTaint := &v1.Taint{ + Key: algorithm.TaintNodeNotReady, + Effect: v1.TaintEffectNoSchedule, + } tests := []struct { Name string @@ -2271,6 +2275,30 @@ func TestTaintsNodeByCondition(t *testing.T) { }, ExpectedTaints: []*v1.Taint{networkUnavailableTaint}, }, + { + Name: "Ready is false", + Node: &v1.Node{ + ObjectMeta: metav1.ObjectMeta{ + Name: "node0", + CreationTimestamp: metav1.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC), + Labels: map[string]string{ + kubeletapis.LabelZoneRegion: "region1", + kubeletapis.LabelZoneFailureDomain: "zone1", + }, + }, + Status: v1.NodeStatus{ + Conditions: []v1.NodeCondition{ + { + Type: v1.NodeReady, + Status: v1.ConditionFalse, + LastHeartbeatTime: metav1.Date(2015, 1, 1, 12, 0, 0, 0, time.UTC), + LastTransitionTime: metav1.Date(2015, 1, 1, 12, 0, 0, 0, time.UTC), + }, + }, + }, + }, + ExpectedTaints: []*v1.Taint{notReadyTaint}, + }, } for _, test := range tests {