Skip to content

Commit

Permalink
feat: Return errors in reconcile instead of requeue
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyno-zeta committed Mar 2, 2024
1 parent 6438093 commit 2876224
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 35 deletions.
19 changes: 6 additions & 13 deletions internal/controller/postgresql/postgresqldatabase_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"fmt"
"reflect"
"time"

"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -38,9 +37,8 @@ import (
)

const (
PGDBRequeueDelayErrorNumberSeconds = 5
readerPrivs = "SELECT"
writerPrivs = "SELECT,INSERT,DELETE,UPDATE"
readerPrivs = "SELECT"
writerPrivs = "SELECT,INSERT,DELETE,UPDATE"
)

// PostgresqlDatabaseReconciler reconciles a PostgresqlDatabase object.
Expand Down Expand Up @@ -679,11 +677,8 @@ func (r *PostgresqlDatabaseReconciler) manageError(
logger.Error(err, "unable to update status")
}

// Requeue
return ctrl.Result{
RequeueAfter: PGDBRequeueDelayErrorNumberSeconds * time.Second,
Requeue: true,
}, nil
// Return error
return ctrl.Result{}, issue
}

func (r *PostgresqlDatabaseReconciler) manageSuccess(
Expand All @@ -702,10 +697,8 @@ func (r *PostgresqlDatabaseReconciler) manageSuccess(
if err != nil {
logger.Error(err, "unable to update status")

return ctrl.Result{
RequeueAfter: PGDBRequeueDelayErrorNumberSeconds * time.Second,
Requeue: true,
}, nil
// Return error
return ctrl.Result{}, err
}

logger.Info("Reconcile done")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ import (
)

const (
PGECRequeueDelayErrorNumberSeconds = 5
DefaultPGPort = 5432
DefaultBouncerPort = 6432
DefaultPGPort = 5432
DefaultBouncerPort = 6432
)

// PostgresqlEngineConfigurationReconciler reconciles a PostgresqlEngineConfiguration object.
Expand Down Expand Up @@ -339,11 +338,8 @@ func (r *PostgresqlEngineConfigurationReconciler) manageError(
logger.Error(err, "unable to update status")
}

// Requeue
return ctrl.Result{
RequeueAfter: PGECRequeueDelayErrorNumberSeconds * time.Second,
Requeue: true,
}, nil
// Return error
return ctrl.Result{}, issue
}

func (r *PostgresqlEngineConfigurationReconciler) manageSuccess(
Expand All @@ -369,10 +365,8 @@ func (r *PostgresqlEngineConfigurationReconciler) manageSuccess(
if err != nil {
logger.Error(err, "unable to update status")

return ctrl.Result{
RequeueAfter: PGECRequeueDelayErrorNumberSeconds * time.Second,
Requeue: true,
}, nil
// Return error
return ctrl.Result{}, err
}

logger.Info("Reconcile done")
Expand Down
14 changes: 4 additions & 10 deletions internal/controller/postgresql/postgresqluserrole_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import (
)

const (
PGURRequeueDelayErrorNumberSeconds = 5
ListLimit = 10
Login0Suffix = "-0"
Login1Suffix = "-1"
Expand Down Expand Up @@ -1371,11 +1370,8 @@ func (r *PostgresqlUserRoleReconciler) manageError(
logger.Error(err, "unable to update status")
}

// Requeue
return reconcile.Result{
RequeueAfter: PGURRequeueDelayErrorNumberSeconds * time.Second,
Requeue: true,
}, nil
// Return error
return ctrl.Result{}, issue
}

func (r *PostgresqlUserRoleReconciler) manageSuccess(
Expand All @@ -1394,10 +1390,8 @@ func (r *PostgresqlUserRoleReconciler) manageSuccess(
if err != nil {
logger.Error(err, "unable to update status")

return reconcile.Result{
RequeueAfter: PGURRequeueDelayErrorNumberSeconds * time.Second,
Requeue: true,
}, nil
// Return error
return ctrl.Result{}, err
}

logger.Info("Reconcile done")
Expand Down

0 comments on commit 2876224

Please sign in to comment.