mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-21 12:52:14 +02:00
Improve the pod moving behavior during the Kubernetes cluster upgrade. (#281)
* Improve the pod moving behavior during the Kubernetes cluster upgrade. Fix an issue of not waiting for at least one replica to become ready (if the Statefulset indicates there are replicas) when moving the master pod off the decomissioned node. Resolves the first part of #279. Small fixes to error messages. * Eliminate a race condition during the swithover. When the operator initiates the failover (switchover) that fails and then retries it for a second time it may happen that the previous waitForPodChannel is still active. As a result, the operator subscribes to the former master pod two times, causing a panic. The problem was that the original code didn't bother to cancel the waitForPodLalbel for the new master pod in the case when the failover fails. This commit fixes it by adding a stop channel to that function. Code review by @zerg-junior
This commit is contained in:
@@ -858,6 +858,7 @@ func (c *Cluster) GetStatus() *spec.ClusterStatus {
|
||||
// ManualFailover does manual failover to a candidate pod
|
||||
func (c *Cluster) ManualFailover(curMaster *v1.Pod, candidate spec.NamespacedName) error {
|
||||
c.logger.Debugf("failing over from %q to %q", curMaster.Name, candidate)
|
||||
|
||||
podLabelErr := make(chan error)
|
||||
stopCh := make(chan struct{})
|
||||
defer close(podLabelErr)
|
||||
@@ -868,11 +869,12 @@ func (c *Cluster) ManualFailover(curMaster *v1.Pod, candidate spec.NamespacedNam
|
||||
|
||||
role := Master
|
||||
|
||||
_, err := c.waitForPodLabel(ch, &role)
|
||||
|
||||
select {
|
||||
case <-stopCh:
|
||||
case podLabelErr <- err:
|
||||
case podLabelErr <- func() error {
|
||||
_, err := c.waitForPodLabel(ch, stopCh, &role)
|
||||
return err
|
||||
}():
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user