Skip to content

Commit b105ff2

Browse files
fix
Signed-off-by: Yaroslav Borbat <[email protected]>
1 parent e2d21b1 commit b105ff2

File tree

7 files changed

+60
-28
lines changed

7 files changed

+60
-28
lines changed

api/core/v1alpha2/vmcondition/condition.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,6 @@ const (
9595
ReasonVmIsRunning Reason = "VirtualMachineRunning"
9696
ReasonInternalVirtualMachineError Reason = "InternalVirtualMachineError"
9797
ReasonPodNotStarted Reason = "PodNotStarted"
98-
ReasonVmIsNotRunning Reason = "VirtualMachineNotRunning"
99-
ReasonVmIsRunning Reason = "VirtualMachineRunning"
100-
ReasonInternalVirtualMachineError Reason = "InternalVirtualMachineError"
101-
ReasonPodNotStarted Reason = "PodNotStarted"
102-
ReasonMigrationIsPending Reason = "MigrationIsPending"
10398

10499
// ReasonFilesystemFrozen indicates that virtual machine's filesystem has been successfully frozen.
105100
ReasonFilesystemFrozen Reason = "Frozen"

images/virtualization-artifact/pkg/controller/service/generic_options.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2025 Flant JSC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package service
218

319
import "github.com/deckhouse/virtualization-controller/pkg/common/provisioner"

images/virtualization-artifact/pkg/controller/vd/internal/migration.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2025 Flant JSC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package internal
218

319
import (
@@ -50,7 +66,7 @@ func (h MigrationHandler) Handle(ctx context.Context, vd *virtv2.VirtualDisk) (r
5066
return reconcile.Result{}, nil
5167
}
5268

53-
action, err := h.getAction(vd)
69+
action, err := h.getAction(ctx, vd)
5470
if err != nil {
5571
return reconcile.Result{}, err
5672
}
@@ -77,14 +93,14 @@ const (
7793
complete
7894
)
7995

80-
func (h MigrationHandler) getAction(vd *virtv2.VirtualDisk) (action, error) {
96+
func (h MigrationHandler) getAction(ctx context.Context, vd *virtv2.VirtualDisk) (action, error) {
8197
currentlyMountedVM := currentlyMountedVM(vd)
8298
if currentlyMountedVM == "" {
8399
return none, nil
84100
}
85101

86102
vm := virtv2.VirtualMachine{}
87-
err := h.client.Get(context.Background(), types.NamespacedName{Name: currentlyMountedVM, Namespace: vd.Namespace}, &vm)
103+
err := h.client.Get(ctx, types.NamespacedName{Name: currentlyMountedVM, Namespace: vd.Namespace}, &vm)
88104
if err != nil {
89105
return none, client.IgnoreNotFound(err)
90106
}
@@ -116,7 +132,7 @@ func (h MigrationHandler) getAction(vd *virtv2.VirtualDisk) (action, error) {
116132

117133
if migratingPending && disksNotMigratable {
118134
pvc := &corev1.PersistentVolumeClaim{}
119-
err := h.client.Get(context.Background(), types.NamespacedName{Name: vd.Status.Target.PersistentVolumeClaim, Namespace: vd.Namespace}, pvc)
135+
err := h.client.Get(ctx, types.NamespacedName{Name: vd.Status.Target.PersistentVolumeClaim, Namespace: vd.Namespace}, pvc)
120136
if err != nil {
121137
return none, client.IgnoreNotFound(err)
122138
}
@@ -168,7 +184,6 @@ func (h MigrationHandler) handleMigrate(ctx context.Context, vd *virtv2.VirtualD
168184
}
169185
if targetStorageClass != nil {
170186
if !h.scValidator.IsStorageClassAllowed(targetStorageClass.Name) {
171-
172187
vd.Status.MigrationInfo = virtv2.VirtualDiskMigrationInfo{
173188
Failed: true,
174189
Message: fmt.Sprintf("StorageClass %s is not allowed for use.", targetStorageClass.Name),
@@ -178,7 +193,6 @@ func (h MigrationHandler) handleMigrate(ctx context.Context, vd *virtv2.VirtualD
178193
return nil
179194
}
180195
if h.scValidator.IsStorageClassDeprecated(targetStorageClass) {
181-
182196
vd.Status.MigrationInfo = virtv2.VirtualDiskMigrationInfo{
183197
Failed: true,
184198
Message: fmt.Sprintf("StorageClass %s is deprecated, please use a different one.", targetStorageClass.Name),
@@ -206,7 +220,6 @@ func (h MigrationHandler) handleMigrate(ctx context.Context, vd *virtv2.VirtualD
206220
}
207221

208222
if targetStorageClass.GetDeletionTimestamp() != nil {
209-
210223
vd.Status.MigrationInfo = virtv2.VirtualDiskMigrationInfo{
211224
Failed: true,
212225
Message: fmt.Sprintf("StorageClass %s is terminating and cannot be used.", targetStorageClass.Name),
@@ -216,7 +229,6 @@ func (h MigrationHandler) handleMigrate(ctx context.Context, vd *virtv2.VirtualD
216229
}
217230

218231
if targetStorageClass.VolumeBindingMode == nil || *targetStorageClass.VolumeBindingMode != storev1.VolumeBindingWaitForFirstConsumer {
219-
220232
vd.Status.MigrationInfo = virtv2.VirtualDiskMigrationInfo{
221233
Failed: true,
222234
Message: fmt.Sprintf("StorageClass %s does not support migration, VolumeBindingMode must be WaitForFirstConsumer.", targetStorageClass.Name),

images/virtualization-artifact/pkg/controller/vd/internal/supplements/supplements.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2025 Flant JSC
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package supplements
218

319
import (

images/virtualization-artifact/pkg/controller/vd/vd_controller.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"sigs.k8s.io/controller-runtime/pkg/metrics"
2929

3030
"github.com/deckhouse/deckhouse/pkg/log"
31-
3231
"github.com/deckhouse/virtualization-controller/pkg/config"
3332
"github.com/deckhouse/virtualization-controller/pkg/controller/service"
3433
"github.com/deckhouse/virtualization-controller/pkg/controller/vd/internal"

images/virtualization-artifact/pkg/controller/vm/internal/migrating.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,9 @@ func (h *MigratingHandler) getVMOPCandidate(ctx context.Context, s state.Virtual
197197
{
198198
var vmopCandidates []*virtv2.VirtualMachineOperation
199199
for _, op := range vmops {
200-
if !commonvmop.IsMigration(op) {
201-
continue
202-
}
203-
204-
cond, _ := conditions.GetCondition(vmopcondition.TypeCompleted, op.Status.Conditions)
205-
if cond.Reason == vmopcondition.ReasonWaitingForVirtualMachineToBeReadyToMigrate.String() || op.Status.Phase == virtv2.VMOPPhaseInProgress {
200+
if operationIsCandidate(op) {
206201
vmopCandidates = append(vmopCandidates, op)
207202
}
208-
209203
}
210204

211205
switch length := len(vmopCandidates); length {
@@ -255,8 +249,12 @@ func liveMigrationFailed(migrationState *virtv2.VirtualMachineMigrationState) bo
255249
return migrationState != nil && migrationState.EndTimestamp != nil && migrationState.Result == virtv2.MigrationResultFailed
256250
}
257251

258-
func isOperationInProgress(vmop *virtv2.VirtualMachineOperation) bool {
252+
func operationIsCandidate(vmop *virtv2.VirtualMachineOperation) bool {
253+
if !commonvmop.IsMigration(vmop) {
254+
return false
255+
}
256+
259257
sent, _ := conditions.GetCondition(vmopcondition.TypeSignalSent, vmop.Status.Conditions)
260258
completed, _ := conditions.GetCondition(vmopcondition.TypeCompleted, vmop.Status.Conditions)
261-
return sent.Status == metav1.ConditionTrue && completed.Status != metav1.ConditionTrue
259+
return (sent.Status == metav1.ConditionTrue && completed.Status != metav1.ConditionTrue) || completed.Reason == vmopcondition.ReasonWaitingForVirtualMachineToBeReadyToMigrate.String()
262260
}

images/virtualization-artifact/pkg/controller/vm/internal/watcher/virtualdisk_watcher.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,7 @@ func (w *VirtualDiskWatcher) Watch(mgr manager.Manager, ctr controller.Controlle
5959
oldMigrationCondition, _ := conditions.GetCondition(vdcondition.MigrationType, e.ObjectOld.Status.Conditions)
6060
newMigrationCondition, _ := conditions.GetCondition(vdcondition.MigrationType, e.ObjectNew.Status.Conditions)
6161

62-
if oldMigrationCondition != newMigrationCondition {
63-
return true
64-
}
65-
66-
return false
62+
return oldMigrationCondition != newMigrationCondition
6763
},
6864
},
6965
),

0 commit comments

Comments
 (0)