Fix conflict error on status update
@@ -9,6 +9,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
+ k8sretry "k8s.io/client-go/util/retry"
"sigs.k8s.io/controller-runtime/pkg/client"
api "github.com/percona/percona-xtradb-cluster-operator/pkg/apis/pxc/v1"
@@ -124,17 +125,20 @@ func (r *ReconcilePerconaXtraDBCluster) updateStatus(cr *api.PerconaXtraDBCluste
}
func (r *ReconcilePerconaXtraDBCluster) writeStatus(cr *api.PerconaXtraDBCluster) error {
- err := r.client.Status().Update(context.TODO(), cr)
- if err != nil {
- // may be it's k8s v1.10 and erlier (e.g. oc3.9) that doesn't support status updates
- // so try to update whole CR
- err := r.client.Update(context.TODO(), cr)
+ err := k8sretry.RetryOnConflict(k8sretry.DefaultRetry, func() error {
+ c := &api.PerconaXtraDBCluster{}
+
+ err := r.client.Get(context.TODO(), types.NamespacedName{Name: cr.Name, Namespace: cr.Namespace}, c)
if err != nil {
- return errors.Wrap(err, "send update")
- }
+ return err
}
- return nil
+ c.Status = cr.Status
+
+ return r.client.Status().Update(context.TODO(), c)
+ })
+
+ return errors.Wrap(err, "write status")
}
func (r *ReconcilePerconaXtraDBCluster) upgradeInProgress(cr *api.PerconaXtraDBCluster, appName string) (bool, error) {
