Skip to content

Commit

Permalink
Merge pull request #3477 from Poor12/automated-cherry-pick-of-#3455-u…
Browse files Browse the repository at this point in the history
…pstream-release-1.5

Automated cherry pick of #3455: fix generation inconsistent
  • Loading branch information
karmada-bot committed Apr 27, 2023
2 parents 874d148 + 0723611 commit a09a584
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion pkg/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,15 @@ func (s *Scheduler) doScheduleBinding(namespace, name string) (err error) {
}
// TODO(dddddai): reschedule bindings on cluster change
klog.V(3).Infof("Don't need to schedule ResourceBinding(%s/%s)", rb.Namespace, rb.Name)

// If no scheduling is required, we need to ensure that binding.Generation is equal to
// binding.Status.SchedulerObservedGeneration which means the current status of binding
// is the latest status of successful scheduling.
if rb.Generation != rb.Status.SchedulerObservedGeneration {
updateRB := rb.DeepCopy()
updateRB.Status.SchedulerObservedGeneration = updateRB.Generation
return patchBindingStatus(s.KarmadaClient, rb, updateRB)
}
return nil
}

Expand Down Expand Up @@ -385,6 +394,15 @@ func (s *Scheduler) doScheduleClusterBinding(name string) (err error) {
}
// TODO(dddddai): reschedule bindings on cluster change
klog.Infof("Don't need to schedule ClusterResourceBinding(%s)", name)

// If no scheduling is required, we need to ensure that binding.Generation is equal to
// binding.Status.SchedulerObservedGeneration which means the current status of binding
// is the latest status of successful scheduling.
if crb.Generation != crb.Status.SchedulerObservedGeneration {
updateCRB := crb.DeepCopy()
updateCRB.Status.SchedulerObservedGeneration = updateCRB.Generation
return patchClusterResourceBindingStatus(s.KarmadaClient, crb, updateCRB)
}
return nil
}

Expand Down Expand Up @@ -526,6 +544,7 @@ func (s *Scheduler) patchScheduleResultForResourceBinding(oldBinding *workv1alph
_, err = s.KarmadaClient.WorkV1alpha2().ResourceBindings(newBinding.Namespace).Patch(context.TODO(), newBinding.Name, types.MergePatchType, patchBytes, metav1.PatchOptions{})
if err != nil {
klog.Errorf("Failed to patch schedule to ResourceBinding(%s/%s): %v", oldBinding.Namespace, oldBinding.Name, err)
return err
}

klog.V(4).Infof("Patch schedule to ResourceBinding(%s/%s) succeed", oldBinding.Namespace, oldBinding.Name)
Expand Down Expand Up @@ -668,7 +687,13 @@ func (s *Scheduler) patchScheduleResultForClusterResourceBinding(oldBinding *wor
}

_, err = s.KarmadaClient.WorkV1alpha2().ClusterResourceBindings().Patch(context.TODO(), newBinding.Name, types.MergePatchType, patchBytes, metav1.PatchOptions{})
return err
if err != nil {
klog.Errorf("Failed to patch schedule to ClusterResourceBinding(%s): %v", oldBinding.Name, err)
return err
}

klog.V(4).Infof("Patch schedule to ClusterResourceBinding(%s) succeed", oldBinding.Name)
return nil
}

func (s *Scheduler) handleErr(err error, key interface{}) {
Expand Down

0 comments on commit a09a584

Please sign in to comment.