kubevirt.io/api@v1.2.0/snapshot/v1alpha1/types.go (about) 1 /* 2 * This file is part of the KubeVirt project 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 * Copyright 2020 Red Hat, Inc. 17 * 18 */ 19 20 package v1alpha1 21 22 import ( 23 "time" 24 25 corev1 "k8s.io/api/core/v1" 26 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 27 "k8s.io/apimachinery/pkg/types" 28 29 v1 "kubevirt.io/api/core/v1" 30 ) 31 32 const DefaultFailureDeadline = 5 * time.Minute 33 34 // VirtualMachineSnapshot defines the operation of snapshotting a VM 35 // +genclient 36 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 37 type VirtualMachineSnapshot struct { 38 metav1.TypeMeta `json:",inline"` 39 metav1.ObjectMeta `json:"metadata,omitempty"` 40 41 Spec VirtualMachineSnapshotSpec `json:"spec"` 42 43 // +optional 44 Status *VirtualMachineSnapshotStatus `json:"status,omitempty"` 45 } 46 47 // DeletionPolicy defines that to do with VirtualMachineSnapshot 48 // when VirtualMachineSnapshot is deleted 49 type DeletionPolicy string 50 51 const ( 52 // VirtualMachineSnapshotContentDelete causes the 53 // VirtualMachineSnapshotContent to be deleted 54 VirtualMachineSnapshotContentDelete DeletionPolicy = "Delete" 55 56 // VirtualMachineSnapshotContentRetain causes the 57 // VirtualMachineSnapshotContent to stay around 58 VirtualMachineSnapshotContentRetain DeletionPolicy = "Retain" 59 ) 60 61 // VirtualMachineSnapshotSpec is the spec for a VirtualMachineSnapshot resource 62 type VirtualMachineSnapshotSpec struct { 63 Source corev1.TypedLocalObjectReference `json:"source"` 64 65 // +optional 66 DeletionPolicy *DeletionPolicy `json:"deletionPolicy,omitempty"` 67 68 // This time represents the number of seconds we permit the vm snapshot 69 // to take. In case we pass this deadline we mark this snapshot 70 // as failed. 71 // Defaults to DefaultFailureDeadline - 5min 72 // +optional 73 FailureDeadline *metav1.Duration `json:"failureDeadline,omitempty"` 74 } 75 76 // Indication is a way to indicate the state of the vm when taking the snapshot 77 type Indication string 78 79 const ( 80 VMSnapshotOnlineSnapshotIndication Indication = "Online" 81 VMSnapshotNoGuestAgentIndication Indication = "NoGuestAgent" 82 VMSnapshotGuestAgentIndication Indication = "GuestAgent" 83 ) 84 85 // VirtualMachineSnapshotPhase is the current phase of the VirtualMachineSnapshot 86 type VirtualMachineSnapshotPhase string 87 88 const ( 89 PhaseUnset VirtualMachineSnapshotPhase = "" 90 InProgress VirtualMachineSnapshotPhase = "InProgress" 91 Succeeded VirtualMachineSnapshotPhase = "Succeeded" 92 Failed VirtualMachineSnapshotPhase = "Failed" 93 Deleting VirtualMachineSnapshotPhase = "Deleting" 94 Unknown VirtualMachineSnapshotPhase = "Unknown" 95 ) 96 97 // VirtualMachineSnapshotStatus is the status for a VirtualMachineSnapshot resource 98 type VirtualMachineSnapshotStatus struct { 99 // +optional 100 SourceUID *types.UID `json:"sourceUID,omitempty"` 101 102 // +optional 103 VirtualMachineSnapshotContentName *string `json:"virtualMachineSnapshotContentName,omitempty"` 104 105 // +optional 106 // +nullable 107 CreationTime *metav1.Time `json:"creationTime,omitempty"` 108 109 // +optional 110 Phase VirtualMachineSnapshotPhase `json:"phase,omitempty"` 111 112 // +optional 113 ReadyToUse *bool `json:"readyToUse,omitempty"` 114 115 // +optional 116 Error *Error `json:"error,omitempty"` 117 118 // +optional 119 Conditions []Condition `json:"conditions,omitempty"` 120 121 // +optional 122 // +listType=set 123 Indications []Indication `json:"indications,omitempty"` 124 125 // +optional 126 SnapshotVolumes *SnapshotVolumesLists `json:"snapshotVolumes,omitempty"` 127 } 128 129 // SnapshotVolumesLists includes the list of volumes which were included in the snapshot and volumes which were excluded from the snapshot 130 type SnapshotVolumesLists struct { 131 // +optional 132 // +listType=set 133 IncludedVolumes []string `json:"includedVolumes,omitempty"` 134 135 // +optional 136 // +listType=set 137 ExcludedVolumes []string `json:"excludedVolumes,omitempty"` 138 } 139 140 // Error is the last error encountered during the snapshot/restore 141 type Error struct { 142 // +optional 143 Time *metav1.Time `json:"time,omitempty"` 144 145 // +optional 146 Message *string `json:"message,omitempty"` 147 } 148 149 // ConditionType is the const type for Conditions 150 type ConditionType string 151 152 const ( 153 // ConditionReady is the "ready" condition type 154 ConditionReady ConditionType = "Ready" 155 156 // ConditionProgressing is the "progressing" condition type 157 ConditionProgressing ConditionType = "Progressing" 158 159 // ConditionFailure is the "failure" condition type 160 ConditionFailure ConditionType = "Failure" 161 ) 162 163 // Condition defines conditions 164 type Condition struct { 165 Type ConditionType `json:"type"` 166 167 Status corev1.ConditionStatus `json:"status"` 168 169 // +optional 170 // +nullable 171 LastProbeTime metav1.Time `json:"lastProbeTime,omitempty"` 172 173 // +optional 174 // +nullable 175 LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"` 176 177 // +optional 178 Reason string `json:"reason,omitempty"` 179 180 // +optional 181 Message string `json:"message,omitempty"` 182 } 183 184 // VirtualMachineSnapshotList is a list of VirtualMachineSnapshot resources 185 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 186 type VirtualMachineSnapshotList struct { 187 metav1.TypeMeta `json:",inline"` 188 metav1.ListMeta `json:"metadata"` 189 190 Items []VirtualMachineSnapshot `json:"items"` 191 } 192 193 // VirtualMachineSnapshotContent contains the snapshot data 194 // +genclient 195 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 196 type VirtualMachineSnapshotContent struct { 197 metav1.TypeMeta `json:",inline"` 198 metav1.ObjectMeta `json:"metadata,omitempty"` 199 200 Spec VirtualMachineSnapshotContentSpec `json:"spec"` 201 202 // +optional 203 Status *VirtualMachineSnapshotContentStatus `json:"status,omitempty"` 204 } 205 206 // VirtualMachineSnapshotContentSpec is the spec for a VirtualMachineSnapshotContent resource 207 type VirtualMachineSnapshotContentSpec struct { 208 VirtualMachineSnapshotName *string `json:"virtualMachineSnapshotName,omitempty"` 209 210 Source SourceSpec `json:"source"` 211 212 // +optional 213 VolumeBackups []VolumeBackup `json:"volumeBackups,omitempty"` 214 } 215 216 type VirtualMachine struct { 217 // +kubebuilder:pruning:PreserveUnknownFields 218 // +nullable 219 metav1.ObjectMeta `json:"metadata,omitempty"` 220 // VirtualMachineSpec contains the VirtualMachine specification. 221 Spec v1.VirtualMachineSpec `json:"spec,omitempty" valid:"required"` 222 // Status holds the current state of the controller and brief information 223 // about its associated VirtualMachineInstance 224 Status v1.VirtualMachineStatus `json:"status,omitempty"` 225 } 226 227 // SourceSpec contains the appropriate spec for the resource being snapshotted 228 type SourceSpec struct { 229 // +optional 230 VirtualMachine *VirtualMachine `json:"virtualMachine,omitempty"` 231 } 232 233 type PersistentVolumeClaim struct { 234 // Standard object's metadata. 235 // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata 236 // +kubebuilder:pruning:PreserveUnknownFields 237 // +optional 238 metav1.ObjectMeta `json:"metadata,omitempty"` 239 240 // Spec defines the desired characteristics of a volume requested by a pod author. 241 // More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims 242 // +optional 243 Spec corev1.PersistentVolumeClaimSpec `json:"spec,omitempty"` 244 } 245 246 // VolumeBackup contains the data neeed to restore a PVC 247 type VolumeBackup struct { 248 VolumeName string `json:"volumeName"` 249 250 PersistentVolumeClaim PersistentVolumeClaim `json:"persistentVolumeClaim"` 251 252 // +optional 253 VolumeSnapshotName *string `json:"volumeSnapshotName,omitempty"` 254 } 255 256 // VirtualMachineSnapshotContentStatus is the status for a VirtualMachineSnapshotStatus resource 257 type VirtualMachineSnapshotContentStatus struct { 258 // +optional 259 // +nullable 260 CreationTime *metav1.Time `json:"creationTime,omitempty"` 261 262 // +optional 263 ReadyToUse *bool `json:"readyToUse,omitempty"` 264 265 // +optional 266 Error *Error `json:"error,omitempty"` 267 268 // +optional 269 VolumeSnapshotStatus []VolumeSnapshotStatus `json:"volumeSnapshotStatus,omitempty"` 270 } 271 272 // VirtualMachineSnapshotContentList is a list of VirtualMachineSnapshot resources 273 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 274 type VirtualMachineSnapshotContentList struct { 275 metav1.TypeMeta `json:",inline"` 276 metav1.ListMeta `json:"metadata"` 277 278 Items []VirtualMachineSnapshotContent `json:"items"` 279 } 280 281 // VolumeSnapshotStatus is the status of a VolumeSnapshot 282 type VolumeSnapshotStatus struct { 283 VolumeSnapshotName string `json:"volumeSnapshotName"` 284 285 // +optional 286 // +nullable 287 CreationTime *metav1.Time `json:"creationTime,omitempty"` 288 289 // +optional 290 ReadyToUse *bool `json:"readyToUse,omitempty"` 291 292 // +optional 293 Error *Error `json:"error,omitempty"` 294 } 295 296 // VirtualMachineRestore defines the operation of restoring a VM 297 // +genclient 298 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 299 type VirtualMachineRestore struct { 300 metav1.TypeMeta `json:",inline"` 301 metav1.ObjectMeta `json:"metadata,omitempty"` 302 303 Spec VirtualMachineRestoreSpec `json:"spec"` 304 305 // +optional 306 Status *VirtualMachineRestoreStatus `json:"status,omitempty"` 307 } 308 309 // VirtualMachineRestoreSpec is the spec for a VirtualMachineRestoreresource 310 type VirtualMachineRestoreSpec struct { 311 // initially only VirtualMachine type supported 312 Target corev1.TypedLocalObjectReference `json:"target"` 313 314 VirtualMachineSnapshotName string `json:"virtualMachineSnapshotName"` 315 316 // If the target for the restore does not exist, it will be created. Patches holds JSON patches that would be 317 // applied to the target manifest before it's created. Patches should fit the target's Kind. 318 // 319 // Example for a patch: {"op": "replace", "path": "/metadata/name", "value": "new-vm-name"} 320 // 321 // +optional 322 // +listType=atomic 323 Patches []string `json:"patches,omitempty"` 324 } 325 326 // VirtualMachineRestoreStatus is the spec for a VirtualMachineRestoreresource 327 type VirtualMachineRestoreStatus struct { 328 // +optional 329 Restores []VolumeRestore `json:"restores,omitempty"` 330 331 // +optional 332 RestoreTime *metav1.Time `json:"restoreTime,omitempty"` 333 334 // +optional 335 DeletedDataVolumes []string `json:"deletedDataVolumes,omitempty"` 336 337 // +optional 338 Complete *bool `json:"complete,omitempty"` 339 340 // +optional 341 Conditions []Condition `json:"conditions,omitempty"` 342 } 343 344 // VolumeRestore contains the data neeed to restore a PVC 345 type VolumeRestore struct { 346 VolumeName string `json:"volumeName"` 347 348 PersistentVolumeClaimName string `json:"persistentVolumeClaim"` 349 350 VolumeSnapshotName string `json:"volumeSnapshotName"` 351 352 // +optional 353 DataVolumeName *string `json:"dataVolumeName,omitempty"` 354 } 355 356 // VirtualMachineRestoreList is a list of VirtualMachineRestore resources 357 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 358 type VirtualMachineRestoreList struct { 359 metav1.TypeMeta `json:",inline"` 360 metav1.ListMeta `json:"metadata"` 361 362 Items []VirtualMachineRestore `json:"items"` 363 }