Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions internal/controller/postgrescluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,18 @@ func (r *PostgresClusterReconciler) Reconcile(ctx context.Context, req ctrl.Requ
_ = r.persistStatusIfChanged(ctx, postgresCluster, persistedStatus)
return ctrl.Result{}, createPoolerErr
}
if !r.arePoolersReady(ctx, postgresCluster) {

rwPooler := &cnpgv1.Pooler{}
rwErr := r.Get(ctx, types.NamespacedName{
Name: poolerResourceName(postgresCluster.Name, readWriteEndpoint),
Namespace: postgresCluster.Namespace,
}, rwPooler)
roPooler := &cnpgv1.Pooler{}
roErr := r.Get(ctx, types.NamespacedName{
Name: poolerResourceName(postgresCluster.Name, readOnlyEndpoint),
Namespace: postgresCluster.Namespace,
}, roPooler)
if rwErr != nil || roErr != nil || !r.arePoolersReady(rwPooler, roPooler) {
logger.Info("Connection poolers are not ready yet, requeueing")
updateStatus(
poolerReady,
Expand Down Expand Up @@ -984,10 +995,7 @@ func (r *PostgresClusterReconciler) syncPoolerStatus(ctx context.Context, postgr

// isPoolerReady checks if a pooler has all instances scheduled.
// Note: CNPG PoolerStatus only tracks scheduled instances, not ready pods.
func (r *PostgresClusterReconciler) isPoolerReady(pooler *cnpgv1.Pooler, err error) bool {
if err != nil {
return false
}
func (r *PostgresClusterReconciler) isPoolerReady(pooler *cnpgv1.Pooler) bool {
desiredInstances := int32(1)
if pooler.Spec.Instances != nil {
desiredInstances = *pooler.Spec.Instances
Expand All @@ -1005,20 +1013,8 @@ func (r *PostgresClusterReconciler) getPoolerInstanceCount(pooler *cnpgv1.Pooler
}

// arePoolersReady checks if both RW and RO poolers have all instances scheduled.
func (r *PostgresClusterReconciler) arePoolersReady(ctx context.Context, postgresCluster *enterprisev4.PostgresCluster) bool {
rwPooler := &cnpgv1.Pooler{}
rwErr := r.Get(ctx, types.NamespacedName{
Name: poolerResourceName(postgresCluster.Name, readWriteEndpoint),
Namespace: postgresCluster.Namespace,
}, rwPooler)

roPooler := &cnpgv1.Pooler{}
roErr := r.Get(ctx, types.NamespacedName{
Name: poolerResourceName(postgresCluster.Name, readOnlyEndpoint),
Namespace: postgresCluster.Namespace,
}, roPooler)

return r.isPoolerReady(rwPooler, rwErr) && r.isPoolerReady(roPooler, roErr)
func (r *PostgresClusterReconciler) arePoolersReady(rwPooler, roPooler *cnpgv1.Pooler) bool {
return r.isPoolerReady(rwPooler) && r.isPoolerReady(roPooler)
}

// normalizeManagedRole projects a CNPG RoleConfiguration down to only the fields this controller controls.
Expand Down Expand Up @@ -1494,6 +1490,7 @@ func cnpgPoolerPredicator() predicate.Predicate {
},
}
}

// secretPredicator filters Secret events to trigger reconciles on creation, deletion, or owner reference changes.
func secretPredicator() predicate.Predicate {
return predicate.Funcs{
Expand Down
Loading
Loading