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 2022 Red Hat, Inc. 17 * 18 */ 19 20 package v1alpha1 21 22 import ( 23 corev1 "k8s.io/api/core/v1" 24 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 25 ) 26 27 // VirtualMachineClone is a CRD that clones one VM into another. 28 // 29 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 30 // +k8s:openapi-gen=true 31 // +genclient 32 type VirtualMachineClone struct { 33 metav1.TypeMeta `json:",inline"` 34 metav1.ObjectMeta `json:"metadata,omitempty"` 35 36 Spec VirtualMachineCloneSpec `json:"spec" valid:"required"` 37 Status VirtualMachineCloneStatus `json:"status,omitempty"` 38 } 39 40 type VirtualMachineCloneTemplateFilters struct { 41 // Example use: "!some/key*". 42 // For a detailed description, please refer to https://kubevirt.io/user-guide/operations/clone_api/#label-annotation-filters. 43 // +optional 44 // +listType=atomic 45 AnnotationFilters []string `json:"annotationFilters,omitempty"` 46 // Example use: "!some/key*". 47 // For a detailed description, please refer to https://kubevirt.io/user-guide/operations/clone_api/#label-annotation-filters. 48 // +optional 49 // +listType=atomic 50 LabelFilters []string `json:"labelFilters,omitempty"` 51 } 52 53 type VirtualMachineCloneSpec struct { 54 // Source is the object that would be cloned. Currently supported source types are: 55 // VirtualMachine of kubevirt.io API group, 56 // VirtualMachineSnapshot of snapshot.kubevirt.io API group 57 Source *corev1.TypedLocalObjectReference `json:"source"` 58 59 // Target is the outcome of the cloning process. 60 // Currently supported source types are: 61 // - VirtualMachine of kubevirt.io API group 62 // - Empty (nil). 63 // If the target is not provided, the target type would default to VirtualMachine and a random 64 // name would be generated for the target. The target's name can be viewed by 65 // inspecting status "TargetName" field below. 66 // +optional 67 Target *corev1.TypedLocalObjectReference `json:"target,omitempty"` 68 69 // Example use: "!some/key*". 70 // For a detailed description, please refer to https://kubevirt.io/user-guide/operations/clone_api/#label-annotation-filters. 71 // +optional 72 // +listType=atomic 73 AnnotationFilters []string `json:"annotationFilters,omitempty"` 74 // Example use: "!some/key*". 75 // For a detailed description, please refer to https://kubevirt.io/user-guide/operations/clone_api/#label-annotation-filters. 76 // +optional 77 // +listType=atomic 78 LabelFilters []string `json:"labelFilters,omitempty"` 79 // For a detailed description, please refer to https://kubevirt.io/user-guide/operations/clone_api/#label-annotation-filters. 80 // +optional 81 Template VirtualMachineCloneTemplateFilters `json:"template,omitempty"` 82 // NewMacAddresses manually sets that target interfaces' mac addresses. The key is the interface name and the 83 // value is the new mac address. If this field is not specified, a new MAC address will 84 // be generated automatically, as for any interface that is not included in this map. 85 // +optional 86 NewMacAddresses map[string]string `json:"newMacAddresses,omitempty"` 87 // NewSMBiosSerial manually sets that target's SMbios serial. If this field is not specified, a new serial will 88 // be generated automatically. 89 // +optional 90 NewSMBiosSerial *string `json:"newSMBiosSerial,omitempty"` 91 } 92 93 type VirtualMachineClonePhase string 94 95 const ( 96 PhaseUnset VirtualMachineClonePhase = "" 97 SnapshotInProgress VirtualMachineClonePhase = "SnapshotInProgress" 98 CreatingTargetVM VirtualMachineClonePhase = "CreatingTargetVM" 99 RestoreInProgress VirtualMachineClonePhase = "RestoreInProgress" 100 Succeeded VirtualMachineClonePhase = "Succeeded" 101 Failed VirtualMachineClonePhase = "Failed" 102 Unknown VirtualMachineClonePhase = "Unknown" 103 ) 104 105 type VirtualMachineCloneStatus struct { 106 // +optional 107 // +nullable 108 CreationTime *metav1.Time `json:"creationTime,omitempty"` 109 110 // +optional 111 Phase VirtualMachineClonePhase `json:"phase,omitempty"` 112 113 // +optional 114 // +listType=atomic 115 Conditions []Condition `json:"conditions,omitempty"` 116 117 // +optional 118 // +nullable 119 SnapshotName *string `json:"snapshotName,omitempty"` 120 121 // +optional 122 // +nullable 123 RestoreName *string `json:"restoreName,omitempty"` 124 125 // +optional 126 // +nullable 127 TargetName *string `json:"targetName,omitempty"` 128 } 129 130 // ConditionType is the const type for Conditions 131 type ConditionType string 132 133 const ( 134 // ConditionReady is the "ready" condition type 135 ConditionReady ConditionType = "Ready" 136 137 // ConditionProgressing is the "progressing" condition type 138 ConditionProgressing ConditionType = "Progressing" 139 ) 140 141 // Condition defines conditions 142 type Condition struct { 143 Type ConditionType `json:"type"` 144 145 Status corev1.ConditionStatus `json:"status"` 146 147 // +optional 148 // +nullable 149 LastProbeTime metav1.Time `json:"lastProbeTime,omitempty"` 150 151 // +optional 152 // +nullable 153 LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"` 154 155 // +optional 156 Reason string `json:"reason,omitempty"` 157 158 // +optional 159 Message string `json:"message,omitempty"` 160 } 161 162 // VirtualMachineCloneList is a list of MigrationPolicy 163 // 164 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 165 type VirtualMachineCloneList struct { 166 metav1.TypeMeta `json:",inline"` 167 metav1.ListMeta `json:"metadata,omitempty"` 168 // +listType=atomic 169 Items []VirtualMachineClone `json:"items"` 170 } 171