@@ -19,6 +19,7 @@ package handler
19
19
import (
20
20
"cmp"
21
21
"context"
22
+ "log/slog"
22
23
"slices"
23
24
"time"
24
25
@@ -33,6 +34,7 @@ import (
33
34
commonvd "github.com/deckhouse/virtualization-controller/pkg/common/vd"
34
35
commonvmop "github.com/deckhouse/virtualization-controller/pkg/common/vmop"
35
36
"github.com/deckhouse/virtualization-controller/pkg/controller/conditions"
37
+ "github.com/deckhouse/virtualization-controller/pkg/logger"
36
38
"github.com/deckhouse/virtualization/api/core/v1alpha2"
37
39
"github.com/deckhouse/virtualization/api/core/v1alpha2/vdcondition"
38
40
)
@@ -59,14 +61,20 @@ func (h *MigrationHandler) Handle(ctx context.Context, vd *v1alpha2.VirtualDisk)
59
61
return reconcile.Result {}, nil
60
62
}
61
63
64
+ log , ctx := logger .GetHandlerContext (ctx , MigrationHandlerName )
65
+ log .Info ("Detected VirtualDisk with changed StorageClass" )
66
+
62
67
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..." )
64
71
return reconcile.Result {}, nil
65
72
}
66
73
67
74
vm , err := h .getVirtualMachine (ctx , vd )
68
75
if err != nil {
69
76
if k8serrors .IsNotFound (err ) {
77
+ log .Info ("VirtualMachine not found. Cannot be migrated now. Skip..." )
70
78
return reconcile.Result {RequeueAfter : 30 * time .Second }, nil
71
79
}
72
80
return reconcile.Result {}, err
@@ -78,6 +86,7 @@ func (h *MigrationHandler) Handle(ctx context.Context, vd *v1alpha2.VirtualDisk)
78
86
}
79
87
80
88
if len (migratingVMOPs ) > 0 {
89
+ log .Info ("VirtualMachine is already migrating. Skip..." )
81
90
return reconcile.Result {}, nil
82
91
}
83
92
@@ -87,23 +96,33 @@ func (h *MigrationHandler) Handle(ctx context.Context, vd *v1alpha2.VirtualDisk)
87
96
// wait for 3 seconds before creating the vmop
88
97
// this needs to be several virtual disks will be changed if needed.
89
98
h .delay [vm .UID ] = now .Add (3 * time .Second )
99
+
100
+ log .Info ("Waiting for 3 seconds before creating the vmop" )
101
+
90
102
return reconcile.Result {RequeueAfter : 3 * time .Second }, nil
91
103
}
92
104
105
+ log .Info ("Delay is set. Waiting for the delay" )
106
+
93
107
if now .Before (delay ) {
94
108
requeueAfter := delay .Sub (now )
109
+
110
+ log .Info ("VMOP will be created after the delay" , slog .Duration ("delay" , requeueAfter ))
95
111
return reconcile.Result {RequeueAfter : requeueAfter }, nil
96
112
}
97
113
98
114
backoff := h .calculateBackoff (finishedVMOPs )
99
115
if backoff > 0 {
116
+ log .Info ("VMOP will be created after the backoff" , slog .Duration ("backoff" , backoff ))
100
117
return reconcile.Result {RequeueAfter : backoff }, nil
101
118
}
102
119
103
120
vmop := newVolumeMigrationVMOP (vm .Name , vm .Namespace )
121
+ log .Info ("Create VMOP" , slog .String ("vmop.generate-name" , vmop .GenerateName ), slog .String ("vmop.namespace" , vmop .Namespace ))
104
122
if err := h .client .Create (ctx , vmop ); err != nil {
105
123
return reconcile.Result {}, err
106
124
}
125
+ log .Debug ("VMOP created" , slog .String ("vmop.name" , vmop .Name ), slog .String ("vmop.namespace" , vmop .Namespace ))
107
126
108
127
delete (h .delay , vm .UID )
109
128
0 commit comments