Add retry on CreateOrUpdateWork
Signed-off-by: pigletfly <wangbing.adam@gmail.com>
This commit is contained in:
parent
b5493ccf5f
commit
c996f6bd5b
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue