Skip to content

Commit

Permalink
Test different execution order for primaries and standbies
Browse files Browse the repository at this point in the history
  • Loading branch information
eberlep committed Aug 31, 2022
1 parent a17cf11 commit 3f57b1c
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions controllers/postgres_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,16 @@ func (r *PostgresReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
}

// check (and update if neccessary) the current patroni replication config.
immediateRequeue, patroniErr := r.checkAndUpdatePatroniReplicationConfig(ctx, instance)
if immediateRequeue {
// if a config change was performed that requires a while to settle in, we simply requeue
// on the next reconciliation loop, the config should be correct already so we can continue with the rest
log.Info("Requeueing after patroni replication config change")
return ctrl.Result{Requeue: true, RequeueAfter: 10 * time.Second}, patroniErr
var patroniErr error
// for primary databases, do that call before updating the custom ressource
if instance.IsReplicationPrimary() {
immediateRequeue, patroniErr := r.checkAndUpdatePatroniReplicationConfig(ctx, instance)
if immediateRequeue {
// if a config change was performed that requires a while to settle in, we simply requeue
// on the next reconciliation loop, the config should be correct already so we can continue with the rest
log.Info("Requeueing after patroni replication config change")
return ctrl.Result{Requeue: true, RequeueAfter: 10 * time.Second}, patroniErr
}
}

// create standby egress rule first, so the standby can actually connect to the primary
Expand Down Expand Up @@ -284,6 +288,17 @@ func (r *PostgresReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
return ctrl.Result{}, fmt.Errorf("unable to create or update ingress ClusterwideNetworkPolicy: %w", err)
}

// for standby databases, do that call after updating the custom ressource
if !instance.IsReplicationPrimary() {
immediateRequeue, patroniErr := r.checkAndUpdatePatroniReplicationConfig(ctx, instance)
if immediateRequeue {
// if a config change was performed that requires a while to settle in, we simply requeue
// on the next reconciliation loop, the config should be correct already so we can continue with the rest
log.Info("Requeueing after patroni replication config change")
return ctrl.Result{Requeue: true, RequeueAfter: 10 * time.Second}, patroniErr
}
}

// when an error occurred while updating the patroni config, requeue here
// this is done down here to make sure the rest of the resource updates were performed
if patroniErr != nil {
Expand Down Expand Up @@ -786,6 +801,7 @@ func (r *PostgresReconciler) checkAndUpdatePatroniReplicationConfig(ctx context.
}
}

r.Log.Info("replication config from Patroni API up to date")
return continueWithReconciliation, nil
}

Expand Down

0 comments on commit 3f57b1c

Please sign in to comment.