mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-22 09:39:54 +02:00
wrap getting Patroni state into retry
This commit is contained in:
+22
-5
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"time"
|
||||||
|
|
||||||
appsv1 "k8s.io/api/apps/v1"
|
appsv1 "k8s.io/api/apps/v1"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
@@ -11,6 +12,7 @@ import (
|
|||||||
|
|
||||||
"github.com/zalando/postgres-operator/pkg/spec"
|
"github.com/zalando/postgres-operator/pkg/spec"
|
||||||
"github.com/zalando/postgres-operator/pkg/util"
|
"github.com/zalando/postgres-operator/pkg/util"
|
||||||
|
"github.com/zalando/postgres-operator/pkg/util/retryutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Cluster) listPods() ([]v1.Pod, error) {
|
func (c *Cluster) listPods() ([]v1.Pod, error) {
|
||||||
@@ -309,12 +311,27 @@ func (c *Cluster) isSafeToRecreatePods(pods *v1.PodList) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, pod := range pods.Items {
|
for _, pod := range pods.Items {
|
||||||
state, err := c.patroni.GetPatroniMemberState(&pod)
|
|
||||||
|
err := retryutil.Retry(3*time.Second, 15*time.Second,
|
||||||
|
func() (bool, error) {
|
||||||
|
|
||||||
|
var state string
|
||||||
|
var err error
|
||||||
|
|
||||||
|
state, err = c.patroni.GetPatroniMemberState(&pod)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
c.logger.Errorf("failed to get Patroni state for pod: %s", err)
|
||||||
|
return false, err
|
||||||
|
} else if state == "creating replica" {
|
||||||
|
c.logger.Warningf("cannot re-create replica %s: it is currently being initialized", pod.Name)
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.logger.Errorf("failed to get Patroni state for pod: %s", err)
|
|
||||||
return false
|
|
||||||
} else if state == "creating replica" {
|
|
||||||
c.logger.Warningf("cannot re-create replica %s: it is currently being initialized", pod.Name)
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user