Skip to content

Commit e78dbe6

Browse files
committed
Address review feedback
1 parent 604b760 commit e78dbe6

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

pkg/cluster/cluster.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,7 @@ func (c *Cluster) GetSwitchoverSchedule() string {
17661766
}
17671767

17681768
// Switchover does a switchover (via Patroni) to a candidate pod
1769-
func (c *Cluster) Switchover(curMaster *v1.Pod, candidate spec.NamespacedName, inMaintWindow bool) error {
1769+
func (c *Cluster) Switchover(curMaster *v1.Pod, candidate spec.NamespacedName, scheduled bool) error {
17701770
var err error
17711771

17721772
stopCh := make(chan struct{})
@@ -1775,18 +1775,17 @@ func (c *Cluster) Switchover(curMaster *v1.Pod, candidate spec.NamespacedName, i
17751775
defer close(stopCh)
17761776

17771777
var scheduled_at string
1778-
if inMaintWindow {
1779-
c.logger.Debugf("switching over from %q to %q", curMaster.Name, candidate)
1780-
c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeNormal, "Switchover", "Switching over from %q to %q", curMaster.Name, candidate)
1781-
1778+
if scheduled {
17821779
scheduled_at = c.GetSwitchoverSchedule()
17831780
} else {
1781+
c.logger.Debugf("switching over from %q to %q", curMaster.Name, candidate)
1782+
c.eventRecorder.Eventf(c.GetReference(), v1.EventTypeNormal, "Switchover", "Switching over from %q to %q", curMaster.Name, candidate)
17841783
scheduled_at = ""
17851784
}
17861785

17871786
if err = c.patroni.Switchover(curMaster, candidate.Name, scheduled_at); err == nil {
1788-
if inMaintWindow {
1789-
c.logger.Infof("switchover is scheduled at %s", scheduled_at)
1787+
if scheduled {
1788+
c.logger.Infof("switchover from %q to %q is scheduled at %s", curMaster.Name, candidate, scheduled_at)
17901789
return nil
17911790
}
17921791
c.logger.Debugf("successfully switched over from %q to %q", curMaster.Name, candidate)
@@ -1796,7 +1795,7 @@ func (c *Cluster) Switchover(curMaster *v1.Pod, candidate spec.NamespacedName, i
17961795
err = fmt.Errorf("could not get master pod label: %v", err)
17971796
}
17981797
} else {
1799-
if inMaintWindow {
1798+
if scheduled {
18001799
return fmt.Errorf("could not schedule switchover: %v", err)
18011800
}
18021801
err = fmt.Errorf("could not switch over from %q to %q: %v", curMaster.Name, candidate, err)

0 commit comments

Comments
 (0)