Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: yaroslavborbat <[email protected]>
  • Loading branch information
yaroslavborbat committed Sep 25, 2024
1 parent 7f291ea commit e7ba18e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions api/core/v1alpha2/vmopcondition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ const (
// ReasonStopInProgress is a ReasonCompleted indicating that the stop signal has been sent and stop is in progress.
ReasonStopInProgress ReasonCompleted = "StopInProgress"

// ReasonMigrateInProgress is a ReasonCompleted indicating that the migrate signal has been sent and stop is in progress.
ReasonMigrateInProgress ReasonCompleted = "MigrateInProgress"
// ReasonMigrationInProgress is a ReasonCompleted indicating that the migrate signal has been sent and stop is in progress.
ReasonMigrationInProgress ReasonCompleted = "MigrationInProgress"

// ReasonOperationFailed is a ReasonCompleted indicating that operation has failed.
ReasonOperationFailed ReasonCompleted = "OperationFailed"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (s VMOperationService) InProgressReasonForType(vmop *virtv2.VirtualMachineO
case virtv2.VMOPTypeRestart:
return vmopcondition.ReasonRestartInProgress
case virtv2.VMOPTypeMigrate:
return vmopcondition.ReasonMigrateInProgress
return vmopcondition.ReasonMigrationInProgress
}
return vmopcondition.ReasonCompletedUnknown
}
Expand All @@ -207,28 +207,30 @@ func (s VMOperationService) IsComplete(ctx context.Context, vmop *virtv2.Virtual
return false, err
}

return vmPhase == virtv2.MachineRunning &&
s.afterSignalSent(kvvmi.GetCreationTimestamp().Time, vmop), nil
return kvvmi != nil && vmPhase == virtv2.MachineRunning &&
s.isAfterSignalSentOrCreation(kvvmi.GetCreationTimestamp().Time, vmop), nil
case virtv2.VMOPTypeMigrate:
kvvmi, err := s.getKVVMI(ctx, vmop.GetNamespace(), vmop.Spec.VirtualMachine)
if err != nil {
return false, err
}

if s.afterSignalSent(kvvmi.GetCreationTimestamp().Time, vmop) {
if kvvmi == nil {
return false, nil
}
if s.isAfterSignalSentOrCreation(kvvmi.GetCreationTimestamp().Time, vmop) {
return true, nil
}
migrationState := kvvmi.Status.MigrationState
return migrationState != nil &&
migrationState.EndTimestamp != nil &&
s.afterSignalSent(migrationState.EndTimestamp.Time, vmop), nil
s.isAfterSignalSentOrCreation(migrationState.EndTimestamp.Time, vmop), nil

default:
return false, nil
}
}

func (s VMOperationService) afterSignalSent(timestamp time.Time, vmop *virtv2.VirtualMachineOperation) bool {
func (s VMOperationService) isAfterSignalSentOrCreation(timestamp time.Time, vmop *virtv2.VirtualMachineOperation) bool {
// Use vmop creation time or time from SignalSent condition.
signalSentTime := vmop.GetCreationTimestamp().Time
signalSendCond, found := GetCondition(vmopcondition.SignalSentType.String(), vmop.Status.Conditions)
Expand Down

0 comments on commit e7ba18e

Please sign in to comment.