Skip to content

Commit b3637c9

Browse files
author
kaiyuechen
committed
Reconcile NoExecute Taint
1 parent cb38560 commit b3637c9

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

pkg/controller/nodelifecycle/node_lifecycle_controller.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ func (nc *Controller) processTaintBaseEviction(node *v1.Node, observedReadyCondi
872872
if !nodeutil.SwapNodeControllerTaint(nc.kubeClient, []*v1.Taint{&taintToAdd}, []*v1.Taint{UnreachableTaintTemplate}, node) {
873873
klog.Errorf("Failed to instantly swap UnreachableTaint to NotReadyTaint. Will try again in the next cycle.")
874874
}
875-
} else if nc.markNodeForTainting(node) {
875+
} else if nc.markNodeForTainting(node, v1.ConditionFalse) {
876876
klog.V(2).Infof("Node %v is NotReady as of %v. Adding it to the Taint queue.",
877877
node.Name,
878878
decisionTimestamp,
@@ -885,7 +885,7 @@ func (nc *Controller) processTaintBaseEviction(node *v1.Node, observedReadyCondi
885885
if !nodeutil.SwapNodeControllerTaint(nc.kubeClient, []*v1.Taint{&taintToAdd}, []*v1.Taint{NotReadyTaintTemplate}, node) {
886886
klog.Errorf("Failed to instantly swap NotReadyTaint to UnreachableTaint. Will try again in the next cycle.")
887887
}
888-
} else if nc.markNodeForTainting(node) {
888+
} else if nc.markNodeForTainting(node, v1.ConditionUnknown) {
889889
klog.V(2).Infof("Node %v is unresponsive as of %v. Adding it to the Taint queue.",
890890
node.Name,
891891
decisionTimestamp,
@@ -1476,9 +1476,21 @@ func (nc *Controller) evictPods(node *v1.Node, pods []*v1.Pod) (bool, error) {
14761476
return nc.zonePodEvictor[utilnode.GetZoneKey(node)].Add(node.Name, string(node.UID)), nil
14771477
}
14781478

1479-
func (nc *Controller) markNodeForTainting(node *v1.Node) bool {
1479+
func (nc *Controller) markNodeForTainting(node *v1.Node, status v1.ConditionStatus) bool {
14801480
nc.evictorLock.Lock()
14811481
defer nc.evictorLock.Unlock()
1482+
if status == v1.ConditionFalse {
1483+
if !taintutils.TaintExists(node.Spec.Taints, NotReadyTaintTemplate) {
1484+
nc.zoneNoExecuteTainter[utilnode.GetZoneKey(node)].SetRemove(node.Name)
1485+
}
1486+
}
1487+
1488+
if status == v1.ConditionUnknown {
1489+
if !taintutils.TaintExists(node.Spec.Taints, UnreachableTaintTemplate) {
1490+
nc.zoneNoExecuteTainter[utilnode.GetZoneKey(node)].SetRemove(node.Name)
1491+
}
1492+
}
1493+
14821494
return nc.zoneNoExecuteTainter[utilnode.GetZoneKey(node)].Add(node.Name, string(node.UID))
14831495
}
14841496

pkg/controller/nodelifecycle/scheduler/rate_limited_queue.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ func (q *UniqueQueue) Clear() {
194194
}
195195
}
196196

197+
// SetRemove remove value from the set if value existed
198+
func (q *UniqueQueue) SetRemove(value string) {
199+
q.lock.Lock()
200+
defer q.lock.Unlock()
201+
if q.set.Has(value) {
202+
q.set.Delete(value)
203+
}
204+
}
205+
197206
// RateLimitedTimedQueue is a unique item priority queue ordered by
198207
// the expected next time of execution. It is also rate limited.
199208
type RateLimitedTimedQueue struct {
@@ -280,6 +289,11 @@ func (q *RateLimitedTimedQueue) Clear() {
280289
q.queue.Clear()
281290
}
282291

292+
// SetRemove remove value from the set of the queue
293+
func (q *RateLimitedTimedQueue) SetRemove(value string) {
294+
q.queue.SetRemove(value)
295+
}
296+
283297
// SwapLimiter safely swaps current limiter for this queue with the
284298
// passed one if capacities or qps's differ.
285299
func (q *RateLimitedTimedQueue) SwapLimiter(newQPS float32) {

pkg/controller/nodelifecycle/scheduler/rate_limited_queue_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,17 @@ func TestClear(t *testing.T) {
282282
}
283283
}
284284

285+
func TestSetRemove(t *testing.T) {
286+
evictor := NewRateLimitedTimedQueue(flowcontrol.NewFakeAlwaysRateLimiter())
287+
evictor.Add("first", "11111")
288+
289+
evictor.SetRemove("first")
290+
291+
if evictor.queue.set.Len() != 0 {
292+
t.Fatalf("SetRemove should remove element from the set.")
293+
}
294+
}
295+
285296
func TestSwapLimiter(t *testing.T) {
286297
evictor := NewRateLimitedTimedQueue(flowcontrol.NewFakeAlwaysRateLimiter())
287298
fakeAlways := flowcontrol.NewFakeAlwaysRateLimiter()

0 commit comments

Comments
 (0)