Skip to content

Commit 0e11ffb

Browse files
committed
K8SPS-357: Retry getting primary after reboot
1 parent b7ffb32 commit 0e11ffb

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

pkg/controller/ps/crash_recovery.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ import (
55
"context"
66
"fmt"
77
"strings"
8+
"time"
89

910
"github.com/pkg/errors"
1011
corev1 "k8s.io/api/core/v1"
1112
"k8s.io/apimachinery/pkg/labels"
13+
"k8s.io/apimachinery/pkg/util/wait"
14+
"k8s.io/client-go/util/retry"
1215
"sigs.k8s.io/controller-runtime/pkg/client"
1316
logf "sigs.k8s.io/controller-runtime/pkg/log"
1417

@@ -102,7 +105,22 @@ func (r *PerconaServerMySQLReconciler) reconcileFullClusterCrash(ctx context.Con
102105
break
103106
}
104107

105-
primary, err := r.getPrimaryPod(ctx, cr)
108+
var primary *corev1.Pod
109+
err = retry.OnError(wait.Backoff{
110+
Duration: 10 * time.Second,
111+
Factor: 1.5,
112+
Steps: 10,
113+
}, func(err error) bool { return true }, func() error {
114+
var err error
115+
116+
primary, err = r.getPrimaryPod(ctx, cr)
117+
if err != nil {
118+
log.V(1).Error(err, "failed to get primary pod")
119+
return err
120+
}
121+
122+
return nil
123+
})
106124
if err != nil {
107125
log.Error(err, "failed to get primary pod")
108126
break

0 commit comments

Comments
 (0)