Skip to content

Commit 408f71b

Browse files
committed
feat: realign steps
Signed-off-by: Daniil Antoshin <[email protected]>
1 parent 277d3da commit 408f71b

File tree

9 files changed

+39
-261
lines changed

9 files changed

+39
-261
lines changed

api/core/v1alpha2/events.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ const (
4040
// ReasonVMStartFailed is an event reason indicating that the start of the VM failed.
4141
ReasonVMStartFailed = "Failed"
4242

43+
// ReasonVMStartFailed is an event reason indicating that the start of the VM failed.
44+
ReasonVMStopFailed = "Failed"
45+
4346
// ReasonVMLastAppliedSpecIsInvalid is event reason that JSON in last-applied-spec annotation is invalid.
4447
ReasonVMLastAppliedSpecIsInvalid = "LastAppliedSpecIsInvalid"
4548

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ func (r VMSnapshotRestore) Sync(ctx context.Context, vm *virtv2.VirtualMachine)
4949
defer func() { conditions.SetCondition(cb.Generation(vm.Generation), &vm.Status.Conditions) }()
5050

5151
return steptaker.NewStepTakers(
52-
step.NewStopVMStep(r.recorder, cb),
52+
step.NewDryRunStep(r.recorder, cb, vm),
53+
step.NewVMSnapshotReadyStep(r.client, r.recorder, cb, r.vmop),
54+
step.NewStopVMStep(r.client, r.recorder, cb, r.vmop),
5355
step.NewRestoreVMStep(r.client, r.recorder, cb, r.vmop),
56+
step.NewStartVMStep(r.client, r.recorder, cb, r.vmop),
5457
).Run(ctx, vm)
5558
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Copyright 2024 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+
package step
17+
18+
import (
19+
"context"
20+
21+
corev1 "k8s.io/api/core/v1"
22+
23+
virtv2 "github.com/deckhouse/virtualization/api/core/v1alpha2"
24+
)
25+
26+
// go:generate moq -rm -out mock.go . Restorer
27+
type Restorer interface {
28+
RestoreVirtualMachine(ctx context.Context, secret *corev1.Secret) (*virtv2.VirtualMachine, error)
29+
RestoreProvisioner(ctx context.Context, secret *corev1.Secret) (*corev1.Secret, error)
30+
RestoreVirtualMachineIPAddress(ctx context.Context, secret *corev1.Secret) (*virtv2.VirtualMachineIPAddress, error)
31+
RestoreVirtualMachineBlockDeviceAttachments(ctx context.Context, secret *corev1.Secret) ([]*virtv2.VirtualMachineBlockDeviceAttachment, error)
32+
}

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

Lines changed: 0 additions & 168 deletions
This file was deleted.

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ import (
3636
vmrestorecondition "github.com/deckhouse/virtualization/api/core/v1alpha2/vm-restore-condition"
3737
)
3838

39-
type Restorer interface {
40-
RestoreVirtualMachine(ctx context.Context, secret *corev1.Secret) (*virtv2.VirtualMachine, error)
41-
RestoreProvisioner(ctx context.Context, secret *corev1.Secret) (*corev1.Secret, error)
42-
RestoreVirtualMachineIPAddress(ctx context.Context, secret *corev1.Secret) (*virtv2.VirtualMachineIPAddress, error)
43-
RestoreVirtualMachineBlockDeviceAttachments(ctx context.Context, secret *corev1.Secret) ([]*virtv2.VirtualMachineBlockDeviceAttachment, error)
44-
}
45-
4639
type RestoreVMStep struct {
4740
client client.Client
4841
recorder eventrecord.EventRecorderLogger

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,18 @@ package step
1818

1919
import (
2020
"context"
21-
"errors"
22-
"fmt"
2321

2422
corev1 "k8s.io/api/core/v1"
2523
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26-
"k8s.io/apimachinery/pkg/types"
2724
"sigs.k8s.io/controller-runtime/pkg/client"
2825
"sigs.k8s.io/controller-runtime/pkg/reconcile"
2926

30-
"github.com/deckhouse/virtualization-controller/pkg/common/object"
3127
"github.com/deckhouse/virtualization-controller/pkg/controller/conditions"
32-
"github.com/deckhouse/virtualization-controller/pkg/controller/service"
33-
"github.com/deckhouse/virtualization-controller/pkg/controller/vmop/internal/snapshot/restorer"
3428
"github.com/deckhouse/virtualization-controller/pkg/eventrecord"
3529
virtv2 "github.com/deckhouse/virtualization/api/core/v1alpha2"
3630
vmrestorecondition "github.com/deckhouse/virtualization/api/core/v1alpha2/vm-restore-condition"
3731
)
3832

39-
type Restorer interface {
40-
RestoreVirtualMachine(ctx context.Context, secret *corev1.Secret) (*virtv2.VirtualMachine, error)
41-
RestoreProvisioner(ctx context.Context, secret *corev1.Secret) (*corev1.Secret, error)
42-
RestoreVirtualMachineIPAddress(ctx context.Context, secret *corev1.Secret) (*virtv2.VirtualMachineIPAddress, error)
43-
RestoreVirtualMachineBlockDeviceAttachments(ctx context.Context, secret *corev1.Secret) ([]*virtv2.VirtualMachineBlockDeviceAttachment, error)
44-
}
45-
4633
type StartVMStep struct {
4734
client client.Client
4835
recorder eventrecord.EventRecorderLogger

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,18 @@ package step
1818

1919
import (
2020
"context"
21-
"errors"
22-
"fmt"
2321

2422
corev1 "k8s.io/api/core/v1"
2523
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26-
"k8s.io/apimachinery/pkg/types"
2724
"sigs.k8s.io/controller-runtime/pkg/client"
2825
"sigs.k8s.io/controller-runtime/pkg/reconcile"
2926

30-
"github.com/deckhouse/virtualization-controller/pkg/common/object"
3127
"github.com/deckhouse/virtualization-controller/pkg/controller/conditions"
32-
"github.com/deckhouse/virtualization-controller/pkg/controller/service"
33-
"github.com/deckhouse/virtualization-controller/pkg/controller/vmop/internal/snapshot/restorer"
3428
"github.com/deckhouse/virtualization-controller/pkg/eventrecord"
3529
virtv2 "github.com/deckhouse/virtualization/api/core/v1alpha2"
3630
vmrestorecondition "github.com/deckhouse/virtualization/api/core/v1alpha2/vm-restore-condition"
3731
)
3832

39-
type Restorer interface {
40-
RestoreVirtualMachine(ctx context.Context, secret *corev1.Secret) (*virtv2.VirtualMachine, error)
41-
RestoreProvisioner(ctx context.Context, secret *corev1.Secret) (*corev1.Secret, error)
42-
RestoreVirtualMachineIPAddress(ctx context.Context, secret *corev1.Secret) (*virtv2.VirtualMachineIPAddress, error)
43-
RestoreVirtualMachineBlockDeviceAttachments(ctx context.Context, secret *corev1.Secret) ([]*virtv2.VirtualMachineBlockDeviceAttachment, error)
44-
}
45-
4633
type StopVMStep struct {
4734
client client.Client
4835
recorder eventrecord.EventRecorderLogger

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

Lines changed: 0 additions & 48 deletions
This file was deleted.

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,20 @@ package step
1818

1919
import (
2020
"context"
21-
"errors"
2221
"fmt"
2322

24-
corev1 "k8s.io/api/core/v1"
2523
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2624
"k8s.io/apimachinery/pkg/types"
2725
"sigs.k8s.io/controller-runtime/pkg/client"
2826
"sigs.k8s.io/controller-runtime/pkg/reconcile"
2927

3028
"github.com/deckhouse/virtualization-controller/pkg/common/object"
3129
"github.com/deckhouse/virtualization-controller/pkg/controller/conditions"
32-
"github.com/deckhouse/virtualization-controller/pkg/controller/service"
33-
"github.com/deckhouse/virtualization-controller/pkg/controller/vmop/internal/snapshot/restorer"
3430
"github.com/deckhouse/virtualization-controller/pkg/eventrecord"
3531
virtv2 "github.com/deckhouse/virtualization/api/core/v1alpha2"
3632
vmrestorecondition "github.com/deckhouse/virtualization/api/core/v1alpha2/vm-restore-condition"
3733
)
3834

39-
type Restorer interface {
40-
RestoreVirtualMachine(ctx context.Context, secret *corev1.Secret) (*virtv2.VirtualMachine, error)
41-
RestoreProvisioner(ctx context.Context, secret *corev1.Secret) (*corev1.Secret, error)
42-
RestoreVirtualMachineIPAddress(ctx context.Context, secret *corev1.Secret) (*virtv2.VirtualMachineIPAddress, error)
43-
RestoreVirtualMachineBlockDeviceAttachments(ctx context.Context, secret *corev1.Secret) ([]*virtv2.VirtualMachineBlockDeviceAttachment, error)
44-
}
45-
4635
type VMSnapshotReadyStep struct {
4736
client client.Client
4837
recorder eventrecord.EventRecorderLogger

0 commit comments

Comments
 (0)