mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-05 16:29:24 +02:00
Merge branch 'master' into pending_rolling_updates
This commit is contained in:
+46
-18
@@ -216,18 +216,20 @@ func (c *Cluster) getTeamMembers() ([]string, error) {
|
||||
|
||||
token, err := c.oauthTokenGetter.getOAuthToken()
|
||||
if err != nil {
|
||||
return []string{}, fmt.Errorf("could not get oauth token: %v", err)
|
||||
c.logger.Warnf("could not get oauth token to authenticate to team service API, returning empty list of team members: %v", err)
|
||||
return []string{}, nil
|
||||
}
|
||||
|
||||
teamInfo, err := c.teamsAPIClient.TeamInfo(c.Spec.TeamID, token)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not get team info: %v", err)
|
||||
c.logger.Warnf("could not get team info, returning empty list of team members: %v", err)
|
||||
return []string{}, nil
|
||||
}
|
||||
|
||||
return teamInfo.Members, nil
|
||||
}
|
||||
|
||||
func (c *Cluster) waitForPodLabel(podEvents chan spec.PodEvent, role *PostgresRole) (*v1.Pod, error) {
|
||||
func (c *Cluster) waitForPodLabel(podEvents chan spec.PodEvent, stopChan chan struct{}, role *PostgresRole) (*v1.Pod, error) {
|
||||
timeout := time.After(c.OpConfig.PodLabelWaitTimeout)
|
||||
for {
|
||||
select {
|
||||
@@ -243,6 +245,8 @@ func (c *Cluster) waitForPodLabel(podEvents chan spec.PodEvent, role *PostgresRo
|
||||
}
|
||||
case <-timeout:
|
||||
return nil, fmt.Errorf("pod label wait timeout")
|
||||
case <-stopChan:
|
||||
return nil, fmt.Errorf("pod label wait cancelled")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -280,7 +284,10 @@ func (c *Cluster) waitStatefulsetReady() error {
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Cluster) waitPodLabelsReady() error {
|
||||
func (c *Cluster) _waitPodLabelsReady(anyReplica bool) error {
|
||||
var (
|
||||
podsNumber int
|
||||
)
|
||||
ls := c.labelsSet(false)
|
||||
namespace := c.Namespace
|
||||
|
||||
@@ -297,35 +304,56 @@ func (c *Cluster) waitPodLabelsReady() error {
|
||||
c.OpConfig.PodRoleLabel: string(Replica),
|
||||
}).String(),
|
||||
}
|
||||
pods, err := c.KubeClient.Pods(namespace).List(listOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
podsNumber = 1
|
||||
if !anyReplica {
|
||||
pods, err := c.KubeClient.Pods(namespace).List(listOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
podsNumber = len(pods.Items)
|
||||
c.logger.Debugf("Waiting for %d pods to become ready", podsNumber)
|
||||
} else {
|
||||
c.logger.Debugf("Waiting for any replica pod to become ready")
|
||||
}
|
||||
podsNumber := len(pods.Items)
|
||||
|
||||
err = retryutil.Retry(c.OpConfig.ResourceCheckInterval, c.OpConfig.ResourceCheckTimeout,
|
||||
err := retryutil.Retry(c.OpConfig.ResourceCheckInterval, c.OpConfig.ResourceCheckTimeout,
|
||||
func() (bool, error) {
|
||||
masterPods, err2 := c.KubeClient.Pods(namespace).List(masterListOption)
|
||||
if err2 != nil {
|
||||
return false, err2
|
||||
masterCount := 0
|
||||
if !anyReplica {
|
||||
masterPods, err2 := c.KubeClient.Pods(namespace).List(masterListOption)
|
||||
if err2 != nil {
|
||||
return false, err2
|
||||
}
|
||||
if len(masterPods.Items) > 1 {
|
||||
return false, fmt.Errorf("too many masters (%d pods with the master label found)",
|
||||
len(masterPods.Items))
|
||||
}
|
||||
masterCount = len(masterPods.Items)
|
||||
}
|
||||
replicaPods, err2 := c.KubeClient.Pods(namespace).List(replicaListOption)
|
||||
if err2 != nil {
|
||||
return false, err2
|
||||
}
|
||||
if len(masterPods.Items) > 1 {
|
||||
return false, fmt.Errorf("too many masters")
|
||||
}
|
||||
if len(replicaPods.Items) == podsNumber {
|
||||
replicaCount := len(replicaPods.Items)
|
||||
if anyReplica && replicaCount > 0 {
|
||||
c.logger.Debugf("Found %d running replica pods", replicaCount)
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return len(masterPods.Items)+len(replicaPods.Items) == podsNumber, nil
|
||||
return masterCount+replicaCount >= podsNumber, nil
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *Cluster) waitForAnyReplicaLabelReady() error {
|
||||
return c._waitPodLabelsReady(true)
|
||||
}
|
||||
|
||||
func (c *Cluster) waitForAllPodsLabelReady() error {
|
||||
return c._waitPodLabelsReady(false)
|
||||
}
|
||||
|
||||
func (c *Cluster) waitStatefulsetPodsReady() error {
|
||||
c.setProcessName("waiting for the pods of the statefulset")
|
||||
// TODO: wait for the first Pod only
|
||||
@@ -334,7 +362,7 @@ func (c *Cluster) waitStatefulsetPodsReady() error {
|
||||
}
|
||||
|
||||
// TODO: wait only for master
|
||||
if err := c.waitPodLabelsReady(); err != nil {
|
||||
if err := c.waitForAllPodsLabelReady(); err != nil {
|
||||
return fmt.Errorf("pod labels error: %v", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user