use meta.Accessor() in onResourceBindingUpdate() (#6141)

Signed-off-by: zach593 <zach_li@outlook.com>
This commit is contained in:
Zach 2025-02-21 09:39:16 +08:00 committed by GitHub
parent 71359de8f2
commit cfebd4dcb6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 7 deletions

View File

@ -37,7 +37,6 @@ import (
"github.com/karmada-io/karmada/pkg/util" "github.com/karmada-io/karmada/pkg/util"
"github.com/karmada-io/karmada/pkg/util/fedinformer" "github.com/karmada-io/karmada/pkg/util/fedinformer"
"github.com/karmada-io/karmada/pkg/util/gclient" "github.com/karmada-io/karmada/pkg/util/gclient"
"github.com/karmada-io/karmada/pkg/util/helper"
) )
// addAllEventHandlers is a helper function used in Scheduler // addAllEventHandlers is a helper function used in Scheduler
@ -130,20 +129,24 @@ func (s *Scheduler) onResourceBindingAdd(obj interface{}) {
} }
func (s *Scheduler) onResourceBindingUpdate(old, cur interface{}) { func (s *Scheduler) onResourceBindingUpdate(old, cur interface{}) {
unstructuredOldObj, err := helper.ToUnstructured(old) oldMeta, err := meta.Accessor(old)
if err != nil { if err != nil {
klog.Errorf("Failed to transform oldObj, error: %v", err) klog.Errorf("Failed to transform oldObj as metav1.Object, error: %v", err)
return return
} }
unstructuredNewObj, err := helper.ToUnstructured(cur) newMeta, err := meta.Accessor(cur)
if err != nil { if err != nil {
klog.Errorf("Failed to transform newObj, error: %v", err) klog.Errorf("Failed to transform newObj as metav1.Object, error: %v", err)
return return
} }
if unstructuredOldObj.GetGeneration() == unstructuredNewObj.GetGeneration() { if oldMeta.GetGeneration() == newMeta.GetGeneration() {
klog.V(4).Infof("Ignore update event of object (kind=%s, %s/%s) as specification no change", unstructuredOldObj.GetKind(), unstructuredOldObj.GetNamespace(), unstructuredOldObj.GetName()) if oldMeta.GetNamespace() != "" {
klog.V(4).Infof("Ignore update event of resourceBinding %s/%s as specification no change", oldMeta.GetNamespace(), oldMeta.GetName())
} else {
klog.V(4).Infof("Ignore update event of clusterResourceBinding %s as specification no change", oldMeta.GetName())
}
return return
} }