Skip to content

Commit

Permalink
dev: introduce Aborted CHI status
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsingerus committed Nov 29, 2023
1 parent dd5bd9b commit 8535771
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions pkg/apis/clickhouse.altinity.com/v1/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package v1
const (
StatusInProgress = "InProgress"
StatusCompleted = "Completed"
StatusAborted = "Aborted"
StatusTerminating = "Terminating"
)

Expand Down
12 changes: 12 additions & 0 deletions pkg/apis/clickhouse.altinity.com/v1/type_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,18 @@ func (s *ChiStatus) ReconcileComplete() {
})
}

// ReconcileAbort marks reconcile abortion
func (s *ChiStatus) ReconcileAbort() {
doWithWriteLock(s, func(s *ChiStatus) {
if s == nil {
return
}
s.Status = StatusAborted
s.Action = ""
pushTaskIDCompletedNoSync(s)
})
}

// DeleteStart marks deletion start
func (s *ChiStatus) DeleteStart() {
doWithWriteLock(s, func(s *ChiStatus) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/chi/worker-chi-reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (w *worker) reconcileCHI(ctx context.Context, old, new *chiV1.ClickHouseIns
WithStatusError(new).
M(new).F().
Error("FAILED to reconcile CHI err: %v", err)
w.markReconcileCompletedUnsuccessfully(ctx, new)
w.markReconcileCompletedUnsuccessfully(ctx, new, err)
} else {
// Post-process added items
if util.IsContextDone(ctx) {
Expand Down
10 changes: 8 additions & 2 deletions pkg/controller/chi/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package chi

import (
"context"
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -692,13 +693,18 @@ func (w *worker) finalizeReconcileAndMarkCompleted(ctx context.Context, _chi *ch
Info("reconcile completed successfully, task id: %s", _chi.Spec.GetTaskID())
}

func (w *worker) markReconcileCompletedUnsuccessfully(ctx context.Context, chi *chiV1.ClickHouseInstallation) {
func (w *worker) markReconcileCompletedUnsuccessfully(ctx context.Context, chi *chiV1.ClickHouseInstallation, err error) {
if util.IsContextDone(ctx) {
log.V(2).Info("task is done")
return
}

chi.EnsureStatus().ReconcileComplete()
switch {
case err == nil:
chi.EnsureStatus().ReconcileComplete()
case errors.Is(err, errCRUDAbort):
chi.EnsureStatus().ReconcileAbort()
}
w.c.updateCHIObjectStatus(ctx, chi, UpdateCHIStatusOptions{
CopyCHIStatusOptions: chiV1.CopyCHIStatusOptions{
MainFields: true,
Expand Down

0 comments on commit 8535771

Please sign in to comment.