Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions internal/controller/storagemig/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (r *StorageMigrationReconciler) Reconcile(ctx context.Context, req ctrl.Req
migrationCopy := migration.DeepCopy()
// Apply changes to the status.
if !apiequality.Semantic.DeepEqual(migration.Status, origMigration.Status) {
log.V(1).Info("Updating VirtualMachineStorageMigration status", "phase", migration.Status.Phase)
log.V(5).Info("Updating VirtualMachineStorageMigration status", "phase", migration.Status.Phase)
if err := r.Status().Update(context.TODO(), migration); err != nil {
return reconcile.Result{}, err
}
Expand All @@ -158,13 +158,13 @@ func (r *StorageMigrationReconciler) Reconcile(ctx context.Context, req ctrl.Req
// Apply changes to the migration.
if !apiequality.Semantic.DeepEqual(migration.ObjectMeta, origMigration.ObjectMeta) {
migration.Finalizers = migrationCopy.Finalizers
log.V(1).Info("Updating VirtualMachineStorageMigration object metadata", "finalizers", migration.Finalizers)
log.V(5).Info("Updating VirtualMachineStorageMigration object metadata", "finalizers", migration.Finalizers)
if err := r.Update(context.TODO(), migration); err != nil {
return reconcile.Result{}, err
}
}

log.V(1).Info("Reconciling VirtualMachineStorageMigration completed")
log.V(5).Info("Reconciling VirtualMachineStorageMigration completed")
return ctrl.Result{RequeueAfter: requeueAfter}, nil
}

Expand All @@ -180,11 +180,11 @@ func (r *StorageMigrationReconciler) setOwnerReference(plan *migrations.VirtualM
ref.APIVersion = plan.APIVersion
ref.Name = plan.Name
ref.UID = plan.UID
r.Log.Info("Owner reference already set")
r.Log.V(5).Info("Owner reference already set")
return
}
}
r.Log.Info("Adding owner reference", "plan metadata", plan.TypeMeta)
r.Log.V(5).Info("Adding owner reference", "plan metadata", plan.TypeMeta)
migration.OwnerReferences = append(
migration.OwnerReferences,
metav1.OwnerReference{
Expand All @@ -193,7 +193,7 @@ func (r *StorageMigrationReconciler) setOwnerReference(plan *migrations.VirtualM
Name: plan.Name,
UID: plan.UID,
})
r.Log.Info("migration owner reference", "owner reference", migration.OwnerReferences)
r.Log.V(5).Info("migration owner reference", "owner reference", migration.OwnerReferences)
}

// SetupWithManager sets up the controller with the Manager.
Expand Down Expand Up @@ -230,7 +230,7 @@ func (r *StorageMigrationReconciler) SetupWithManager(mgr ctrl.Manager) error {

// Watch for changes to MigPlans
if err := c.Watch(source.Kind(mgr.GetCache(), &migrations.VirtualMachineStorageMigrationPlan{},
handler.TypedEnqueueRequestsFromMapFunc[*migrations.VirtualMachineStorageMigrationPlan, reconcile.Request](r.getMigMigrationsForPlan),
handler.TypedEnqueueRequestsFromMapFunc(r.getMigMigrationsForPlan),
predicate.TypedFuncs[*migrations.VirtualMachineStorageMigrationPlan]{
CreateFunc: func(e event.TypedCreateEvent[*migrations.VirtualMachineStorageMigrationPlan]) bool { return true },
DeleteFunc: func(e event.TypedDeleteEvent[*migrations.VirtualMachineStorageMigrationPlan]) bool { return true },
Expand All @@ -242,7 +242,7 @@ func (r *StorageMigrationReconciler) SetupWithManager(mgr ctrl.Manager) error {

// Watch for changes to VirtualMachineInstanceMigrations
if err := c.Watch(source.Kind(mgr.GetCache(), &virtv1.VirtualMachineInstanceMigration{},
handler.TypedEnqueueRequestsFromMapFunc[*virtv1.VirtualMachineInstanceMigration, reconcile.Request](r.getMigMigrationsForVMIM),
handler.TypedEnqueueRequestsFromMapFunc(r.getMigMigrationsForVMIM),
predicate.TypedFuncs[*virtv1.VirtualMachineInstanceMigration]{
CreateFunc: func(e event.TypedCreateEvent[*virtv1.VirtualMachineInstanceMigration]) bool { return true },
DeleteFunc: func(e event.TypedDeleteEvent[*virtv1.VirtualMachineInstanceMigration]) bool { return true },
Expand Down
16 changes: 8 additions & 8 deletions internal/controller/storagemig/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,30 @@ func (t *Task) Run(ctx context.Context) error {
t.init()
log := t.Log

log.Info("Running task.Run", "phase", t.Owner.Status.Phase)
log.V(5).Info("Running task.Run", "phase", t.Owner.Status.Phase)
// Run the current phase.
switch t.Owner.Status.Phase {
case migrations.Started:
log.Info("Processing Started phase")
log.V(5).Info("Processing Started phase")
// Set finalizer on migration
t.Owner.AddFinalizer(migrations.VirtualMachineStorageMigrationFinalizer, t.Log)
t.Owner.Status.Phase = migrations.RefreshStorageMigrationPlan
case migrations.RefreshStorageMigrationPlan:
log.Info("Processing RefreshStorageMigrationPlan phase")
log.V(5).Info("Processing RefreshStorageMigrationPlan phase")
if err := t.refreshReadyVirtualMachines(ctx); err != nil {
return err
}
t.Owner.Status.Phase = migrations.WaitForStorageMigrationPlanRefreshCompletion
case migrations.WaitForStorageMigrationPlanRefreshCompletion:
log.Info("Processing WaitForStorageMigrationPlanRefreshCompletion phase")
log.V(5).Info("Processing WaitForStorageMigrationPlanRefreshCompletion phase")
if completed, err := t.refreshCompletedVirtualMachines(ctx); err != nil {
return err
} else if !completed {
return nil
}
t.Owner.Status.Phase = migrations.BeginLiveMigration
case migrations.BeginLiveMigration:
log.Info("Processing BeginLiveMigration phase", "readyMigrations", len(t.Plan.Status.ReadyMigrations))
log.V(5).Info("Processing BeginLiveMigration phase", "readyMigrations", len(t.Plan.Status.ReadyMigrations))
for _, vm := range t.Plan.Status.ReadyMigrations {
if can, err := t.canVMStorageMigrate(ctx, vm.Name); err != nil {
return err
Expand All @@ -92,7 +92,7 @@ func (t *Task) Run(ctx context.Context) error {
}
t.Owner.Status.Phase = migrations.WaitForLiveMigrationToComplete
case migrations.WaitForLiveMigrationToComplete:
log.Info("Processing WaitForLiveMigrationToComplete phase", "runningMigrations", len(t.Owner.Status.RunningMigrations))
log.V(5).Info("Processing WaitForLiveMigrationToComplete phase", "runningMigrations", len(t.Owner.Status.RunningMigrations))
runningMigrations := make([]migrations.RunningVirtualMachineMigration, 0)
for _, vm := range t.Owner.Status.RunningMigrations {
if ok, err := t.isLiveMigrationCompleted(ctx, vm.Name); err != nil {
Expand Down Expand Up @@ -146,15 +146,15 @@ func (t *Task) isLiveMigrationCompleted(ctx context.Context, vmName string) (boo
var activeVMIM *virtv1.VirtualMachineInstanceMigration
for _, vmim := range vmimList.Items {
if vmim.Spec.VMIName == vmName && vmim.Status.Phase != virtv1.MigrationFailed {
t.Log.Info("Found active VMIM", "vmim", vmim.Name)
t.Log.V(5).Info("Found active VMIM", "vmim", vmim.Name)
activeVMIM = &vmim
break
}
}
if activeVMIM == nil {
return false, nil
}
t.Log.Info("is active VMIM completed", "completed", activeVMIM.Status.MigrationState != nil && activeVMIM.Status.MigrationState.Completed && !activeVMIM.Status.MigrationState.Failed)
t.Log.V(5).Info("is active VMIM completed", "completed", activeVMIM.Status.MigrationState != nil && activeVMIM.Status.MigrationState.Completed && !activeVMIM.Status.MigrationState.Failed)
return activeVMIM.Status.MigrationState != nil && activeVMIM.Status.MigrationState.Completed && !activeVMIM.Status.MigrationState.Failed, nil
}

Expand Down
8 changes: 4 additions & 4 deletions internal/controller/storagemig/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,11 @@ func (t *Task) refreshReadyVirtualMachines(ctx context.Context) error {
}
planCopy.Annotations[storagemigplan.RefreshStartTimeAnnotation] = time.Now().Format(time.RFC3339Nano)
delete(planCopy.Annotations, storagemigplan.RefreshEndTimeAnnotation)
t.Log.V(1).Info("new plan annotations", "annotations", planCopy.Annotations)
t.Log.V(5).Info("new plan annotations", "annotations", planCopy.Annotations)
if err := t.Client.Patch(ctx, planCopy, client.MergeFrom(plan)); err != nil {
return err
}
t.Log.V(1).Info("refreshed plan annotations", "annotations", planCopy.Annotations)
t.Log.V(5).Info("refreshed plan annotations", "annotations", planCopy.Annotations)
return nil
}

Expand All @@ -244,13 +244,13 @@ func (t *Task) refreshCompletedVirtualMachines(ctx context.Context) (bool, error
if startTimeString, ok := plan.Annotations[storagemigplan.RefreshStartTimeAnnotation]; !ok {
return false, fmt.Errorf("refresh start time not found")
} else {
log.Info("startTime", "startTime", startTimeString)
log.V(5).Info("refresh start time", "startTime", startTimeString)
if startTime, err = time.Parse(time.RFC3339Nano, startTimeString); err != nil {
return false, err
}
}
if endTime, ok := plan.Annotations[storagemigplan.RefreshEndTimeAnnotation]; ok {
log.Info("endTime", "endTime", endTime)
log.V(5).Info("refresh end time", "endTime", endTime)
if endTime, err := time.Parse(time.RFC3339Nano, endTime); err != nil {
return false, err
} else {
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/storagemigplan/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type StorageMigPlanReconciler struct {
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.20.4/pkg/reconcile
func (r *StorageMigPlanReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := r.Log
log.V(1).Info("Reconciling VirtualMachineStorageMigrationPlan", "name", req.NamespacedName)
log.V(5).Info("Reconciling VirtualMachineStorageMigrationPlan", "name", req.NamespacedName)
// Fetch the MigPlan instance
plan := &migrations.VirtualMachineStorageMigrationPlan{}
err := r.Get(context.TODO(), req.NamespacedName, plan)
Expand Down Expand Up @@ -117,7 +117,7 @@ func (r *StorageMigPlanReconciler) Reconcile(ctx context.Context, req ctrl.Reque

planStatusCopy := plan.Status.DeepCopy()
if !apiequality.Semantic.DeepEqual(plan.Status, planCopy.Status) {
log.V(1).Info("Updating MigPlan status")
log.V(5).Info("Updating MigPlan status")
if err := r.Status().Update(context.TODO(), plan); err != nil {
return reconcile.Result{}, err
}
Expand Down
8 changes: 1 addition & 7 deletions internal/controller/storagemigplan/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ var (

// Validate the plan resource.
func (r *StorageMigPlanReconciler) validate(ctx context.Context, plan *migrations.VirtualMachineStorageMigrationPlan) error {
r.Log.Info("Validating storage migration plan", "plan", plan.Name)
if err := r.validateLiveMigrationPossible(ctx, plan); err != nil {
return fmt.Errorf("err checking if live migration is possible: %w", err)
}
Expand All @@ -81,7 +80,6 @@ func (r *StorageMigPlanReconciler) validateLiveMigrationPossible(ctx context.Con
if err := r.validateKubeVirtInstalled(ctx, plan); err != nil {
return err
}
r.Log.Info("mig plan status", "conditions", plan.Status.Conditions)
if plan.Status.HasAnyCondition(StorageMigrationNotPossibleType) {
r.Log.Info("KubeVirt is not installed, version is not supported, or storage live migration is not enabled, skipping storage migration possible validation")
return nil
Expand Down Expand Up @@ -125,7 +123,6 @@ func (r *StorageMigPlanReconciler) validateStorageMigrationPossible(ctx context.
}
}
// Validate the PVCs are valid
r.Log.Info("validating PVCs", "migrations", plan.Status.ReadyMigrations)
if reason, message, err := r.validatePVCs(ctx, plan); err != nil {
return err
} else if message != "" {
Expand Down Expand Up @@ -269,7 +266,6 @@ func (r *StorageMigPlanReconciler) validatePVCs(ctx context.Context, plan *migra
invalidMigrations := make([]migrations.VirtualMachineStorageMigrationPlanStatusVirtualMachine, 0)
lastReason := ""
lastMessage := ""
r.Log.Info("validating PVCs", "number of ready migrations", len(plan.Status.ReadyMigrations))
for _, vm := range plan.Status.ReadyMigrations {
issueFound := false
for i, pvc := range vm.TargetMigrationPVCs {
Expand Down Expand Up @@ -297,7 +293,6 @@ func (r *StorageMigPlanReconciler) validatePVCs(ctx context.Context, plan *migra
break
}
}
r.Log.Info("validating PVC", "pvc", vm.TargetMigrationPVCs[i].DestinationPVC.Name, "sourcePVC", vm.SourcePVCs[i].Name, "isMigrating", r.isVMMigrating(ctx, plan))
if vm.TargetMigrationPVCs[i].DestinationPVC.Name != nil && *vm.TargetMigrationPVCs[i].DestinationPVC.Name == vm.SourcePVCs[i].Name && !r.isVMMigrating(ctx, plan) {
lastReason = migrations.Conflict
lastMessage = fmt.Sprintf("VM %s has a destination PVC name for volume %s that is the same as the source PVC name", vm.Name, vm.TargetMigrationPVCs[i].VolumeName)
Expand Down Expand Up @@ -330,7 +325,6 @@ func (r *StorageMigPlanReconciler) isVMMigrating(ctx context.Context, plan *migr
(storageMigration.Status.Phase == migrations.WaitForLiveMigrationToComplete ||
storageMigration.Status.Phase == migrations.CleanupMigrationResources ||
storageMigration.Status.Phase == migrations.Completed) {
r.Log.Info("VM is migrating", "vm", plan.Name)
return true
}
}
Expand Down Expand Up @@ -409,7 +403,7 @@ func (r *StorageMigPlanReconciler) validateKubeVirtInstalled(ctx context.Context
log.V(3).Info("KubeVirt operator version", "major", major, "minor", minor, "bugfix", bugfix)
// Check if kubevirt operator version is at least 1.3.0 if live migration is enabled.
if major < 1 || (major == 1 && minor < 3) {
log.Info("KubeVirt operator version is not supported", "version", operatorVersion)
log.V(3).Info("KubeVirt operator version is not supported", "version", operatorVersion)
plan.Status.SetCondition(migrations.Condition{
Type: StorageMigrationNotPossibleType,
Status: corev1.ConditionTrue,
Expand Down
Loading