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 "time" 24 25 corev1 "k8s.io/api/core/v1" 26 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 27 ) 28 29 const ( 30 App = "virt-exporter" 31 DefaultDurationTTL = 2 * time.Hour 32 ) 33 34 // VirtualMachineExport defines the operation of exporting a VM source 35 // +genclient 36 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 37 type VirtualMachineExport struct { 38 metav1.TypeMeta `json:",inline"` 39 metav1.ObjectMeta `json:"metadata,omitempty"` 40 41 Spec VirtualMachineExportSpec `json:"spec"` 42 43 // +optional 44 Status *VirtualMachineExportStatus `json:"status,omitempty"` 45 } 46 47 // VirtualMachineExportList is a list of VirtualMachineExport resources 48 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 49 type VirtualMachineExportList struct { 50 metav1.TypeMeta `json:",inline"` 51 metav1.ListMeta `json:"metadata"` 52 // +listType=atomic 53 Items []VirtualMachineExport `json:"items"` 54 } 55 56 // VirtualMachineExportSpec is the spec for a VirtualMachineExport resource 57 type VirtualMachineExportSpec struct { 58 Source corev1.TypedLocalObjectReference `json:"source"` 59 60 // +optional 61 // TokenSecretRef is the name of the custom-defined secret that contains the token used by the export server pod 62 TokenSecretRef *string `json:"tokenSecretRef,omitempty"` 63 64 // ttlDuration limits the lifetime of an export 65 // If this field is set, after this duration has passed from counting from CreationTimestamp, 66 // the export is eligible to be automatically deleted. 67 // If this field is omitted, a reasonable default is applied. 68 // +optional 69 TTLDuration *metav1.Duration `json:"ttlDuration,omitempty"` 70 } 71 72 // VirtualMachineExportPhase is the current phase of the VirtualMachineExport 73 type VirtualMachineExportPhase string 74 75 const ( 76 // Pending means the Virtual Machine export is pending 77 Pending VirtualMachineExportPhase = "Pending" 78 // Ready means the Virtual Machine export is ready 79 Ready VirtualMachineExportPhase = "Ready" 80 // Terminated means the Virtual Machine export is terminated and no longer available 81 Terminated VirtualMachineExportPhase = "Terminated" 82 // Skipped means the export is invalid in a way so the exporter pod cannot start, and we are skipping creating the exporter server pod. 83 Skipped VirtualMachineExportPhase = "Skipped" 84 ) 85 86 // VirtualMachineExportStatus is the status for a VirtualMachineExport resource 87 type VirtualMachineExportStatus struct { 88 // +optional 89 Phase VirtualMachineExportPhase `json:"phase,omitempty"` 90 91 // +optional 92 Links *VirtualMachineExportLinks `json:"links,omitempty"` 93 94 // +optional 95 // TokenSecretRef is the name of the secret that contains the token used by the export server pod 96 TokenSecretRef *string `json:"tokenSecretRef,omitempty"` 97 98 // The time at which the VM Export will be completely removed according to specified TTL 99 // Formula is CreationTimestamp + TTL 100 TTLExpirationTime *metav1.Time `json:"ttlExpirationTime,omitempty"` 101 102 // +optional 103 // ServiceName is the name of the service created associated with the Virtual Machine export. It will be used to 104 // create the internal URLs for downloading the images 105 ServiceName string `json:"serviceName,omitempty"` 106 107 // +optional 108 // VirtualMachineName shows the name of the source virtual machine if the source is either a VirtualMachine or 109 // a VirtualMachineSnapshot. This is mainly to easily identify the source VirtualMachine in case of a 110 // VirtualMachineSnapshot 111 VirtualMachineName *string `json:"virtualMachineName,omitempty"` 112 113 // +optional 114 // +listType=atomic 115 Conditions []Condition `json:"conditions,omitempty"` 116 } 117 118 // VirtualMachineExportLinks contains the links that point the exported VM resources 119 type VirtualMachineExportLinks struct { 120 // +optional 121 Internal *VirtualMachineExportLink `json:"internal,omitempty"` 122 // +optional 123 External *VirtualMachineExportLink `json:"external,omitempty"` 124 } 125 126 // VirtualMachineExportLink contains a list of volumes available for export, as well as the URLs to obtain these volumes 127 type VirtualMachineExportLink struct { 128 // Cert is the public CA certificate base64 encoded 129 Cert string `json:"cert"` 130 131 // Volumes is a list of available volumes to export 132 // +listType=map 133 // +listMapKey=name 134 // +optional 135 Volumes []VirtualMachineExportVolume `json:"volumes,omitempty"` 136 137 // Manifests is a list of available manifests for the export 138 // +listType=map 139 // +listMapKey=type 140 // +optional 141 Manifests []VirtualMachineExportManifest `json:"manifests,omitempty"` 142 } 143 144 // VirtualMachineExportManifest contains the type and URL of the exported manifest 145 type VirtualMachineExportManifest struct { 146 // Type is the type of manifest returned 147 Type ExportManifestType `json:"type"` 148 149 // Url is the url of the endpoint that returns the manifest 150 Url string `json:"url"` 151 } 152 153 type ExportManifestType string 154 155 const ( 156 // AllManifests returns all manifests except for the token secret 157 AllManifests ExportManifestType = "all" 158 // AuthHeader returns a CDI compatible secret containing the token as an Auth header 159 AuthHeader ExportManifestType = "auth-header-secret" 160 ) 161 162 // VirtualMachineExportVolume contains the name and available formats for the exported volume 163 type VirtualMachineExportVolume struct { 164 // Name is the name of the exported volume 165 Name string `json:"name"` 166 // +listType=map 167 // +listMapKey=format 168 // +optional 169 Formats []VirtualMachineExportVolumeFormat `json:"formats,omitempty"` 170 } 171 172 type ExportVolumeFormat string 173 174 const ( 175 // KubeVirtRaw is the volume in RAW format 176 KubeVirtRaw ExportVolumeFormat = "raw" 177 // KubeVirtGZ is the volume in gzipped RAW format. 178 KubeVirtGz ExportVolumeFormat = "gzip" 179 // Dir is an uncompressed directory, which points to the root of a PersistentVolumeClaim, exposed using a FileServer https://pkg.go.dev/net/http#FileServer 180 Dir ExportVolumeFormat = "dir" 181 // ArchiveGz is a tarred and gzipped version of the root of a PersistentVolumeClaim 182 ArchiveGz ExportVolumeFormat = "tar.gz" 183 ) 184 185 // VirtualMachineExportVolumeFormat contains the format type and URL to get the volume in that format 186 type VirtualMachineExportVolumeFormat struct { 187 // Format is the format of the image at the specified URL 188 Format ExportVolumeFormat `json:"format"` 189 // Url is the url that contains the volume in the format specified 190 Url string `json:"url"` 191 } 192 193 // ConditionType is the const type for Conditions 194 type ConditionType string 195 196 const ( 197 // ConditionReady is the "ready" condition type 198 ConditionReady ConditionType = "Ready" 199 // ConditionPVC is the condition of the PVC we are exporting 200 ConditionPVC ConditionType = "PVCReady" 201 // ConditionVolumesCreated is the condition to see if volumes are created from volume snapshots 202 ConditionVolumesCreated ConditionType = "VolumesCreated" 203 ) 204 205 // Condition defines conditions 206 type Condition struct { 207 Type ConditionType `json:"type"` 208 209 Status corev1.ConditionStatus `json:"status"` 210 211 // +optional 212 // +nullable 213 LastProbeTime metav1.Time `json:"lastProbeTime,omitempty"` 214 215 // +optional 216 // +nullable 217 LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"` 218 219 // +optional 220 Reason string `json:"reason,omitempty"` 221 222 // +optional 223 Message string `json:"message,omitempty"` 224 } 225