Skip to content

Commit

Permalink
PTEUDO-1422: fix new db status
Browse files Browse the repository at this point in the history
  • Loading branch information
bfabricio committed Dec 16, 2024
1 parent b0ab674 commit 76cf740
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
8 changes: 4 additions & 4 deletions api/v1/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func ProvisioningCondition() metav1.Condition {
ConditionSync,
metav1.ConditionFalse,
ReasonProvisioning,
"Database provisioning is in progress.",
"Database provisioning is in progress",
)
}

Expand All @@ -64,7 +64,7 @@ func DeletingCondition() metav1.Condition {
ConditionSync,
metav1.ConditionFalse,
ReasonDeleting,
"Database deletion is in progress.",
"Database deletion is in progress",
)
}

Expand All @@ -73,7 +73,7 @@ func MigratingCondition() metav1.Condition {
ConditionSync,
metav1.ConditionFalse,
ReasonMigrating,
"Database migration is underway.",
"Database migration is underway",
)
}

Expand Down Expand Up @@ -109,6 +109,6 @@ func ReconcileSuccessCondition() metav1.Condition {
ConditionReady,
metav1.ConditionTrue,
ReasonAvailable,
"Database successfully synchronized and ready for use.",
"Database successfully synchronized and ready for use",
)
}
20 changes: 17 additions & 3 deletions pkg/databaseclaim/claimstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ func (m *StatusManager) SetError(ctx context.Context, dbClaim *v1.DatabaseClaim,
}
logr := log.FromContext(ctx).WithValues("databaseclaim", nname)

m.SetStatusCondition(ctx, dbClaim, v1.ReconcileErrorCondition(inErr))
err := m.SetConditionAndUpdateStatus(ctx, dbClaim, v1.ReconcileErrorCondition(inErr))
if err != nil {
return ctrl.Result{}, err
}

var wrappedErr *managedErr
if existingErr, isManaged := inErr.(*managedErr); isManaged {
logr.Error(existingErr, "manageError called multiple times for the same error")
Expand All @@ -73,7 +77,7 @@ func (m *StatusManager) SetError(ctx context.Context, dbClaim *v1.DatabaseClaim,
}

refreshedClaim.Status.Error = wrappedErr.Error()
if err := m.UpdateStatus(ctx, dbClaim); err != nil {
if err := m.UpdateStatus(ctx, refreshedClaim); err != nil {
logr.Error(err, "Failed to update DatabaseClaim status")
return ctrl.Result{}, wrappedErr
}
Expand Down Expand Up @@ -133,7 +137,7 @@ func (m *StatusManager) SetStatusCondition(ctx context.Context, dbClaim *v1.Data
if condition.Status == cond.Status && !condition.LastTransitionTime.IsZero() {
condition.LastTransitionTime = cond.LastTransitionTime
} else {
logf.V(1).Info("Condition status changed %s -> %s", string(cond.Status), string(condition.Status))
logf.V(1).Info(fmt.Sprintf("Condition status changed %s -> %s", cond.Status, condition.Status))
}
dbClaim.Status.Conditions[idx] = condition
return
Expand All @@ -143,6 +147,16 @@ func (m *StatusManager) SetStatusCondition(ctx context.Context, dbClaim *v1.Data
dbClaim.Status.Conditions = append(dbClaim.Status.Conditions, condition)
}

func (m *StatusManager) SetConditionAndUpdateStatus(ctx context.Context, dbClaim *v1.DatabaseClaim, condition metav1.Condition) error {
m.SetStatusCondition(ctx, dbClaim, condition)

if err := m.UpdateStatus(ctx, dbClaim); err != nil {
return err
}

return nil
}

func (m *StatusManager) UpdateClusterStatus(status *v1.Status, hostParams *hostparams.HostParams) {
status.DBVersion = hostParams.DBVersion
status.Type = v1.DatabaseType(hostParams.Type)
Expand Down
10 changes: 8 additions & 2 deletions pkg/databaseclaim/databaseclaim.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ func (r *DatabaseClaimReconciler) Reconcile(ctx context.Context, req ctrl.Reques
// The object is being deleted
if controllerutil.ContainsFinalizer(&dbClaim, dbFinalizerName) {
logr.Info("clean_up_finalizer")
r.statusManager.SetStatusCondition(ctx, &dbClaim, v1.DeletingCondition())
err_ := r.statusManager.SetConditionAndUpdateStatus(ctx, &dbClaim, v1.DeletingCondition())
if err_ != nil {
return ctrl.Result{}, err_
}
// check if the claim is in the middle of rds migration, if so, wait for it to complete
if dbClaim.Status.MigrationState != "" && dbClaim.Status.MigrationState != pgctl.S_Completed.String() {
logr.Info("migration is in progress. object cannot be deleted")
Expand Down Expand Up @@ -500,7 +503,10 @@ func (r *DatabaseClaimReconciler) reconcileNewDB(ctx context.Context, reqInfo *r
logr := log.FromContext(ctx).WithValues("databaseclaim", dbClaim.Namespace+"/"+dbClaim.Name, "func", "reconcileNewDB")
logr.Info("reconcileNewDB", "r.Input", reqInfo)

r.statusManager.SetStatusCondition(ctx, dbClaim, v1.ProvisioningCondition())
err_ := r.statusManager.SetConditionAndUpdateStatus(ctx, dbClaim, v1.ProvisioningCondition())
if err_ != nil {
return ctrl.Result{}, err_
}

cloud := basefun.GetCloud(r.Config.Viper)

Expand Down

0 comments on commit 76cf740

Please sign in to comment.