Merge pull request #4814 from whitewindmills/retry-on-conflict-for-apply-cluster-policy

Use RetryOnConflict for applying CRB
This commit is contained in:
karmada-bot 2024-04-09 12:14:52 +08:00 committed by GitHub
commit 7a65ee8e11
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 27 additions and 24 deletions

View File

@ -620,6 +620,7 @@ func (d *ResourceDetector) ApplyClusterPolicy(object *unstructured.Unstructured,
return err
}
bindingCopy := binding.DeepCopy()
err = retry.RetryOnConflict(retry.DefaultRetry, func() (err error) {
operationResult, err = controllerutil.CreateOrUpdate(context.TODO(), d.Client, bindingCopy, func() error {
// If this binding exists and its owner is not the input object, return error and let garbage collector
// delete this binding and try again later. See https://github.com/karmada-io/karmada/issues/2090.
@ -646,6 +647,8 @@ func (d *ResourceDetector) ApplyClusterPolicy(object *unstructured.Unstructured,
bindingCopy.Spec.ConflictResolution = binding.Spec.ConflictResolution
return nil
})
return err
})
if err != nil {
klog.Errorf("Failed to apply cluster policy(%s) for object: %s. error: %v", policy.Name, objectKey, err)
return err