From 2a7eb6dfe949ae26270ed8cb3a407a5935295dcf Mon Sep 17 00:00:00 2001 From: Zou Nengren Date: Wed, 19 Jan 2022 14:24:42 +0800 Subject: [PATCH] replace reflect with generation (#885) Signed-off-by: zounengren --- pkg/controller/sidecarset/sidecarset_controller.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pkg/controller/sidecarset/sidecarset_controller.go b/pkg/controller/sidecarset/sidecarset_controller.go index 4099d3860d..a84407a3fa 100644 --- a/pkg/controller/sidecarset/sidecarset_controller.go +++ b/pkg/controller/sidecarset/sidecarset_controller.go @@ -19,7 +19,6 @@ package sidecarset import ( "context" "flag" - "reflect" appsv1alpha1 "github.com/openkruise/kruise/apis/apps/v1alpha1" "github.com/openkruise/kruise/pkg/control/sidecarcontrol" @@ -90,10 +89,10 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error { // Watch for changes to SidecarSet err = c.Watch(&source.Kind{Type: &appsv1alpha1.SidecarSet{}}, &handler.EnqueueRequestForObject{}, predicate.Funcs{ UpdateFunc: func(e event.UpdateEvent) bool { - old := e.ObjectOld.(*appsv1alpha1.SidecarSet) - new := e.ObjectNew.(*appsv1alpha1.SidecarSet) - if !reflect.DeepEqual(old.Spec, new.Spec) { - klog.V(3).Infof("Observed updated Spec for SidecarSet: %s/%s", new.Namespace, new.Name) + oldScS := e.ObjectOld.(*appsv1alpha1.SidecarSet) + newScS := e.ObjectNew.(*appsv1alpha1.SidecarSet) + if oldScS.GetGeneration() != newScS.GetGeneration() { + klog.V(3).Infof("Observed updated Spec for SidecarSet: %s/%s", newScS.GetNamespace(), newScS.GetName()) return true } return false