diff --git a/pkg/util/helper/work.go b/pkg/util/helper/work.go index 92592a9db..fca85c158 100644 --- a/pkg/util/helper/work.go +++ b/pkg/util/helper/work.go @@ -7,6 +7,7 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/client-go/util/retry" "k8s.io/klog/v2" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" @@ -39,10 +40,17 @@ func CreateOrUpdateWork(client client.Client, workMeta metav1.ObjectMeta, resour } runtimeObject := work.DeepCopy() - operationResult, err := controllerutil.CreateOrUpdate(context.TODO(), client, runtimeObject, func() error { - runtimeObject.Spec = work.Spec - runtimeObject.Labels = work.Labels - runtimeObject.Annotations = work.Annotations + var operationResult controllerutil.OperationResult + err = retry.RetryOnConflict(retry.DefaultRetry, func() (err error) { + operationResult, err = controllerutil.CreateOrUpdate(context.TODO(), client, runtimeObject, func() error { + runtimeObject.Spec = work.Spec + runtimeObject.Labels = work.Labels + runtimeObject.Annotations = work.Annotations + return nil + }) + if err != nil { + return err + } return nil }) if err != nil {