Avoid enqueue when status of k8s pods change

This commit is contained in:
wadecai
2020-06-06 15:36:17 +08:00
parent dfca10f0dc
commit 3db9ab97c6
3 changed files with 99 additions and 1 deletions

View File

@@ -270,13 +270,16 @@ func (pc *PodController) Run(ctx context.Context, podSyncWorkers int) (retErr er
},
UpdateFunc: func(oldObj, newObj interface{}) {
// Create a copy of the old and new pod objects so we don't mutate the cache.
oldPod := oldObj.(*corev1.Pod)
newPod := newObj.(*corev1.Pod)
// At this point we know that something in .metadata or .spec has changed, so we must proceed to sync the pod.
if key, err := cache.MetaNamespaceKeyFunc(newPod); err != nil {
log.G(ctx).Error(err)
} else {
pc.k8sQ.AddRateLimited(key)
if podShouldEnqueue(oldPod, newPod) {
pc.k8sQ.AddRateLimited(key)
}
}
},
DeleteFunc: func(pod interface{}) {