Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Xieql <xieqianglong@huawei.com>
  • Loading branch information
Xieql committed Oct 24, 2023
1 parent d75b910 commit 1ac96a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
8 changes: 4 additions & 4 deletions pkg/apis/backups/v1alpha1/migrate_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ const (
// the controller's validations and therefore will not run.
MigratePhaseFailedValidation MigratePhase = "FailedValidation"

// MigratePhaseWaitingForSource means the migrate is currently fetching source cluster resource.
MigratePhaseWaitingForSource MigratePhase = "WaitingForSource"
// MigratePhaseBackupInProgress indicates that the backup phase of the migrate is currently in progress.
MigratePhaseBackupInProgress MigratePhase = "BackupInProgress"

// MigratePhaseInProgress means the migrate is currently executing migrating.
MigratePhaseInProgress MigratePhase = "InProgress"
// MigratePhaseRestoreInProgress indicates that the restore phase of the migrate is currently in progress.
MigratePhaseRestoreInProgress MigratePhase = "RestoreInProgress"

// MigratePhaseCompleted means the migrate has run successfully
// without errors.
Expand Down
27 changes: 8 additions & 19 deletions pkg/fleet-manager/migrate_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package fleet
import (
"context"
"fmt"
"time"

"github.com/hashicorp/go-multierror"
"github.com/pkg/errors"
Expand All @@ -34,12 +33,6 @@ import (
backupapi "kurator.dev/kurator/pkg/apis/backups/v1alpha1"
)

const (
// MigrationDelay ensures the restore operation happens after the backup.
// This helps avoid potential issues due to timing synchronization.
MigrationDelay = 1 * time.Second
)

// MigrateManager reconciles a Migrate object
type MigrateManager struct {
client.Client
Expand Down Expand Up @@ -97,8 +90,8 @@ func (m *MigrateManager) reconcileMigrate(ctx context.Context, migrate *backupap
// Update the migrate phase
phase := migrate.Status.Phase
if len(phase) == 0 || phase == backupapi.MigratePhasePending {
migrate.Status.Phase = backupapi.MigratePhaseWaitingForSource
log.Info("Migrate Phase changes", "phase", backupapi.MigratePhaseWaitingForSource)
migrate.Status.Phase = backupapi.MigratePhaseBackupInProgress
log.Info("Migrate Phase changes", "phase", backupapi.MigratePhaseBackupInProgress)
}

// The actual migration operation can be divided into two stages
Expand Down Expand Up @@ -160,6 +153,9 @@ func (m *MigrateManager) reconcileMigrateBackup(ctx context.Context, migrate *ba

if veleroBackup.Status.Phase == velerov1.BackupPhaseCompleted {
conditions.MarkTrue(migrate, backupapi.SourceReadyCondition)
} else {
log.Info("Waiting for source backup to be ready", "sourceBackupName", sourceBackupName)
return ctrl.Result{RequeueAfter: RequeueAfter}, nil
}

return ctrl.Result{}, nil
Expand All @@ -169,22 +165,15 @@ func (m *MigrateManager) reconcileMigrateBackup(ctx context.Context, migrate *ba
func (m *MigrateManager) reconcileMigrateRestore(ctx context.Context, migrate *backupapi.Migrate) (ctrl.Result, error) {
log := ctrl.LoggerFrom(ctx)

// If source cluster's backup resource is not ready, return directly.
if !isMigrateSourceReady(migrate) {
return ctrl.Result{RequeueAfter: RequeueAfter}, nil
}

targetClusters, err := fetchDestinationClusters(ctx, m.Client, migrate.Namespace, migrate.Spec.TargetClusters)
if err != nil {
log.Error(err, "Failed to fetch target clusters for migration")
return ctrl.Result{}, fmt.Errorf("fetching target clusters: %w", err)
}

if migrate.Status.Phase != backupapi.MigratePhaseInProgress {
migrate.Status.Phase = backupapi.MigratePhaseInProgress
log.Info("Migrate Phase changes", "phase", backupapi.MigratePhaseInProgress)
// Ensure the restore point is created after the backup.
time.Sleep(MigrationDelay)
if migrate.Status.Phase != backupapi.MigratePhaseBackupInProgress {
migrate.Status.Phase = backupapi.MigratePhaseRestoreInProgress
log.Info("Migrate Phase changes", "phase", backupapi.MigratePhaseRestoreInProgress)
}

// referredBackupName is same in different target clusters velero restore, because the velero backup will sync to current cluster.
Expand Down

0 comments on commit 1ac96a0

Please sign in to comment.