wrap getting Patroni state into retry
This commit is contained in:
		
							parent
							
								
									168b679506
								
							
						
					
					
						commit
						d9755db4d5
					
				| 
						 | 
					@ -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 {
 | 
									if err != nil {
 | 
				
			||||||
					c.logger.Errorf("failed to get Patroni state for pod: %s", err)
 | 
										c.logger.Errorf("failed to get Patroni state for pod: %s", err)
 | 
				
			||||||
			return false
 | 
										return false, err
 | 
				
			||||||
				} else if state == "creating replica" {
 | 
									} else if state == "creating replica" {
 | 
				
			||||||
					c.logger.Warningf("cannot re-create replica %s: it is currently being initialized", pod.Name)
 | 
										c.logger.Warningf("cannot re-create replica %s: it is currently being initialized", pod.Name)
 | 
				
			||||||
 | 
										return false, nil
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									return true, nil
 | 
				
			||||||
 | 
								},
 | 
				
			||||||
 | 
							)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if err != nil {
 | 
				
			||||||
			return false
 | 
								return false
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue