...

Source file src/kubevirt.io/api/snapshot/v1beta1/types.go

Documentation: kubevirt.io/api/snapshot/v1beta1

     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 v1beta1
    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  	// +listType=atomic
   120  	Conditions []Condition `json:"conditions,omitempty"`
   121  
   122  	// +optional
   123  	// +listType=set
   124  	Indications []Indication `json:"indications,omitempty"`
   125  
   126  	// +optional
   127  	SnapshotVolumes *SnapshotVolumesLists `json:"snapshotVolumes,omitempty"`
   128  }
   129  
   130  // SnapshotVolumesLists includes the list of volumes which were included in the snapshot and volumes which were excluded from the snapshot
   131  type SnapshotVolumesLists struct {
   132  	// +optional
   133  	// +listType=set
   134  	IncludedVolumes []string `json:"includedVolumes,omitempty"`
   135  
   136  	// +optional
   137  	// +listType=set
   138  	ExcludedVolumes []string `json:"excludedVolumes,omitempty"`
   139  }
   140  
   141  // Error is the last error encountered during the snapshot/restore
   142  type Error struct {
   143  	// +optional
   144  	Time *metav1.Time `json:"time,omitempty"`
   145  
   146  	// +optional
   147  	Message *string `json:"message,omitempty"`
   148  }
   149  
   150  // ConditionType is the const type for Conditions
   151  type ConditionType string
   152  
   153  const (
   154  	// ConditionReady is the "ready" condition type
   155  	ConditionReady ConditionType = "Ready"
   156  
   157  	// ConditionProgressing is the "progressing" condition type
   158  	ConditionProgressing ConditionType = "Progressing"
   159  
   160  	// ConditionFailure is the "failure" condition type
   161  	ConditionFailure ConditionType = "Failure"
   162  )
   163  
   164  // Condition defines conditions
   165  type Condition struct {
   166  	Type ConditionType `json:"type"`
   167  
   168  	Status corev1.ConditionStatus `json:"status"`
   169  
   170  	// +optional
   171  	// +nullable
   172  	LastProbeTime metav1.Time `json:"lastProbeTime,omitempty"`
   173  
   174  	// +optional
   175  	// +nullable
   176  	LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
   177  
   178  	// +optional
   179  	Reason string `json:"reason,omitempty"`
   180  
   181  	// +optional
   182  	Message string `json:"message,omitempty"`
   183  }
   184  
   185  // VirtualMachineSnapshotList is a list of VirtualMachineSnapshot resources
   186  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
   187  type VirtualMachineSnapshotList struct {
   188  	metav1.TypeMeta `json:",inline"`
   189  	metav1.ListMeta `json:"metadata"`
   190  
   191  	Items []VirtualMachineSnapshot `json:"items"`
   192  }
   193  
   194  // VirtualMachineSnapshotContent contains the snapshot data
   195  // +genclient
   196  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
   197  type VirtualMachineSnapshotContent struct {
   198  	metav1.TypeMeta   `json:",inline"`
   199  	metav1.ObjectMeta `json:"metadata,omitempty"`
   200  
   201  	Spec VirtualMachineSnapshotContentSpec `json:"spec"`
   202  
   203  	// +optional
   204  	Status *VirtualMachineSnapshotContentStatus `json:"status,omitempty"`
   205  }
   206  
   207  // VirtualMachineSnapshotContentSpec is the spec for a VirtualMachineSnapshotContent resource
   208  type VirtualMachineSnapshotContentSpec struct {
   209  	VirtualMachineSnapshotName *string `json:"virtualMachineSnapshotName,omitempty"`
   210  
   211  	Source SourceSpec `json:"source"`
   212  
   213  	// +optional
   214  	// +listType=atomic
   215  	VolumeBackups []VolumeBackup `json:"volumeBackups,omitempty"`
   216  }
   217  
   218  type VirtualMachine struct {
   219  	// +kubebuilder:pruning:PreserveUnknownFields
   220  	// +nullable
   221  	metav1.ObjectMeta `json:"metadata,omitempty"`
   222  	// VirtualMachineSpec contains the VirtualMachine specification.
   223  	Spec v1.VirtualMachineSpec `json:"spec,omitempty" valid:"required"`
   224  	// Status holds the current state of the controller and brief information
   225  	// about its associated VirtualMachineInstance
   226  	Status v1.VirtualMachineStatus `json:"status,omitempty"`
   227  }
   228  
   229  // SourceSpec contains the appropriate spec for the resource being snapshotted
   230  type SourceSpec struct {
   231  	// +optional
   232  	VirtualMachine *VirtualMachine `json:"virtualMachine,omitempty"`
   233  }
   234  
   235  type PersistentVolumeClaim struct {
   236  	// Standard object's metadata.
   237  	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
   238  	// +kubebuilder:pruning:PreserveUnknownFields
   239  	// +optional
   240  	metav1.ObjectMeta `json:"metadata,omitempty"`
   241  
   242  	// Spec defines the desired characteristics of a volume requested by a pod author.
   243  	// More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims
   244  	// +optional
   245  	Spec corev1.PersistentVolumeClaimSpec `json:"spec,omitempty"`
   246  }
   247  
   248  // VolumeBackup contains the data neeed to restore a PVC
   249  type VolumeBackup struct {
   250  	VolumeName string `json:"volumeName"`
   251  
   252  	PersistentVolumeClaim PersistentVolumeClaim `json:"persistentVolumeClaim"`
   253  
   254  	// +optional
   255  	VolumeSnapshotName *string `json:"volumeSnapshotName,omitempty"`
   256  }
   257  
   258  // VirtualMachineSnapshotContentStatus is the status for a VirtualMachineSnapshotStatus resource
   259  type VirtualMachineSnapshotContentStatus struct {
   260  	// +optional
   261  	// +nullable
   262  	CreationTime *metav1.Time `json:"creationTime,omitempty"`
   263  
   264  	// +optional
   265  	ReadyToUse *bool `json:"readyToUse,omitempty"`
   266  
   267  	// +optional
   268  	Error *Error `json:"error,omitempty"`
   269  
   270  	// +optional
   271  	// +listType=atomic
   272  	VolumeSnapshotStatus []VolumeSnapshotStatus `json:"volumeSnapshotStatus,omitempty"`
   273  }
   274  
   275  // VirtualMachineSnapshotContentList is a list of VirtualMachineSnapshot resources
   276  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
   277  type VirtualMachineSnapshotContentList struct {
   278  	metav1.TypeMeta `json:",inline"`
   279  	metav1.ListMeta `json:"metadata"`
   280  
   281  	Items []VirtualMachineSnapshotContent `json:"items"`
   282  }
   283  
   284  // VolumeSnapshotStatus is the status of a VolumeSnapshot
   285  type VolumeSnapshotStatus struct {
   286  	VolumeSnapshotName string `json:"volumeSnapshotName"`
   287  
   288  	// +optional
   289  	// +nullable
   290  	CreationTime *metav1.Time `json:"creationTime,omitempty"`
   291  
   292  	// +optional
   293  	ReadyToUse *bool `json:"readyToUse,omitempty"`
   294  
   295  	// +optional
   296  	Error *Error `json:"error,omitempty"`
   297  }
   298  
   299  // VirtualMachineRestore defines the operation of restoring a VM
   300  // +genclient
   301  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
   302  type VirtualMachineRestore struct {
   303  	metav1.TypeMeta   `json:",inline"`
   304  	metav1.ObjectMeta `json:"metadata,omitempty"`
   305  
   306  	Spec VirtualMachineRestoreSpec `json:"spec"`
   307  
   308  	// +optional
   309  	Status *VirtualMachineRestoreStatus `json:"status,omitempty"`
   310  }
   311  
   312  // VirtualMachineRestoreSpec is the spec for a VirtualMachineRestoreresource
   313  type VirtualMachineRestoreSpec struct {
   314  	// initially only VirtualMachine type supported
   315  	Target corev1.TypedLocalObjectReference `json:"target"`
   316  
   317  	VirtualMachineSnapshotName string `json:"virtualMachineSnapshotName"`
   318  
   319  	// If the target for the restore does not exist, it will be created. Patches holds JSON patches that would be
   320  	// applied to the target manifest before it's created. Patches should fit the target's Kind.
   321  	//
   322  	// Example for a patch: {"op": "replace", "path": "/metadata/name", "value": "new-vm-name"}
   323  	//
   324  	// +optional
   325  	// +listType=atomic
   326  	Patches []string `json:"patches,omitempty"`
   327  }
   328  
   329  // VirtualMachineRestoreStatus is the spec for a VirtualMachineRestoreresource
   330  type VirtualMachineRestoreStatus struct {
   331  	// +optional
   332  	// +listType=atomic
   333  	Restores []VolumeRestore `json:"restores,omitempty"`
   334  
   335  	// +optional
   336  	RestoreTime *metav1.Time `json:"restoreTime,omitempty"`
   337  
   338  	// +optional
   339  	// +listType=set
   340  	DeletedDataVolumes []string `json:"deletedDataVolumes,omitempty"`
   341  
   342  	// +optional
   343  	Complete *bool `json:"complete,omitempty"`
   344  
   345  	// +optional
   346  	// +listType=atomic
   347  	Conditions []Condition `json:"conditions,omitempty"`
   348  }
   349  
   350  // VolumeRestore contains the data neeed to restore a PVC
   351  type VolumeRestore struct {
   352  	VolumeName string `json:"volumeName"`
   353  
   354  	PersistentVolumeClaimName string `json:"persistentVolumeClaim"`
   355  
   356  	VolumeSnapshotName string `json:"volumeSnapshotName"`
   357  
   358  	// +optional
   359  	DataVolumeName *string `json:"dataVolumeName,omitempty"`
   360  }
   361  
   362  // VirtualMachineRestoreList is a list of VirtualMachineRestore resources
   363  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
   364  type VirtualMachineRestoreList struct {
   365  	metav1.TypeMeta `json:",inline"`
   366  	metav1.ListMeta `json:"metadata"`
   367  
   368  	Items []VirtualMachineRestore `json:"items"`
   369  }
   370  

View as plain text