perform manual failover on pg cluster rolling upgrade

This commit is contained in:
Murat Kabilov
2017-10-04 16:56:47 +03:00
committed by GitHub
parent 00194d0130
commit 48ec6b35b9
3 changed files with 56 additions and 8 deletions
+13 -6
View File
@@ -3,6 +3,7 @@ package cluster
import (
"encoding/json"
"fmt"
"math/rand"
"strings"
"time"
@@ -182,15 +183,17 @@ func (c *Cluster) getTeamMembers() ([]string, error) {
return teamInfo.Members, nil
}
func (c *Cluster) waitForPodLabel(podEvents chan spec.PodEvent) error {
func (c *Cluster) waitForPodLabel(podEvents chan spec.PodEvent, role *PostgresRole) error {
for {
select {
case podEvent := <-podEvents:
role := c.podSpiloRole(podEvent.CurPod)
// We cannot assume any role of the newly created pod. Normally, for a multi-pod cluster
// we should observe the 'replica' value, but it could be that some pods are not allowed
// to promote, therefore, the new pod could be a master as well.
if role == constants.PodRoleMaster || role == constants.PodRoleReplica {
podRole := PostgresRole(podEvent.CurPod.Labels[c.OpConfig.PodRoleLabel])
if role == nil {
if podRole == Master || podRole == Replica {
return nil
}
} else if *role == podRole {
return nil
}
case <-time.After(c.OpConfig.PodLabelWaitTimeout):
@@ -342,3 +345,7 @@ func (c *Cluster) credentialSecretNameForCluster(username string, clusterName st
func (c *Cluster) podSpiloRole(pod *v1.Pod) string {
return pod.Labels[c.OpConfig.PodRoleLabel]
}
func masterCandidate(replicas []spec.NamespacedName) spec.NamespacedName {
return replicas[rand.Intn(len(replicas))]
}