Skip to content

Commit

Permalink
K8SPSMDB-971: Ensure restore status is updated (#1311)
Browse files Browse the repository at this point in the history
Co-authored-by: Viacheslav Sarzhan <[email protected]>
  • Loading branch information
egegunes and hors authored Sep 15, 2023
1 parent 7f8b418 commit b6a53b1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/util/retry"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
Expand Down Expand Up @@ -236,7 +237,14 @@ func (r *ReconcilePerconaServerMongoDBRestore) getBackup(ctx context.Context, cr
}

func (r *ReconcilePerconaServerMongoDBRestore) updateStatus(ctx context.Context, cr *psmdbv1.PerconaServerMongoDBRestore) error {
err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
var backoff = wait.Backoff{
Steps: 5,
Duration: 500 * time.Millisecond,
Factor: 5.0,
Jitter: 0.1,
}

err := retry.OnError(backoff, func(error) bool { return true }, func() error {
c := &psmdbv1.PerconaServerMongoDBRestore{}

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

c.Status = cr.Status

return r.client.Status().Update(ctx, c)
err = r.client.Status().Update(ctx, c)
if err != nil {
return err
}

// ensure status is updated
c = &psmdbv1.PerconaServerMongoDBRestore{}
err = r.client.Get(ctx, types.NamespacedName{Name: cr.Name, Namespace: cr.Namespace}, c)
if err != nil {
return err
}

if c.Status.State != cr.Status.State {
return errors.New("status not updated")
}

return nil
})

if k8serrors.IsNotFound(err) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/perconaservermongodbrestore/physical.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func (r *ReconcilePerconaServerMongoDBRestore) reconcilePhysicalRestore(ctx cont
log.V(1).Info("Check restore status", "command", command, "pod", pod.Name)

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

return nil
Expand Down

0 comments on commit b6a53b1

Please sign in to comment.