Skip to content

Commit 0c88556

Browse files
fix
Signed-off-by: Yaroslav Borbat <[email protected]>
1 parent b540611 commit 0c88556

File tree

1 file changed

+20
-1
lines changed
  • images/virtualization-artifact/pkg/controller/volumemigration/internal/handler

1 file changed

+20
-1
lines changed

images/virtualization-artifact/pkg/controller/volumemigration/internal/handler/migration.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package handler
1919
import (
2020
"cmp"
2121
"context"
22+
"log/slog"
2223
"slices"
2324
"time"
2425

@@ -33,6 +34,7 @@ import (
3334
commonvd "github.com/deckhouse/virtualization-controller/pkg/common/vd"
3435
commonvmop "github.com/deckhouse/virtualization-controller/pkg/common/vmop"
3536
"github.com/deckhouse/virtualization-controller/pkg/controller/conditions"
37+
"github.com/deckhouse/virtualization-controller/pkg/logger"
3638
"github.com/deckhouse/virtualization/api/core/v1alpha2"
3739
"github.com/deckhouse/virtualization/api/core/v1alpha2/vdcondition"
3840
)
@@ -59,14 +61,20 @@ func (h *MigrationHandler) Handle(ctx context.Context, vd *v1alpha2.VirtualDisk)
5961
return reconcile.Result{}, nil
6062
}
6163

64+
log, ctx := logger.GetHandlerContext(ctx, MigrationHandlerName)
65+
log.Info("Detected VirtualDisk with changed StorageClass")
66+
6267
ready, _ := conditions.GetCondition(vdcondition.ReadyType, vd.Status.Conditions)
63-
if ready.Status != metav1.ConditionTrue {
68+
if ready.Status != metav1.ConditionTrue && conditions.IsLastUpdated(ready, vd) {
69+
70+
log.Info("VirtualDisk is not ready. Cannot be migrated now. Skip...")
6471
return reconcile.Result{}, nil
6572
}
6673

6774
vm, err := h.getVirtualMachine(ctx, vd)
6875
if err != nil {
6976
if k8serrors.IsNotFound(err) {
77+
log.Info("VirtualMachine not found. Cannot be migrated now. Skip...")
7078
return reconcile.Result{RequeueAfter: 30 * time.Second}, nil
7179
}
7280
return reconcile.Result{}, err
@@ -78,6 +86,7 @@ func (h *MigrationHandler) Handle(ctx context.Context, vd *v1alpha2.VirtualDisk)
7886
}
7987

8088
if len(migratingVMOPs) > 0 {
89+
log.Info("VirtualMachine is already migrating. Skip...")
8190
return reconcile.Result{}, nil
8291
}
8392

@@ -87,23 +96,33 @@ func (h *MigrationHandler) Handle(ctx context.Context, vd *v1alpha2.VirtualDisk)
8796
// wait for 3 seconds before creating the vmop
8897
// this needs to be several virtual disks will be changed if needed.
8998
h.delay[vm.UID] = now.Add(3 * time.Second)
99+
100+
log.Info("Waiting for 3 seconds before creating the vmop")
101+
90102
return reconcile.Result{RequeueAfter: 3 * time.Second}, nil
91103
}
92104

105+
log.Info("Delay is set. Waiting for the delay")
106+
93107
if now.Before(delay) {
94108
requeueAfter := delay.Sub(now)
109+
110+
log.Info("VMOP will be created after the delay", slog.Duration("delay", requeueAfter))
95111
return reconcile.Result{RequeueAfter: requeueAfter}, nil
96112
}
97113

98114
backoff := h.calculateBackoff(finishedVMOPs)
99115
if backoff > 0 {
116+
log.Info("VMOP will be created after the backoff", slog.Duration("backoff", backoff))
100117
return reconcile.Result{RequeueAfter: backoff}, nil
101118
}
102119

103120
vmop := newVolumeMigrationVMOP(vm.Name, vm.Namespace)
121+
log.Info("Create VMOP", slog.String("vmop.generate-name", vmop.GenerateName), slog.String("vmop.namespace", vmop.Namespace))
104122
if err := h.client.Create(ctx, vmop); err != nil {
105123
return reconcile.Result{}, err
106124
}
125+
log.Debug("VMOP created", slog.String("vmop.name", vmop.Name), slog.String("vmop.namespace", vmop.Namespace))
107126

108127
delete(h.delay, vm.UID)
109128

0 commit comments

Comments
 (0)