do not scheudle when status/metadata change
Signed-off-by: Poor12 <shentiecheng@huawei.com>
This commit is contained in:
parent
35d6638263
commit
8d9538b9c9
|
@ -18,6 +18,7 @@ import (
|
|||
"github.com/karmada-io/karmada/pkg/util"
|
||||
"github.com/karmada-io/karmada/pkg/util/fedinformer"
|
||||
"github.com/karmada-io/karmada/pkg/util/gclient"
|
||||
"github.com/karmada-io/karmada/pkg/util/helper"
|
||||
)
|
||||
|
||||
// addAllEventHandlers is a helper function used in Scheduler
|
||||
|
@ -103,6 +104,23 @@ func (s *Scheduler) onResourceBindingAdd(obj interface{}) {
|
|||
}
|
||||
|
||||
func (s *Scheduler) onResourceBindingUpdate(old, cur interface{}) {
|
||||
unstructuredOldObj, err := helper.ToUnstructured(old)
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to transform oldObj, error: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
unstructuredNewObj, err := helper.ToUnstructured(cur)
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to transform newObj, error: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if unstructuredOldObj.GetGeneration() == unstructuredNewObj.GetGeneration() {
|
||||
klog.V(4).Infof("Ignore update event of object (kind=%s, %s/%s) as specification no change", unstructuredOldObj.GetKind(), unstructuredOldObj.GetNamespace(), unstructuredOldObj.GetName())
|
||||
return
|
||||
}
|
||||
|
||||
key, err := cache.MetaNamespaceKeyFunc(cur)
|
||||
if err != nil {
|
||||
klog.Errorf("couldn't get key for object %#v: %v", cur, err)
|
||||
|
|
|
@ -25,7 +25,12 @@ var (
|
|||
scheduler.onResourceBindingAdd(obj)
|
||||
}
|
||||
updateBinding = func(scheduler *Scheduler, obj interface{}) {
|
||||
scheduler.onResourceBindingUpdate(nil, obj)
|
||||
oldRB := &workv1alpha2.ResourceBinding{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Generation: 1,
|
||||
},
|
||||
}
|
||||
scheduler.onResourceBindingUpdate(oldRB, obj)
|
||||
}
|
||||
policyChanged = func(scheduler *Scheduler, obj interface{}) {
|
||||
rb := obj.(*workv1alpha2.ResourceBinding)
|
||||
|
@ -68,7 +73,7 @@ func TestIncomingBindingMetrics(t *testing.T) {
|
|||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: fmt.Sprintf("test-rb-%d", i),
|
||||
Namespace: "bar",
|
||||
Generation: 1,
|
||||
Generation: 2,
|
||||
},
|
||||
}
|
||||
rbInfos = append(rbInfos, rb)
|
||||
|
@ -77,7 +82,8 @@ func TestIncomingBindingMetrics(t *testing.T) {
|
|||
for i := 1; i <= 3; i++ {
|
||||
crb := &workv1alpha2.ClusterResourceBinding{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: fmt.Sprintf("test-rb-%d", i),
|
||||
Name: fmt.Sprintf("test-rb-%d", i),
|
||||
Generation: 2,
|
||||
},
|
||||
}
|
||||
crbInfos = append(crbInfos, crb)
|
||||
|
|
Loading…
Reference in New Issue