Skip to content

Commit

Permalink
feat: have pre-req retry upon check fail
Browse files Browse the repository at this point in the history
Signed-off-by: Humair Khan <HumairAK@users.noreply.github.com>
  • Loading branch information
HumairAK committed Feb 13, 2024
1 parent 0df6ce3 commit c3221fc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion config/base/params.env
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ ZAP_LOG_LEVEL=info
MAX_CONCURRENT_RECONCILES=10
DSPO_HEALTHCHECK_DATABASE_CONNECTIONTIMEOUT=15s
DSPO_HEALTHCHECK_OBJECTSTORE_CONNECTIONTIMEOUT=15s
DSPO_REQUEUE_TIME=2m
DSPO_REQUEUE_TIME=20s
2 changes: 1 addition & 1 deletion controllers/config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const DefaultObjStoreConnectionTimeout = time.Second * 15

const DefaultMaxConcurrentReconciles = 10

const DefaultRequeueTime = 2 * time.Minute
const DefaultRequeueTime = time.Second * 20

func GetConfigRequiredFields() []string {
return requiredFields
Expand Down
14 changes: 10 additions & 4 deletions controllers/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ var ConnectAndQueryDatabase = func(host, port, username, password, dbname string

testStatement := "SELECT 1;"
_, err = db.QueryContext(ctx, testStatement)
return err == nil, nil
if err != nil {
return false, err
}
return true, nil
}

func (r *DSPAReconciler) isDatabaseAccessible(ctx context.Context, dsp *dspav1alpha1.DataSciencePipelinesApplication,
Expand All @@ -80,7 +83,7 @@ func (r *DSPAReconciler) isDatabaseAccessible(ctx context.Context, dsp *dspav1al
decodePass, _ := b64.StdEncoding.DecodeString(params.DBConnection.Password)
dbConnectionTimeout := config.GetDurationConfigWithDefault(config.DBConnectionTimeoutConfigName, config.DefaultDBConnectionTimeout)

log.V(1).Info(fmt.Sprintf("Database Heath Check connection timeout: %s", dbConnectionTimeout))
log.V(1).Info(fmt.Sprintf("Attempting Database Heath Check connection (with timeout: %s)", dbConnectionTimeout))

dbHealthCheckPassed, err := ConnectAndQueryDatabase(params.DBConnection.Host,
params.DBConnection.Port,
Expand All @@ -90,8 +93,11 @@ func (r *DSPAReconciler) isDatabaseAccessible(ctx context.Context, dsp *dspav1al
dbConnectionTimeout)

if err != nil {
log.Info("Unable to connect to Database")
} else {
log.Info(fmt.Sprintf("Unable to connect to Database: %v", err))
return false, err
}

if dbHealthCheckPassed {
log.Info("Database Health Check Successful")
}

Expand Down
3 changes: 3 additions & 0 deletions controllers/dspipeline_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ func (r *DSPAReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
if err != nil {
return ctrl.Result{}, err
}
} else {
log.Info(fmt.Sprintf("Health check for Database or Object Store failed, retrying in %d seconds.", int(requeueTime.Seconds())))
return ctrl.Result{Requeue: true, RequeueAfter: requeueTime}, nil
}

log.Info("Updating CR status")
Expand Down

0 comments on commit c3221fc

Please sign in to comment.