@@ -214,19 +214,16 @@ func (c *Cluster) movePodFromEndOfLifeNode(pod *v1.Pod) (*v1.Pod, error) {
214
214
// MigrateMasterPod migrates master pod via failover to a replica
215
215
func (c * Cluster ) MigrateMasterPod (podName spec.NamespacedName ) error {
216
216
var (
217
- masterCandidateName spec.NamespacedName
218
- err error
219
- eol bool
217
+ err error
218
+ eol bool
220
219
)
221
220
222
221
oldMaster , err := c .KubeClient .Pods (podName .Namespace ).Get (context .TODO (), podName .Name , metav1.GetOptions {})
223
-
224
222
if err != nil {
225
- return fmt .Errorf ("could not get pod: %v" , err )
223
+ return fmt .Errorf ("could not get master pod: %v" , err )
226
224
}
227
225
228
226
c .logger .Infof ("starting process to migrate master pod %q" , podName )
229
-
230
227
if eol , err = c .podIsEndOfLife (oldMaster ); err != nil {
231
228
return fmt .Errorf ("could not get node %q: %v" , oldMaster .Spec .NodeName , err )
232
229
}
@@ -250,21 +247,21 @@ func (c *Cluster) MigrateMasterPod(podName spec.NamespacedName) error {
250
247
}
251
248
c .Statefulset = sset
252
249
}
253
- // We may not have a cached statefulset if the initial cluster sync has aborted, revert to the spec in that case.
250
+ // we may not have a cached statefulset if the initial cluster sync has aborted, revert to the spec in that case
251
+ masterCandidateName := podName
252
+ masterCandidatePod := oldMaster
254
253
if * c .Statefulset .Spec .Replicas > 1 {
255
254
if masterCandidateName , err = c .getSwitchoverCandidate (oldMaster ); err != nil {
256
255
return fmt .Errorf ("could not find suitable replica pod as candidate for failover: %v" , err )
257
256
}
257
+ masterCandidatePod , err = c .KubeClient .Pods (masterCandidateName .Namespace ).Get (context .TODO (), masterCandidateName .Name , metav1.GetOptions {})
258
+ if err != nil {
259
+ return fmt .Errorf ("could not get master candidate pod: %v" , err )
260
+ }
258
261
} else {
259
262
c .logger .Warningf ("migrating single pod cluster %q, this will cause downtime of the Postgres cluster until pod is back" , c .clusterName ())
260
263
}
261
264
262
- masterCandidatePod , err := c .KubeClient .Pods (masterCandidateName .Namespace ).Get (context .TODO (), masterCandidateName .Name , metav1.GetOptions {})
263
-
264
- if err != nil {
265
- return fmt .Errorf ("could not get master candidate pod: %v" , err )
266
- }
267
-
268
265
// there are two cases for each postgres cluster that has its master pod on the node to migrate from:
269
266
// - the cluster has some replicas - migrate one of those if necessary and failover to it
270
267
// - there are no replicas - just terminate the master and wait until it respawns
0 commit comments