@@ -45,6 +45,7 @@ type VirtualMachineOperation struct {
45
45
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message=".spec is immutable"
46
46
// +kubebuilder:validation:XValidation:rule="self.type == 'Start' ? !has(self.force) || !self.force : true",message="The `Start` operation cannot be performed forcibly."
47
47
// +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."
48
49
type VirtualMachineOperationSpec struct {
49
50
Type VMOPType `json:"type"`
50
51
// Name of the virtual machine the operation is performed for.
@@ -54,14 +55,77 @@ type VirtualMachineOperationSpec struct {
54
55
// * Effect on `Restart` and `Stop`: operation performs immediately.
55
56
// * 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.
56
57
Force * bool `json:"force,omitempty"`
58
+ // Restore defines the restore operation.
59
+ Restore * VirtualMachineOperationRestoreSpec `json:"restore,omitempty"`
57
60
}
58
61
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
+
59
82
type VirtualMachineOperationStatus struct {
60
83
Phase VMOPPhase `json:"phase"`
61
84
// The latest detailed observations of the VirtualMachineOperation resource.
62
85
Conditions []metav1.Condition `json:"conditions,omitempty"`
63
86
// Resource generation last processed by the controller.
64
87
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"`
65
129
}
66
130
67
131
// VirtualMachineOperationList contains a list of VirtualMachineOperation resources.
@@ -95,7 +159,8 @@ const (
95
159
// * `Restart`: Restart the virtual machine.
96
160
// * `Migrate` (deprecated): Migrate the virtual machine to another node where it can be started.
97
161
// * `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}
99
164
type VMOPType string
100
165
101
166
const (
@@ -104,4 +169,5 @@ const (
104
169
VMOPTypeStop VMOPType = "Stop"
105
170
VMOPTypeMigrate VMOPType = "Migrate"
106
171
VMOPTypeEvict VMOPType = "Evict"
172
+ VMOPTypeRestore VMOPType = "Restore"
107
173
)
0 commit comments