Skip to content

Commit afcf479

Browse files
committed
refactor(core): remove VM maintenance check for DryRun restore mode
- Remove ErrVMNotInMaintenance and ErrVMMaintenanceCondNotFound errors - Remove maintenance condition check from vm_restorer.go for DryRun mode - Remove DryRunIgnoredErrors from snapshot_resources.go Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>
1 parent 50e2f28 commit afcf479

File tree

5 files changed

+0
-37
lines changed

5 files changed

+0
-37
lines changed

images/virtualization-artifact/pkg/controller/service/restorer/common/common.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ var (
3535
ErrUpdating = errors.New("will be updated")
3636
ErrQueueing = errors.New("will be queued")
3737
ErrWaitingForDeletion = errors.New("waiting for deletion to complete")
38-
ErrVMNotInMaintenance = errors.New("the virtual machine is not in maintenance mode")
39-
ErrVMMaintenanceCondNotFound = errors.New("the virtual machine maintenance condition is not found")
4038
ErrVirtualImageNotFound = errors.New("the virtual image is not found")
4139
ErrVirtualDiskSnapshotNotFound = errors.New("not found")
4240
ErrClusterVirtualImageNotFound = errors.New("the virtual image is not found")

images/virtualization-artifact/pkg/controller/service/restorer/restorers/vm_restorer.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ import (
2828

2929
"github.com/deckhouse/virtualization-controller/pkg/common/annotations"
3030
"github.com/deckhouse/virtualization-controller/pkg/common/object"
31-
"github.com/deckhouse/virtualization-controller/pkg/controller/conditions"
3231
"github.com/deckhouse/virtualization-controller/pkg/controller/service/restorer/common"
3332
"github.com/deckhouse/virtualization/api/core/v1alpha2"
34-
"github.com/deckhouse/virtualization/api/core/v1alpha2/vmcondition"
3533
)
3634

3735
const ReasonPVCNotFound = "PVC not found"
@@ -184,15 +182,6 @@ func (v *VirtualMachineHandler) ProcessRestore(ctx context.Context) error {
184182
}
185183

186184
if vm != nil {
187-
cond, found := conditions.GetCondition(vmcondition.TypeMaintenance, vm.Status.Conditions)
188-
if !found {
189-
return common.ErrVMMaintenanceCondNotFound
190-
}
191-
192-
if cond.Status != metav1.ConditionTrue {
193-
return common.ErrVMNotInMaintenance
194-
}
195-
196185
// Early return if VM is already fully processed by this restore operation
197186
if value, ok := vm.Annotations[annotations.AnnVMOPRestore]; ok && value == v.restoreUID {
198187
if equality.Semantic.DeepEqual(vm.Spec, v.vm.Spec) {

images/virtualization-artifact/pkg/controller/service/restorer/snapshot_resources.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,6 @@ func (r *SnapshotResources) Process(ctx context.Context) ([]v1alpha2.SnapshotRes
292292
return r.statuses, nil
293293
}
294294

295-
var DryRunIgnoredErrors = []error{
296-
common.ErrVMMaintenanceCondNotFound,
297-
common.ErrVMNotInMaintenance,
298-
}
299-
300295
var BestEffortIgnoredErrors = []error{
301296
common.ErrVirtualImageNotFound,
302297
common.ErrClusterVirtualImageNotFound,
@@ -311,12 +306,6 @@ var RetryErrors = []error{
311306

312307
func shouldIgnoreError(mode v1alpha2.SnapshotOperationMode, err error) bool {
313308
switch mode {
314-
case v1alpha2.SnapshotOperationModeDryRun:
315-
for _, e := range DryRunIgnoredErrors {
316-
if errors.Is(err, e) {
317-
return true
318-
}
319-
}
320309
case v1alpha2.SnapshotOperationModeBestEffort:
321310
for _, e := range BestEffortIgnoredErrors {
322311
if errors.Is(err, e) {

images/virtualization-artifact/pkg/controller/vmop/snapshot/internal/step/process_clone_step.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,16 @@ import (
2121
"errors"
2222

2323
corev1 "k8s.io/api/core/v1"
24-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2524
"k8s.io/apimachinery/pkg/types"
2625
"sigs.k8s.io/controller-runtime/pkg/client"
2726
"sigs.k8s.io/controller-runtime/pkg/reconcile"
2827

2928
"github.com/deckhouse/virtualization-controller/pkg/common/annotations"
3029
"github.com/deckhouse/virtualization-controller/pkg/common/object"
31-
"github.com/deckhouse/virtualization-controller/pkg/controller/conditions"
3230
"github.com/deckhouse/virtualization-controller/pkg/controller/service/restorer"
3331
"github.com/deckhouse/virtualization-controller/pkg/controller/service/restorer/common"
3432
"github.com/deckhouse/virtualization-controller/pkg/eventrecord"
3533
"github.com/deckhouse/virtualization/api/core/v1alpha2"
36-
"github.com/deckhouse/virtualization/api/core/v1alpha2/vmopcondition"
3734
)
3835

3936
type ProcessCloneStep struct {
@@ -52,11 +49,6 @@ func NewProcessCloneStep(
5249
}
5350

5451
func (s ProcessCloneStep) Take(ctx context.Context, vmop *v1alpha2.VirtualMachineOperation) (*reconcile.Result, error) {
55-
cond, found := conditions.GetCondition(vmopcondition.TypeCompleted, vmop.Status.Conditions)
56-
if found && cond.Status == metav1.ConditionTrue {
57-
return nil, nil
58-
}
59-
6052
snapshotName, ok := vmop.Annotations[annotations.AnnVMOPSnapshotName]
6153
if !ok {
6254
return &reconcile.Result{}, errors.New("snapshot name annotation not found")

images/virtualization-artifact/pkg/controller/vmop/snapshot/internal/step/process_restore_step.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@ func NewProcessRestoreStep(
5151
}
5252

5353
func (s ProcessRestoreStep) Take(ctx context.Context, vmop *v1alpha2.VirtualMachineOperation) (*reconcile.Result, error) {
54-
cond, found := conditions.GetCondition(vmopcondition.TypeCompleted, vmop.Status.Conditions)
55-
if found && cond.Status == metav1.ConditionTrue {
56-
return nil, nil
57-
}
58-
5954
maintenanceModeCondition, found := conditions.GetCondition(vmopcondition.TypeMaintenanceMode, vmop.Status.Conditions)
6055
if vmop.Spec.Restore.Mode != v1alpha2.SnapshotOperationModeDryRun && (!found || maintenanceModeCondition.Status == metav1.ConditionFalse) {
6156
return &reconcile.Result{}, nil

0 commit comments

Comments
 (0)