From ea3d3081f2a74e2dfe94fe15ada2561e9281f2c4 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Fri, 12 Jul 2024 15:56:36 +0200 Subject: [PATCH 01/13] Double check config --- controllers/postgres_controller.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/controllers/postgres_controller.go b/controllers/postgres_controller.go index 612f1ecc..316c580b 100644 --- a/controllers/postgres_controller.go +++ b/controllers/postgres_controller.go @@ -1064,12 +1064,12 @@ func (r *PostgresReconciler) checkAndUpdatePatroniReplicationConfig(log logr.Log if instance.Spec.PostgresConnection.SynchronousReplication { if resp.SynchronousNodesAdditional == nil || *resp.SynchronousNodesAdditional != instance.Spec.PostgresConnection.ConnectedPostgresID { log.V(debugLogLevel).Info("synchronous_nodes_additional mistmatch, updating", "response", resp) - return allDone, r.httpPatchPatroni(log, ctx, instance, leaderIP) + return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP) } } else { if resp.SynchronousNodesAdditional != nil { log.V(debugLogLevel).Info("synchronous_nodes_additional mistmatch, updating", "response", resp) - return allDone, r.httpPatchPatroni(log, ctx, instance, leaderIP) + return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP) } } @@ -1080,11 +1080,11 @@ func (r *PostgresReconciler) checkAndUpdatePatroniReplicationConfig(log logr.Log } if resp.StandbyCluster.ApplicationName != instance.ObjectMeta.Name { log.V(debugLogLevel).Info("application_name mismatch, updating", "response", resp) - return allDone, r.httpPatchPatroni(log, ctx, instance, leaderIP) + return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP) } if resp.SynchronousNodesAdditional != nil { log.V(debugLogLevel).Info("synchronous_nodes_additional mistmatch, updating", "response", resp) - return allDone, r.httpPatchPatroni(log, ctx, instance, leaderIP) + return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP) } if resp.StandbyCluster.CreateReplicaMethods == nil { log.V(debugLogLevel).Info("create_replica_methods mismatch, updating", "response", resp) From 59c5021002bfbccc44b7bf2186de56143d86db57 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Fri, 12 Jul 2024 16:01:02 +0200 Subject: [PATCH 02/13] Logging --- controllers/postgres_controller.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/controllers/postgres_controller.go b/controllers/postgres_controller.go index 316c580b..2bd2e5f6 100644 --- a/controllers/postgres_controller.go +++ b/controllers/postgres_controller.go @@ -1063,12 +1063,12 @@ func (r *PostgresReconciler) checkAndUpdatePatroniReplicationConfig(log logr.Log } if instance.Spec.PostgresConnection.SynchronousReplication { if resp.SynchronousNodesAdditional == nil || *resp.SynchronousNodesAdditional != instance.Spec.PostgresConnection.ConnectedPostgresID { - log.V(debugLogLevel).Info("synchronous_nodes_additional mistmatch, updating", "response", resp) + log.V(debugLogLevel).Info("synchronous_nodes_additional mistmatch, updating and requeing", "response", resp) return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP) } } else { if resp.SynchronousNodesAdditional != nil { - log.V(debugLogLevel).Info("synchronous_nodes_additional mistmatch, updating", "response", resp) + log.V(debugLogLevel).Info("synchronous_nodes_additional mistmatch, updating and requeing", "response", resp) return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP) } } @@ -1079,23 +1079,23 @@ func (r *PostgresReconciler) checkAndUpdatePatroniReplicationConfig(log logr.Log return requeueAfterReconcile, nil } if resp.StandbyCluster.ApplicationName != instance.ObjectMeta.Name { - log.V(debugLogLevel).Info("application_name mismatch, updating", "response", resp) + log.V(debugLogLevel).Info("application_name mismatch, updating and requeing", "response", resp) return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP) } if resp.SynchronousNodesAdditional != nil { - log.V(debugLogLevel).Info("synchronous_nodes_additional mistmatch, updating", "response", resp) + log.V(debugLogLevel).Info("synchronous_nodes_additional mistmatch, updating and requeing", "response", resp) return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP) } if resp.StandbyCluster.CreateReplicaMethods == nil { - log.V(debugLogLevel).Info("create_replica_methods mismatch, updating", "response", resp) + log.V(debugLogLevel).Info("create_replica_methods mismatch, updating and requeing", "response", resp) return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP) } if resp.StandbyCluster.Host != instance.Spec.PostgresConnection.ConnectionIP { - log.V(debugLogLevel).Info("host mismatch, requeing", "updating", resp) + log.V(debugLogLevel).Info("host mismatch, updating and requeing", "updating", resp) return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP) } if resp.StandbyCluster.Port != int(instance.Spec.PostgresConnection.ConnectionPort) { - log.V(debugLogLevel).Info("port mismatch, requeing", "updating", resp) + log.V(debugLogLevel).Info("port mismatch, updating and requeing", "updating", resp) return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP) } } From f1ca8db3c8e1b68c4cd664be9ea9ad0be3b2f03b Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Fri, 12 Jul 2024 16:37:52 +0200 Subject: [PATCH 03/13] Especially double check when bootstrapping --- controllers/postgres_controller.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/controllers/postgres_controller.go b/controllers/postgres_controller.go index 2bd2e5f6..cf0b7e06 100644 --- a/controllers/postgres_controller.go +++ b/controllers/postgres_controller.go @@ -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 @@ -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 @@ -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, } From 4ecb5f5d85da9e4290e1239cac404e74fbb5739d Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Fri, 12 Jul 2024 16:44:39 +0200 Subject: [PATCH 04/13] Check for new value --- controllers/postgres_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/postgres_controller.go b/controllers/postgres_controller.go index cf0b7e06..a4cc92a4 100644 --- a/controllers/postgres_controller.go +++ b/controllers/postgres_controller.go @@ -1078,7 +1078,7 @@ func (r *PostgresReconciler) checkAndUpdatePatroniReplicationConfig(log logr.Log log.V(debugLogLevel).Info("standby_cluster mismatch, requeing", "response", resp) return requeueAfterReconcile, nil } - if resp.StandbyCluster.ApplicationName != instance.ObjectMeta.Name { + if resp.StandbyCluster.ApplicationName != instance.ToPeripheralResourceName() { log.V(debugLogLevel).Info("application_name mismatch, updating and requeing", "response", resp) return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP) } From 054ba6986458f4f4cbf90091569b5aac48849f4f Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Fri, 12 Jul 2024 17:05:30 +0200 Subject: [PATCH 05/13] Revert "Especially double check when bootstrapping" This reverts commit f1ca8db3c8e1b68c4cd664be9ea9ad0be3b2f03b. --- controllers/postgres_controller.go | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/controllers/postgres_controller.go b/controllers/postgres_controller.go index a4cc92a4..b7b0bdc5 100644 --- a/controllers/postgres_controller.go +++ b/controllers/postgres_controller.go @@ -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 requeueAfterReconcile, r.updatePatroniReplicationConfigOnAllPods(log, ctx, instance) + return allDone, r.updatePatroniReplicationConfigOnAllPods(log, ctx, instance) } leaderIP := leaderPods.Items[0].Status.PodIP @@ -1170,24 +1170,8 @@ func (r *PostgresReconciler) httpPatchPatroni(log logr.Logger, ctx context.Conte StandbyCluster: nil, } if instance.Spec.PostgresConnection.SynchronousReplication { - // 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()) - } + // enable sync replication + request.SynchronousNodesAdditional = pointer.String(instance.Spec.PostgresConnection.ConnectedPostgresID) } else { // disable sync replication request.SynchronousNodesAdditional = nil @@ -1199,7 +1183,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.ToPeripheralResourceName(), + ApplicationName: instance.ObjectMeta.Name, }, SynchronousNodesAdditional: nil, } From 5d3ca5470531b8f50975713f4d5b4883d3dd9d80 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Fri, 12 Jul 2024 17:06:33 +0200 Subject: [PATCH 06/13] Especially double check when bootstrapping --- controllers/postgres_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/postgres_controller.go b/controllers/postgres_controller.go index b7b0bdc5..b93ee53d 100644 --- a/controllers/postgres_controller.go +++ b/controllers/postgres_controller.go @@ -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 From 7b86f4c04bb7b06cc96ac520f3204d97aad4f7ff Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Fri, 12 Jul 2024 17:13:31 +0200 Subject: [PATCH 07/13] Revert "Check for new value" This reverts commit 4ecb5f5d85da9e4290e1239cac404e74fbb5739d. --- controllers/postgres_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/postgres_controller.go b/controllers/postgres_controller.go index b93ee53d..5f3e1864 100644 --- a/controllers/postgres_controller.go +++ b/controllers/postgres_controller.go @@ -1078,7 +1078,7 @@ func (r *PostgresReconciler) checkAndUpdatePatroniReplicationConfig(log logr.Log log.V(debugLogLevel).Info("standby_cluster mismatch, requeing", "response", resp) return requeueAfterReconcile, nil } - if resp.StandbyCluster.ApplicationName != instance.ToPeripheralResourceName() { + if resp.StandbyCluster.ApplicationName != instance.ObjectMeta.Name { log.V(debugLogLevel).Info("application_name mismatch, updating and requeing", "response", resp) return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP) } From fd7945795a637dab1f0597a88fabe02503c35039 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Wed, 17 Jul 2024 16:07:10 +0200 Subject: [PATCH 08/13] Fetch and use the actual postgres cluster name as application_name for. This resolves some issues when using sync replication. --- controllers/postgres_controller.go | 58 ++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/controllers/postgres_controller.go b/controllers/postgres_controller.go index 5f3e1864..6c355e16 100644 --- a/controllers/postgres_controller.go +++ b/controllers/postgres_controller.go @@ -1062,14 +1062,31 @@ func (r *PostgresReconciler) checkAndUpdatePatroniReplicationConfig(log logr.Log return requeueAfterReconcile, nil } if instance.Spec.PostgresConnection.SynchronousReplication { - if resp.SynchronousNodesAdditional == nil || *resp.SynchronousNodesAdditional != instance.Spec.PostgresConnection.ConnectedPostgresID { + if resp.SynchronousNodesAdditional == nil { log.V(debugLogLevel).Info("synchronous_nodes_additional mistmatch, updating and requeing", "response", resp) - return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP) + return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP, nil) + } + // fetch the sync standby to determine the correct application_name of the instance + var synchronousStandbyApplicationName *string = nil + s := &pg.Postgres{} + ns := types.NamespacedName{ + Name: instance.Spec.PostgresConnection.ConnectedPostgresID, + Namespace: instance.Namespace, + } + if err := r.CtrlClient.Get(ctx, ns, s); err != nil { + r.recorder.Eventf(s, "Warning", "Error", "failed to get referenced sync standby: %v", err) + synchronousStandbyApplicationName = nil + } else { + synchronousStandbyApplicationName = pointer.String(s.ToPeripheralResourceName()) + } + if *resp.SynchronousNodesAdditional != *synchronousStandbyApplicationName { + log.V(debugLogLevel).Info("synchronous_nodes_additional mistmatch, updating and requeing", "response", resp) + return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP, synchronousStandbyApplicationName) } } else { if resp.SynchronousNodesAdditional != nil { log.V(debugLogLevel).Info("synchronous_nodes_additional mistmatch, updating and requeing", "response", resp) - return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP) + return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP, nil) } } @@ -1078,25 +1095,25 @@ func (r *PostgresReconciler) checkAndUpdatePatroniReplicationConfig(log logr.Log log.V(debugLogLevel).Info("standby_cluster mismatch, requeing", "response", resp) return requeueAfterReconcile, nil } - if resp.StandbyCluster.ApplicationName != instance.ObjectMeta.Name { - log.V(debugLogLevel).Info("application_name mismatch, updating and requeing", "response", resp) - return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP) - } - if resp.SynchronousNodesAdditional != nil { - log.V(debugLogLevel).Info("synchronous_nodes_additional mistmatch, updating and requeing", "response", resp) - return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP) - } if resp.StandbyCluster.CreateReplicaMethods == nil { log.V(debugLogLevel).Info("create_replica_methods mismatch, updating and requeing", "response", resp) - return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP) + return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP, nil) } if resp.StandbyCluster.Host != instance.Spec.PostgresConnection.ConnectionIP { log.V(debugLogLevel).Info("host mismatch, updating and requeing", "updating", resp) - return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP) + return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP, nil) } if resp.StandbyCluster.Port != int(instance.Spec.PostgresConnection.ConnectionPort) { log.V(debugLogLevel).Info("port mismatch, updating and requeing", "updating", resp) - return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP) + return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP, nil) + } + if resp.StandbyCluster.ApplicationName != instance.ToPeripheralResourceName() { + log.V(debugLogLevel).Info("application_name mismatch, updating and requeing", "response", resp) + return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP, nil) + } + if resp.SynchronousNodesAdditional != nil { + log.V(debugLogLevel).Info("synchronous_nodes_additional mistmatch, updating and requeing", "response", resp) + return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP, nil) } } @@ -1142,7 +1159,7 @@ func (r *PostgresReconciler) updatePatroniReplicationConfigOnAllPods(log logr.Lo for _, pod := range pods.Items { pod := pod // pin! podIP := pod.Status.PodIP - if err := r.httpPatchPatroni(log, ctx, instance, podIP); err != nil { + if err := r.httpPatchPatroni(log, ctx, instance, podIP, nil); err != nil { lastErr = err log.Info("failed to update pod") } @@ -1155,7 +1172,7 @@ func (r *PostgresReconciler) updatePatroniReplicationConfigOnAllPods(log logr.Lo return nil } -func (r *PostgresReconciler) httpPatchPatroni(log logr.Logger, ctx context.Context, instance *pg.Postgres, podIP string) error { +func (r *PostgresReconciler) httpPatchPatroni(log logr.Logger, ctx context.Context, instance *pg.Postgres, podIP string, synchronousStandbyApplicationName *string) error { if podIP == "" { return errors.New("podIP must not be empty") } @@ -1171,7 +1188,7 @@ func (r *PostgresReconciler) httpPatchPatroni(log logr.Logger, ctx context.Conte } if instance.Spec.PostgresConnection.SynchronousReplication { // enable sync replication - request.SynchronousNodesAdditional = pointer.String(instance.Spec.PostgresConnection.ConnectedPostgresID) + request.SynchronousNodesAdditional = synchronousStandbyApplicationName } else { // disable sync replication request.SynchronousNodesAdditional = nil @@ -1183,7 +1200,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, } @@ -1212,6 +1229,11 @@ func (r *PostgresReconciler) httpPatchPatroni(log logr.Logger, ctx context.Conte } defer resp.Body.Close() + // fake error when standbyApplicationName is required but not provided + if instance.IsReplicationPrimary() && instance.Spec.PostgresConnection.SynchronousReplication && synchronousStandbyApplicationName == nil { + return fmt.Errorf("missing application_name of synchronous standby, disable synchronous replication") + } + return nil } From 2c215f11c3f4b7d8517c27aa0d8763a026702fe8 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Tue, 23 Jul 2024 08:59:25 +0200 Subject: [PATCH 09/13] Always fetch application_name when needed --- controllers/postgres_controller.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/controllers/postgres_controller.go b/controllers/postgres_controller.go index 6c355e16..7c69128a 100644 --- a/controllers/postgres_controller.go +++ b/controllers/postgres_controller.go @@ -1187,6 +1187,21 @@ func (r *PostgresReconciler) httpPatchPatroni(log logr.Logger, ctx context.Conte StandbyCluster: nil, } if instance.Spec.PostgresConnection.SynchronousReplication { + if synchronousStandbyApplicationName == nil { + // fetch the sync standby to determine the correct application_name of the instance + log.V(debugLogLevel).Info("fetching referenced sync standby") + s := &pg.Postgres{} + ns := types.NamespacedName{ + Name: instance.Spec.PostgresConnection.ConnectedPostgresID, + Namespace: instance.Namespace, + } + if err := r.CtrlClient.Get(ctx, ns, s); err != nil { + r.recorder.Eventf(s, "Warning", "Error", "failed to get referenced sync standby: %v", err) + synchronousStandbyApplicationName = nil + } else { + synchronousStandbyApplicationName = pointer.String(s.ToPeripheralResourceName()) + } + } // enable sync replication request.SynchronousNodesAdditional = synchronousStandbyApplicationName } else { From 194b466f02c15506a0fe2d738bd5dcff373072c0 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Tue, 23 Jul 2024 09:06:25 +0200 Subject: [PATCH 10/13] make linter happy --- controllers/postgres_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/postgres_controller.go b/controllers/postgres_controller.go index 7c69128a..550a0088 100644 --- a/controllers/postgres_controller.go +++ b/controllers/postgres_controller.go @@ -1067,7 +1067,7 @@ func (r *PostgresReconciler) checkAndUpdatePatroniReplicationConfig(log logr.Log return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP, nil) } // fetch the sync standby to determine the correct application_name of the instance - var synchronousStandbyApplicationName *string = nil + var synchronousStandbyApplicationName *string s := &pg.Postgres{} ns := types.NamespacedName{ Name: instance.Spec.PostgresConnection.ConnectedPostgresID, From 8b76805cb7fbcb548ca19572e0a3d5dc130c2644 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Tue, 23 Jul 2024 09:31:32 +0200 Subject: [PATCH 11/13] Simplify --- controllers/postgres_controller.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/controllers/postgres_controller.go b/controllers/postgres_controller.go index 550a0088..6cdfb311 100644 --- a/controllers/postgres_controller.go +++ b/controllers/postgres_controller.go @@ -1062,10 +1062,6 @@ func (r *PostgresReconciler) checkAndUpdatePatroniReplicationConfig(log logr.Log return requeueAfterReconcile, nil } if instance.Spec.PostgresConnection.SynchronousReplication { - if resp.SynchronousNodesAdditional == nil { - log.V(debugLogLevel).Info("synchronous_nodes_additional mistmatch, updating and requeing", "response", resp) - return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP, nil) - } // fetch the sync standby to determine the correct application_name of the instance var synchronousStandbyApplicationName *string s := &pg.Postgres{} @@ -1079,7 +1075,7 @@ func (r *PostgresReconciler) checkAndUpdatePatroniReplicationConfig(log logr.Log } else { synchronousStandbyApplicationName = pointer.String(s.ToPeripheralResourceName()) } - if *resp.SynchronousNodesAdditional != *synchronousStandbyApplicationName { + if resp.SynchronousNodesAdditional == nil || *resp.SynchronousNodesAdditional != *synchronousStandbyApplicationName { log.V(debugLogLevel).Info("synchronous_nodes_additional mistmatch, updating and requeing", "response", resp) return requeueAfterReconcile, r.httpPatchPatroni(log, ctx, instance, leaderIP, synchronousStandbyApplicationName) } From d9920c1db3e93a71683982369b6476ab86b274b1 Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Tue, 23 Jul 2024 09:33:14 +0200 Subject: [PATCH 12/13] logging --- controllers/postgres_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/postgres_controller.go b/controllers/postgres_controller.go index 6cdfb311..e366903b 100644 --- a/controllers/postgres_controller.go +++ b/controllers/postgres_controller.go @@ -1185,7 +1185,7 @@ func (r *PostgresReconciler) httpPatchPatroni(log logr.Logger, ctx context.Conte if instance.Spec.PostgresConnection.SynchronousReplication { if synchronousStandbyApplicationName == nil { // fetch the sync standby to determine the correct application_name of the instance - log.V(debugLogLevel).Info("fetching referenced sync standby") + log.V(debugLogLevel).Info("unexpectetly having to fetch the referenced sync standby") s := &pg.Postgres{} ns := types.NamespacedName{ Name: instance.Spec.PostgresConnection.ConnectedPostgresID, From d41deee8ef8bd46ae91b7bb61ace37e314b9a76d Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Tue, 23 Jul 2024 15:19:09 +0200 Subject: [PATCH 13/13] Break it for testing --- controllers/postgres_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/postgres_controller.go b/controllers/postgres_controller.go index e366903b..6c9cb51b 100644 --- a/controllers/postgres_controller.go +++ b/controllers/postgres_controller.go @@ -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 requeueAfterReconcile, r.updatePatroniReplicationConfigOnAllPods(log, ctx, instance) + return allDone, r.updatePatroniReplicationConfigOnAllPods(log, ctx, instance) } leaderIP := leaderPods.Items[0].Status.PodIP