Skip to content

Commit

Permalink
fix: filter k8s node update event to avoid bcs-k8s-watch queue stuck.…
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanhe-bupt committed Oct 8, 2019
1 parent 5aa8328 commit b0be599
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions bcs-k8s/bcs-k8s-watch/app/k8s/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ func (watcher *Watcher) UpdateEvent(oldObj, newObj interface{}) {
// if newTgwIngress.ResourceVersion == oldTgwIngress.ResourceVersion {
// return
//}

if reflect.DeepEqual(oldObj, d) {
dMeta := d.(metav1.Object)
namespace := dMeta.GetNamespace()
Expand All @@ -173,6 +174,30 @@ func (watcher *Watcher) UpdateEvent(oldObj, newObj interface{}) {
return
}

// skip unnecessary node update event, to avoid writer queue stuck
if watcher.resourceType == "Node" {
oldNode := oldObj.(*v1.Node)
newNode := newObj.(*v1.Node)

var tempLastTimes = make([]metav1.Time, 5)
tempVersion := newNode.ResourceVersion
newNode.ResourceVersion = oldNode.ResourceVersion
for i := range newNode.Status.Conditions {
tempLastTimes[i] = newNode.Status.Conditions[i].LastHeartbeatTime
newNode.Status.Conditions[i].LastHeartbeatTime = oldNode.Status.Conditions[i].LastHeartbeatTime
}

if reflect.DeepEqual(oldNode, newNode) {
glog.V(2).Infof("skip unnecessary node update event")
return
}

newNode.ResourceVersion = tempVersion
for i := range newNode.Status.Conditions {
newNode.Status.Conditions[i].LastHeartbeatTime = tempLastTimes[i]
}
}

syncData := watcher.genSyncData(newObj, "Update")
if syncData == nil {
return
Expand Down

0 comments on commit b0be599

Please sign in to comment.