Skip to content

Commit 6a5f64e

Browse files
committed
feat(core): add VMOP restore
Signed-off-by: Daniil Antoshin <[email protected]>
1 parent d2970a3 commit 6a5f64e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+5084
-54
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+
// ReasonVMStopFailed is an event reason indicating that the stop 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

api/core/v1alpha2/virtual_machine_operation.go

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type VirtualMachineOperation struct {
4545
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message=".spec is immutable"
4646
// +kubebuilder:validation:XValidation:rule="self.type == 'Start' ? !has(self.force) || !self.force : true",message="The `Start` operation cannot be performed forcibly."
4747
// +kubebuilder:validation:XValidation:rule="self.type == 'Migrate' ? !has(self.force) || !self.force : true",message="The `Migrate` operation cannot be performed forcibly."
48+
// +kubebuilder:validation:XValidation:rule="self.type == 'Restore' ? has(self.restore) : true",message="Restore requires restore field."
4849
type VirtualMachineOperationSpec struct {
4950
Type VMOPType `json:"type"`
5051
// Name of the virtual machine the operation is performed for.
@@ -54,14 +55,77 @@ type VirtualMachineOperationSpec struct {
5455
// * Effect on `Restart` and `Stop`: operation performs immediately.
5556
// * Effect on `Evict` and `Migrate`: enable the AutoConverge feature to force migration via CPU throttling if the `PreferSafe` or `PreferForced` policies are used for live migration.
5657
Force *bool `json:"force,omitempty"`
58+
// Restore defines the restore operation.
59+
Restore *VirtualMachineOperationRestoreSpec `json:"restore,omitempty"`
5760
}
5861

62+
// VirtualMachineOperationRestoreSpec defines the restore operation.
63+
type VirtualMachineOperationRestoreSpec struct {
64+
Mode VMOPRestoreMode `json:"mode"`
65+
// VirtualMachineSnapshotName defines the source of the restore operation.
66+
VirtualMachineSnapshotName string `json:"virtualMachineSnapshotName"`
67+
}
68+
69+
// VMOPRestoreMode defines the kind of the restore operation.
70+
// * `DryRun`: DryRun run without any changes. Compatibility shows in status.
71+
// * `Strict`: Strict restore as is in the snapshot.
72+
// * `BestEffort`: BestEffort restore without deleted external missing dependencies.
73+
// +kubebuilder:validation:Enum={DryRun,Strict,BestEffort}
74+
type VMOPRestoreMode string
75+
76+
const (
77+
VMOPRestoreModeDryRun VMOPRestoreMode = "DryRun"
78+
VMOPRestoreModeStrict VMOPRestoreMode = "Strict"
79+
VMOPRestoreModeBestEffort VMOPRestoreMode = "BestEffort"
80+
)
81+
5982
type VirtualMachineOperationStatus struct {
6083
Phase VMOPPhase `json:"phase"`
6184
// The latest detailed observations of the VirtualMachineOperation resource.
6285
Conditions []metav1.Condition `json:"conditions,omitempty"`
6386
// Resource generation last processed by the controller.
6487
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
88+
// Resources contains the list of resources that are affected by the snapshot operation.
89+
Resources []VirtualMachineOperationResource `json:"resources,omitempty"`
90+
}
91+
92+
// VMOPResourceKind defines the kind of the resource affected by the operation.
93+
// * `VirtualDisk`: VirtualDisk resource.
94+
// * `VirtualMachine`: VirtualMachine resource.
95+
// * `VirtualImage`: VirtualImage resource.
96+
// * `ClusterVirtualImage`: ClusterVirtualImage resource.
97+
// * `VirtualMachineIPAddress`: VirtualMachineIPAddress resource.
98+
// * `VirtualMachineIPAddressLease`: VirtualMachineIPAddressLease resource.
99+
// * `VirtualMachineClass`: VirtualMachineClass resource.
100+
// * `VirtualMachineOperation`: VirtualMachineOperation resource.
101+
// +kubebuilder:validation:Enum={VMOPResourceSecret,VMOPResourceNetwork,VMOPResourceVirtualDisk,VMOPResourceVirtualImage,VMOPResourceVirtualMachine,VMOPResourceClusterNetwork,VMOPResourceClusterVirtualImage,VMOPResourceVirtualMachineIPAddress,VMOPResourceVirtualMachineMacAddress,VMOPResourceVirtualMachineBlockDeviceAttachment}
102+
type VMOPResourceKind string
103+
104+
const (
105+
VMOPResourceSecret VMOPResourceKind = "Secret"
106+
VMOPResourceNetwork VMOPResourceKind = "Network"
107+
VMOPResourceVirtualDisk VMOPResourceKind = "VirtualDisk"
108+
VMOPResourceVirtualImage VMOPResourceKind = "VirtualImage"
109+
VMOPResourceVirtualMachine VMOPResourceKind = "VirtualMachine"
110+
VMOPResourceClusterNetwork VMOPResourceKind = "ClusterNetwork"
111+
VMOPResourceClusterVirtualImage VMOPResourceKind = "ClusterVirtualImage"
112+
VMOPResourceVirtualMachineIPAddress VMOPResourceKind = "VirtualMachineIPAddress"
113+
VMOPResourceVirtualMachineMacAddress VMOPResourceKind = "VirtualMachineMacAddress"
114+
VMOPResourceVirtualMachineBlockDeviceAttachment VMOPResourceKind = "VirtualMachineBlockDeviceAttachment"
115+
)
116+
117+
// VirtualMachineOperationResource defines the resource affected by the operation.
118+
type VirtualMachineOperationResource struct {
119+
// API version of the resource.
120+
APIVersion string `json:"apiVersion"`
121+
// Name of the resource.
122+
Name string `json:"name"`
123+
// Kind of the resource.
124+
Kind string `json:"kind"`
125+
// Status of the resource.
126+
Status string `json:"status"`
127+
// Message about the resource.
128+
Message string `json:"message"`
65129
}
66130

67131
// VirtualMachineOperationList contains a list of VirtualMachineOperation resources.
@@ -95,7 +159,8 @@ const (
95159
// * `Restart`: Restart the virtual machine.
96160
// * `Migrate` (deprecated): Migrate the virtual machine to another node where it can be started.
97161
// * `Evict`: Migrate the virtual machine to another node where it can be started.
98-
// +kubebuilder:validation:Enum={Restart,Start,Stop,Migrate,Evict}
162+
// * `Restore`: Restore the virtual machine from a snapshot.
163+
// +kubebuilder:validation:Enum={Restart,Start,Stop,Migrate,Evict,Restore}
99164
type VMOPType string
100165

101166
const (
@@ -104,4 +169,5 @@ const (
104169
VMOPTypeStop VMOPType = "Stop"
105170
VMOPTypeMigrate VMOPType = "Migrate"
106171
VMOPTypeEvict VMOPType = "Evict"
172+
VMOPTypeRestore VMOPType = "Restore"
107173
)

api/core/v1alpha2/vmopcondition/condition.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ const (
2828

2929
// TypeSignalSent is a type for condition that indicates operation signal has been sent.
3030
TypeSignalSent Type = "SignalSent"
31+
32+
// TypeRestoreCompleted is a type for condition that indicates success of restore.
33+
TypeRestoreCompleted Type = "RestoreCompleted"
34+
35+
// TypeMaintenanceMode is a type for condition that indicates VMOP has put VM in maintenance mode.
36+
TypeMaintenanceMode Type = "MaintenanceMode"
3137
)
3238

3339
// ReasonCompleted represents specific reasons for the 'Completed' condition type.
@@ -62,6 +68,9 @@ const (
6268
// ReasonStopInProgress is a ReasonCompleted indicating that the stop signal has been sent and stop is in progress.
6369
ReasonStopInProgress ReasonCompleted = "StopInProgress"
6470

71+
// ReasonRestoreInProgress is a ReasonCompleted indicating that the restore operation is in progress.
72+
ReasonRestoreInProgress ReasonCompleted = "RestoreInProgress"
73+
6574
// ReasonMigrationPending is a ReasonCompleted indicating that the migration process has been initiated but not yet started.
6675
ReasonMigrationPending ReasonCompleted = "MigrationPending"
6776

@@ -87,6 +96,27 @@ const (
8796
ReasonOperationCompleted ReasonCompleted = "OperationCompleted"
8897
)
8998

99+
// ReasonRestoreCompleted represents specific reasons for the 'RestoreCompleted' condition type.
100+
type ReasonRestoreCompleted string
101+
102+
func (r ReasonRestoreCompleted) String() string {
103+
return string(r)
104+
}
105+
106+
const (
107+
// ReasonRestoreInProgress is a ReasonRestoreCompleted indicating that the restore operation is in progress.
108+
ReasonRestoreOperationInProgress ReasonRestoreCompleted = "RestoreInProgress"
109+
110+
// ReasonRestoreOperationCompleted is a ReasonRestoreCompleted indicating that the restore operation has completed successfully.
111+
ReasonRestoreOperationCompleted ReasonRestoreCompleted = "RestoreCompleted"
112+
113+
// ReasonDryRunOperationCompleted is a ReasonRestoreCompleted indicating that the restore dry run operation has completed successfully.
114+
ReasonDryRunOperationCompleted ReasonRestoreCompleted = "RestoreDryRunCompleted"
115+
116+
// ReasonRestoreOperationFailed is a ReasonRestoreCompleted indicating that operation has failed.
117+
ReasonRestoreOperationFailed ReasonRestoreCompleted = "RestoreFailed"
118+
)
119+
90120
// ReasonCompleted represents specific reasons for the 'SignalSent' condition type.
91121
type ReasonSignalSent string
92122

@@ -101,3 +131,21 @@ const (
101131
// ReasonSignalSentSuccess is a ReasonCompleted indicating that signal is sent to the VM.
102132
ReasonSignalSentSuccess ReasonSignalSent = "SignalSentSuccess"
103133
)
134+
135+
// ReasonMaintenanceMode represents specific reasons for the 'MaintenanceMode' condition type.
136+
type ReasonMaintenanceMode string
137+
138+
func (r ReasonMaintenanceMode) String() string {
139+
return string(r)
140+
}
141+
142+
const (
143+
// ReasonMaintenanceModeEnabled is a ReasonMaintenanceMode indicating that VM is in maintenance mode for restore operation.
144+
ReasonMaintenanceModeEnabled ReasonMaintenanceMode = "MaintenanceModeEnabled"
145+
146+
// ReasonMaintenanceModeDisabled is a ReasonMaintenanceMode indicating that VM has exited maintenance mode.
147+
ReasonMaintenanceModeDisabled ReasonMaintenanceMode = "MaintenanceModeDisabled"
148+
149+
// ReasonMaintenanceModeFailure is a ReasonMaintenanceMode indicating that maintenance mode operation failed.
150+
ReasonMaintenanceModeFailure ReasonMaintenanceMode = "MaintenanceModeFailure"
151+
)

api/core/v1alpha2/zz_generated.deepcopy.go

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/pkg/apiserver/api/generated/openapi/zz_generated.openapi.go

Lines changed: 107 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)