Skip to content

Commit

Permalink
chore: collect the log of the backup failed (#8208)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyelei committed Sep 26, 2024
1 parent f2fbe45 commit 7c93f30
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions controllers/dataprotection/log_collection_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/predicate"

dpv1alpha1 "github.com/apecloud/kubeblocks/apis/dataprotection/v1alpha1"
"github.com/apecloud/kubeblocks/pkg/constant"
intctrlutil "github.com/apecloud/kubeblocks/pkg/controllerutil"
dprestore "github.com/apecloud/kubeblocks/pkg/dataprotection/restore"
dptypes "github.com/apecloud/kubeblocks/pkg/dataprotection/types"
Expand Down Expand Up @@ -171,18 +172,28 @@ func (r *LogCollectionReconciler) patchBackupStatus(reqCtx intctrlutil.RequestCt
if err := r.Client.Get(reqCtx.Ctx, client.ObjectKey{Name: backupName, Namespace: reqCtx.Req.Namespace}, backup); err != nil {
return err
}
if backup.Status.FailureReason != "" {
return nil
}
errorLogs, err := r.collectErrorLogs(reqCtx, job)
if err != nil {
return fmt.Errorf("collect error logs failed: %s", err.Error())
}
if errorLogs == "" {
return nil
for i := range backup.Status.Actions {
action := &backup.Status.Actions[i]
if action.ObjectRef == nil {
continue
}
if action.ObjectRef.Kind != constant.JobKind || action.ObjectRef.Name != job.Name {
continue
}
if strings.HasPrefix(action.FailureReason, dptypes.LogCollectorOutput) {
return nil
}
errorLogs, err := r.collectErrorLogs(reqCtx, job)
if err != nil {
return fmt.Errorf("collect error logs failed: %s", err.Error())
}
if errorLogs == "" {
return nil
}
action.FailureReason = fmt.Sprintf("%s: %s", dptypes.LogCollectorOutput, errorLogs)
return r.Client.Status().Update(reqCtx.Ctx, backup)
}
backup.Status.FailureReason = errorLogs
return r.Client.Status().Update(reqCtx.Ctx, backup)
return nil
}

func (r *LogCollectionReconciler) patchRestoreStatus(reqCtx intctrlutil.RequestCtx, job *batchv1.Job, restoreName string) error {
Expand Down

0 comments on commit 7c93f30

Please sign in to comment.