node labels and taints do not change, node events are ignored in daemonset controller

Signed-off-by: xigang <wangxigang2014@gmail.com>
This commit is contained in:
xigang
2023-11-01 16:40:36 +08:00
parent 515d1ce6c0
commit 6b3476b79f
2 changed files with 46 additions and 37 deletions

View File

@@ -24,8 +24,6 @@ import (
"sync"
"time"
"k8s.io/klog/v2"
apps "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
apiequality "k8s.io/apimachinery/pkg/api/equality"
@@ -49,6 +47,7 @@ import (
"k8s.io/client-go/util/workqueue"
v1helper "k8s.io/component-helpers/scheduling/corev1"
"k8s.io/component-helpers/scheduling/corev1/nodeaffinity"
"k8s.io/klog/v2"
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/controller/daemon/util"
@@ -654,42 +653,11 @@ func (dsc *DaemonSetsController) addNode(logger klog.Logger, obj interface{}) {
}
}
// nodeInSameCondition returns true if all effective types ("Status" is true) equals;
// otherwise, returns false.
func nodeInSameCondition(old []v1.NodeCondition, cur []v1.NodeCondition) bool {
if len(old) == 0 && len(cur) == 0 {
return true
}
c1map := map[v1.NodeConditionType]v1.ConditionStatus{}
for _, c := range old {
if c.Status == v1.ConditionTrue {
c1map[c.Type] = c.Status
}
}
for _, c := range cur {
if c.Status != v1.ConditionTrue {
continue
}
if _, found := c1map[c.Type]; !found {
return false
}
delete(c1map, c.Type)
}
return len(c1map) == 0
}
// shouldIgnoreNodeUpdate returns true if Node labels and taints have not changed, otherwise returns false.
// If other calling functions need to use other properties of Node, shouldIgnoreNodeUpdate needs to be updated.
func shouldIgnoreNodeUpdate(oldNode, curNode v1.Node) bool {
if !nodeInSameCondition(oldNode.Status.Conditions, curNode.Status.Conditions) {
return false
}
oldNode.ResourceVersion = curNode.ResourceVersion
oldNode.Status.Conditions = curNode.Status.Conditions
return apiequality.Semantic.DeepEqual(oldNode, curNode)
return apiequality.Semantic.DeepEqual(oldNode.Labels, curNode.Labels) &&
apiequality.Semantic.DeepEqual(oldNode.Spec.Taints, curNode.Spec.Taints)
}
func (dsc *DaemonSetsController) updateNode(logger klog.Logger, old, cur interface{}) {
@@ -706,6 +674,7 @@ func (dsc *DaemonSetsController) updateNode(logger klog.Logger, old, cur interfa
}
// TODO: it'd be nice to pass a hint with these enqueues, so that each ds would only examine the added node (unless it has other work to do, too).
for _, ds := range dsList {
// If NodeShouldRunDaemonPod needs to uses other than Labels and Taints (mutable) properties of node, it needs to update shouldIgnoreNodeUpdate.
oldShouldRun, oldShouldContinueRunning := NodeShouldRunDaemonPod(oldNode, ds)
currentShouldRun, currentShouldContinueRunning := NodeShouldRunDaemonPod(curNode, ds)
if (oldShouldRun != currentShouldRun) || (oldShouldContinueRunning != currentShouldContinueRunning) {