Skip to content

Commit

Permalink
Especially double check when bootstrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
eberlep committed Jul 12, 2024
1 parent 59c5021 commit f1ca8db
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions controllers/postgres_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ func (r *PostgresReconciler) checkAndUpdatePatroniReplicationConfig(log logr.Log
if len(leaderPods.Items) != 1 {
log.V(debugLogLevel).Info("expected exactly one leader pod, selecting all spilo pods as a last resort (might be ok if it is still creating)")
// To make sure any updates to the Zalando postgresql manifest are written, we do not requeue in this case
return allDone, r.updatePatroniReplicationConfigOnAllPods(log, ctx, instance)
return requeueAfterReconcile, r.updatePatroniReplicationConfigOnAllPods(log, ctx, instance)
}
leaderIP := leaderPods.Items[0].Status.PodIP

Expand Down Expand Up @@ -1170,8 +1170,24 @@ func (r *PostgresReconciler) httpPatchPatroni(log logr.Logger, ctx context.Conte
StandbyCluster: nil,
}
if instance.Spec.PostgresConnection.SynchronousReplication {
// enable sync replication
request.SynchronousNodesAdditional = pointer.String(instance.Spec.PostgresConnection.ConnectedPostgresID)
// fetch standby
standby := &pg.Postgres{}
ns := types.NamespacedName{
Name: instance.Spec.PostgresConnection.ConnectedPostgresID,
Namespace: instance.Namespace,
}
if err := r.CtrlClient.Get(ctx, ns, standby); err != nil {
if apierrors.IsNotFound(err) {
// the instance was updated, but does not exist anymore -> do nothing, it was probably deleted
// enable sync replication
request.SynchronousNodesAdditional = nil
}
r.recorder.Eventf(standby, "Warning", "Error", "failed to get referenced standby postgres: %v", err)
request.SynchronousNodesAdditional = nil
} else {
// enable sync replication
request.SynchronousNodesAdditional = pointer.String(standby.ToPeripheralResourceName())
}
} else {
// disable sync replication
request.SynchronousNodesAdditional = nil
Expand All @@ -1183,7 +1199,7 @@ func (r *PostgresReconciler) httpPatchPatroni(log logr.Logger, ctx context.Conte
CreateReplicaMethods: []string{"basebackup_fast_xlog"},
Host: instance.Spec.PostgresConnection.ConnectionIP,
Port: int(instance.Spec.PostgresConnection.ConnectionPort),
ApplicationName: instance.ObjectMeta.Name,
ApplicationName: instance.ToPeripheralResourceName(),
},
SynchronousNodesAdditional: nil,
}
Expand Down

0 comments on commit f1ca8db

Please sign in to comment.