Skip to content

Commit b6a53b1

Browse files
egeguneshors
andauthored
K8SPSMDB-971: Ensure restore status is updated (#1311)
Co-authored-by: Viacheslav Sarzhan <[email protected]>
1 parent 7f8b418 commit b6a53b1

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

pkg/controller/perconaservermongodbrestore/perconaservermongodbrestore_controller.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1414
"k8s.io/apimachinery/pkg/runtime"
1515
"k8s.io/apimachinery/pkg/types"
16+
"k8s.io/apimachinery/pkg/util/wait"
1617
"k8s.io/client-go/util/retry"
1718
"sigs.k8s.io/controller-runtime/pkg/client"
1819
"sigs.k8s.io/controller-runtime/pkg/controller"
@@ -236,7 +237,14 @@ func (r *ReconcilePerconaServerMongoDBRestore) getBackup(ctx context.Context, cr
236237
}
237238

238239
func (r *ReconcilePerconaServerMongoDBRestore) updateStatus(ctx context.Context, cr *psmdbv1.PerconaServerMongoDBRestore) error {
239-
err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
240+
var backoff = wait.Backoff{
241+
Steps: 5,
242+
Duration: 500 * time.Millisecond,
243+
Factor: 5.0,
244+
Jitter: 0.1,
245+
}
246+
247+
err := retry.OnError(backoff, func(error) bool { return true }, func() error {
240248
c := &psmdbv1.PerconaServerMongoDBRestore{}
241249

242250
err := r.client.Get(ctx, types.NamespacedName{Name: cr.Name, Namespace: cr.Namespace}, c)
@@ -246,7 +254,23 @@ func (r *ReconcilePerconaServerMongoDBRestore) updateStatus(ctx context.Context,
246254

247255
c.Status = cr.Status
248256

249-
return r.client.Status().Update(ctx, c)
257+
err = r.client.Status().Update(ctx, c)
258+
if err != nil {
259+
return err
260+
}
261+
262+
// ensure status is updated
263+
c = &psmdbv1.PerconaServerMongoDBRestore{}
264+
err = r.client.Get(ctx, types.NamespacedName{Name: cr.Name, Namespace: cr.Namespace}, c)
265+
if err != nil {
266+
return err
267+
}
268+
269+
if c.Status.State != cr.Status.State {
270+
return errors.New("status not updated")
271+
}
272+
273+
return nil
250274
})
251275

252276
if k8serrors.IsNotFound(err) {

pkg/controller/perconaservermongodbrestore/physical.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func (r *ReconcilePerconaServerMongoDBRestore) reconcilePhysicalRestore(ctx cont
276276
log.V(1).Info("Check restore status", "command", command, "pod", pod.Name)
277277

278278
if err := r.clientcmd.Exec(ctx, &pod, "mongod", command, nil, stdoutBuf, stderrBuf, false); err != nil {
279-
return errors.Wrap(err, "describe restore")
279+
return errors.Wrapf(err, "describe restore stderr: %s stdout: %s", stderrBuf.String(), stdoutBuf.String())
280280
}
281281

282282
return nil

0 commit comments

Comments
 (0)