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 v1alpha2 21 22 import ( 23 "k8s.io/apimachinery/pkg/api/resource" 24 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 25 26 v1 "kubevirt.io/api/core/v1" 27 ) 28 29 // VirtualMachineInstancetype resource contains quantitative and resource related VirtualMachine configuration 30 // that can be used by multiple VirtualMachine resources. 31 // 32 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 33 // +genclient 34 type VirtualMachineInstancetype struct { 35 metav1.TypeMeta `json:",inline"` 36 metav1.ObjectMeta `json:"metadata,omitempty"` 37 38 // Required spec describing the instancetype 39 Spec VirtualMachineInstancetypeSpec `json:"spec"` 40 } 41 42 // VirtualMachineInstancetypeList is a list of VirtualMachineInstancetype resources. 43 // 44 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 45 type VirtualMachineInstancetypeList struct { 46 metav1.TypeMeta `json:",inline"` 47 metav1.ListMeta `json:"metadata,omitempty"` 48 Items []VirtualMachineInstancetype `json:"items"` 49 } 50 51 // VirtualMachineClusterInstancetype is a cluster scoped version of VirtualMachineInstancetype resource. 52 // 53 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 54 // +genclient 55 // +genclient:nonNamespaced 56 type VirtualMachineClusterInstancetype struct { 57 metav1.TypeMeta `json:",inline"` 58 metav1.ObjectMeta `json:"metadata,omitempty"` 59 60 // Required spec describing the instancetype 61 Spec VirtualMachineInstancetypeSpec `json:"spec"` 62 } 63 64 // VirtualMachineClusterInstancetypeList is a list of VirtualMachineClusterInstancetype resources. 65 // 66 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 67 type VirtualMachineClusterInstancetypeList struct { 68 metav1.TypeMeta `json:",inline"` 69 metav1.ListMeta `json:"metadata,omitempty"` 70 Items []VirtualMachineClusterInstancetype `json:"items"` 71 } 72 73 // VirtualMachineInstancetypeSpec is a description of the VirtualMachineInstancetype or VirtualMachineClusterInstancetype. 74 // 75 // CPU and Memory are required attributes with both requiring that their Guest attribute is defined, ensuring a number of vCPUs and amount of RAM is always provided by each instancetype. 76 type VirtualMachineInstancetypeSpec struct { 77 78 // Required CPU related attributes of the instancetype. 79 CPU CPUInstancetype `json:"cpu"` 80 81 // Required Memory related attributes of the instancetype. 82 Memory MemoryInstancetype `json:"memory"` 83 84 // Optionally defines any GPU devices associated with the instancetype. 85 // 86 // +optional 87 // +listType=atomic 88 GPUs []v1.GPU `json:"gpus,omitempty"` 89 90 // Optionally defines any HostDevices associated with the instancetype. 91 // 92 // +optional 93 // +listType=atomic 94 HostDevices []v1.HostDevice `json:"hostDevices,omitempty"` 95 96 // Optionally defines the IOThreadsPolicy to be used by the instancetype. 97 // 98 // +optional 99 IOThreadsPolicy *v1.IOThreadsPolicy `json:"ioThreadsPolicy,omitempty"` 100 101 // Optionally defines the LaunchSecurity to be used by the instancetype. 102 // 103 // +optional 104 LaunchSecurity *v1.LaunchSecurity `json:"launchSecurity,omitempty"` 105 } 106 107 // CPUInstancetype contains the CPU related configuration of a given VirtualMachineInstancetypeSpec. 108 // 109 // Guest is a required attribute and defines the number of vCPUs to be exposed to the guest by the instancetype. 110 type CPUInstancetype struct { 111 112 // Required number of vCPUs to expose to the guest. 113 // 114 // The resulting CPU topology being derived from the optional PreferredCPUTopology attribute of CPUPreferences that itself defaults to PreferSockets. 115 Guest uint32 `json:"guest"` 116 117 // Model specifies the CPU model inside the VMI. 118 // List of available models https://github.com/libvirt/libvirt/tree/master/src/cpu_map. 119 // It is possible to specify special cases like "host-passthrough" to get the same CPU as the node 120 // and "host-model" to get CPU closest to the node one. 121 // Defaults to host-model. 122 // +optional 123 Model string `json:"model,omitempty"` 124 125 // DedicatedCPUPlacement requests the scheduler to place the VirtualMachineInstance on a node 126 // with enough dedicated pCPUs and pin the vCPUs to it. 127 // +optional 128 DedicatedCPUPlacement bool `json:"dedicatedCPUPlacement,omitempty"` 129 130 // NUMA allows specifying settings for the guest NUMA topology 131 // +optional 132 NUMA *v1.NUMA `json:"numa,omitempty"` 133 134 // IsolateEmulatorThread requests one more dedicated pCPU to be allocated for the VMI to place 135 // the emulator thread on it. 136 // +optional 137 IsolateEmulatorThread bool `json:"isolateEmulatorThread,omitempty"` 138 139 // Realtime instructs the virt-launcher to tune the VMI for lower latency, optional for real time workloads 140 // +optional 141 Realtime *v1.Realtime `json:"realtime,omitempty"` 142 } 143 144 // MemoryInstancetype contains the Memory related configuration of a given VirtualMachineInstancetypeSpec. 145 // 146 // Guest is a required attribute and defines the amount of RAM to be exposed to the guest by the instancetype. 147 type MemoryInstancetype struct { 148 149 // Required amount of memory which is visible inside the guest OS. 150 Guest resource.Quantity `json:"guest"` 151 152 // Optionally enables the use of hugepages for the VirtualMachineInstance instead of regular memory. 153 // +optional 154 Hugepages *v1.Hugepages `json:"hugepages,omitempty"` 155 } 156 157 // VirtualMachinePreference resource contains optional preferences related to the VirtualMachine. 158 // 159 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 160 // +genclient 161 type VirtualMachinePreference struct { 162 metav1.TypeMeta `json:",inline"` 163 metav1.ObjectMeta `json:"metadata,omitempty"` 164 165 // Required spec describing the preferences 166 Spec VirtualMachinePreferenceSpec `json:"spec"` 167 } 168 169 // VirtualMachinePreferenceList is a list of VirtualMachinePreference resources. 170 // 171 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 172 type VirtualMachinePreferenceList struct { 173 metav1.TypeMeta `json:",inline"` 174 metav1.ListMeta `json:"metadata,omitempty"` 175 // +listType=set 176 Items []VirtualMachinePreference `json:"items"` 177 } 178 179 // VirtualMachineClusterPreference is a cluster scoped version of the VirtualMachinePreference resource. 180 // 181 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 182 // +genclient 183 // +genclient:nonNamespaced 184 type VirtualMachineClusterPreference struct { 185 metav1.TypeMeta `json:",inline"` 186 metav1.ObjectMeta `json:"metadata,omitempty"` 187 188 // Required spec describing the preferences 189 Spec VirtualMachinePreferenceSpec `json:"spec"` 190 } 191 192 // VirtualMachineClusterPreferenceList is a list of VirtualMachineClusterPreference resources. 193 // 194 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 195 type VirtualMachineClusterPreferenceList struct { 196 metav1.TypeMeta `json:",inline"` 197 metav1.ListMeta `json:"metadata,omitempty"` 198 // +listType=set 199 Items []VirtualMachineClusterPreference `json:"items"` 200 } 201 202 // VirtualMachinePreferenceSpec is a description of the VirtualMachinePreference or VirtualMachineClusterPreference. 203 type VirtualMachinePreferenceSpec struct { 204 205 // Clock optionally defines preferences associated with the Clock attribute of a VirtualMachineInstance DomainSpec 206 // 207 //+optional 208 Clock *ClockPreferences `json:"clock,omitempty"` 209 210 // CPU optionally defines preferences associated with the CPU attribute of a VirtualMachineInstance DomainSpec 211 // 212 //+optional 213 CPU *CPUPreferences `json:"cpu,omitempty"` 214 215 // Devices optionally defines preferences associated with the Devices attribute of a VirtualMachineInstance DomainSpec 216 // 217 //+optional 218 Devices *DevicePreferences `json:"devices,omitempty"` 219 220 // Features optionally defines preferences associated with the Features attribute of a VirtualMachineInstance DomainSpec 221 // 222 //+optional 223 Features *FeaturePreferences `json:"features,omitempty"` 224 225 // Firmware optionally defines preferences associated with the Firmware attribute of a VirtualMachineInstance DomainSpec 226 // 227 //+optional 228 Firmware *FirmwarePreferences `json:"firmware,omitempty"` 229 230 // Machine optionally defines preferences associated with the Machine attribute of a VirtualMachineInstance DomainSpec 231 // 232 //+optional 233 Machine *MachinePreferences `json:"machine,omitempty"` 234 235 // Volumes optionally defines preferences associated with the Volumes attribute of a VirtualMachineInstace DomainSpec 236 // 237 //+optional 238 Volumes *VolumePreferences `json:"volumes,omitempty"` 239 } 240 241 type VolumePreferences struct { 242 243 // PreffereedStorageClassName optionally defines the preferred storageClass 244 // 245 //+optional 246 PreferredStorageClassName string `json:"preferredStorageClassName,omitempty"` 247 } 248 249 // PreferredCPUTopology defines a preferred CPU topology to be exposed to the guest 250 type PreferredCPUTopology string 251 252 const ( 253 254 // Prefer vCPUs to be exposed as cores to the guest 255 PreferCores PreferredCPUTopology = "preferCores" 256 257 // Prefer vCPUs to be exposed as sockets to the guest, this is the default for the PreferredCPUTopology attribute of CPUPreferences. 258 PreferSockets PreferredCPUTopology = "preferSockets" 259 260 // Prefer vCPUs to be exposed as threads to the guest 261 PreferThreads PreferredCPUTopology = "preferThreads" 262 ) 263 264 // CPUPreferences contains various optional CPU preferences. 265 type CPUPreferences struct { 266 267 // PreferredCPUTopology optionally defines the preferred guest visible CPU topology, defaults to PreferSockets. 268 // 269 //+optional 270 PreferredCPUTopology PreferredCPUTopology `json:"preferredCPUTopology,omitempty"` 271 } 272 273 // DevicePreferences contains various optional Device preferences. 274 type DevicePreferences struct { 275 276 // PreferredAutoattachGraphicsDevice optionally defines the preferred value of AutoattachGraphicsDevice 277 // 278 // +optional 279 PreferredAutoattachGraphicsDevice *bool `json:"preferredAutoattachGraphicsDevice,omitempty"` 280 281 // PreferredAutoattachMemBalloon optionally defines the preferred value of AutoattachMemBalloon 282 // 283 // +optional 284 PreferredAutoattachMemBalloon *bool `json:"preferredAutoattachMemBalloon,omitempty"` 285 286 // PreferredAutoattachPodInterface optionally defines the preferred value of AutoattachPodInterface 287 // 288 // +optional 289 PreferredAutoattachPodInterface *bool `json:"preferredAutoattachPodInterface,omitempty"` 290 291 // PreferredAutoattachSerialConsole optionally defines the preferred value of AutoattachSerialConsole 292 // 293 // +optional 294 PreferredAutoattachSerialConsole *bool `json:"preferredAutoattachSerialConsole,omitempty"` 295 296 // PreferredAutoattachInputDevice optionally defines the preferred value of AutoattachInputDevice 297 // 298 // +optional 299 PreferredAutoattachInputDevice *bool `json:"preferredAutoattachInputDevice,omitempty"` 300 301 // PreferredDisableHotplug optionally defines the preferred value of DisableHotplug 302 // 303 // +optional 304 PreferredDisableHotplug *bool `json:"preferredDisableHotplug,omitempty"` 305 306 // PreferredVirtualGPUOptions optionally defines the preferred value of VirtualGPUOptions 307 // 308 // +optional 309 PreferredVirtualGPUOptions *v1.VGPUOptions `json:"preferredVirtualGPUOptions,omitempty"` 310 311 // PreferredSoundModel optionally defines the preferred model for Sound devices. 312 // 313 // +optional 314 PreferredSoundModel string `json:"preferredSoundModel,omitempty"` 315 316 // PreferredUseVirtioTransitional optionally defines the preferred value of UseVirtioTransitional 317 // 318 // +optional 319 PreferredUseVirtioTransitional *bool `json:"preferredUseVirtioTransitional,omitempty"` 320 321 // PreferredInputBus optionally defines the preferred bus for Input devices. 322 // 323 // +optional 324 PreferredInputBus v1.InputBus `json:"preferredInputBus,omitempty"` 325 326 // PreferredInputType optionally defines the preferred type for Input devices. 327 // 328 // +optional 329 PreferredInputType v1.InputType `json:"preferredInputType,omitempty"` 330 331 // PreferredDiskBus optionally defines the preferred bus for Disk Disk devices. 332 // 333 // +optional 334 PreferredDiskBus v1.DiskBus `json:"preferredDiskBus,omitempty"` 335 336 // PreferredLunBus optionally defines the preferred bus for Lun Disk devices. 337 // 338 // +optional 339 PreferredLunBus v1.DiskBus `json:"preferredLunBus,omitempty"` 340 341 // PreferredCdromBus optionally defines the preferred bus for Cdrom Disk devices. 342 // 343 // +optional 344 PreferredCdromBus v1.DiskBus `json:"preferredCdromBus,omitempty"` 345 346 // PreferredDedicatedIoThread optionally enables dedicated IO threads for Disk devices. 347 // 348 // +optional 349 PreferredDiskDedicatedIoThread *bool `json:"preferredDiskDedicatedIoThread,omitempty"` 350 351 // PreferredCache optionally defines the DriverCache to be used by Disk devices. 352 // 353 // +optional 354 PreferredDiskCache v1.DriverCache `json:"preferredDiskCache,omitempty"` 355 356 // PreferredIo optionally defines the QEMU disk IO mode to be used by Disk devices. 357 // 358 // +optional 359 PreferredDiskIO v1.DriverIO `json:"preferredDiskIO,omitempty"` 360 361 // PreferredBlockSize optionally defines the block size of Disk devices. 362 // 363 // +optional 364 PreferredDiskBlockSize *v1.BlockSize `json:"preferredDiskBlockSize,omitempty"` 365 366 // PreferredInterfaceModel optionally defines the preferred model to be used by Interface devices. 367 // 368 // +optional 369 PreferredInterfaceModel string `json:"preferredInterfaceModel,omitempty"` 370 371 // PreferredRng optionally defines the preferred rng device to be used. 372 // 373 // +optional 374 PreferredRng *v1.Rng `json:"preferredRng,omitempty"` 375 376 // PreferredBlockMultiQueue optionally enables the vhost multiqueue feature for virtio disks. 377 // 378 // +optional 379 PreferredBlockMultiQueue *bool `json:"preferredBlockMultiQueue,omitempty"` 380 381 // PreferredNetworkInterfaceMultiQueue optionally enables the vhost multiqueue feature for virtio interfaces. 382 // 383 // +optional 384 PreferredNetworkInterfaceMultiQueue *bool `json:"preferredNetworkInterfaceMultiQueue,omitempty"` 385 386 // PreferredTPM optionally defines the preferred TPM device to be used. 387 // 388 // +optional 389 PreferredTPM *v1.TPMDevice `json:"preferredTPM,omitempty"` 390 } 391 392 // FeaturePreferences contains various optional defaults for Features. 393 type FeaturePreferences struct { 394 395 // PreferredAcpi optionally enables the ACPI feature 396 // 397 // +optional 398 PreferredAcpi *v1.FeatureState `json:"preferredAcpi,omitempty"` 399 400 // PreferredApic optionally enables and configures the APIC feature 401 // 402 // +optional 403 PreferredApic *v1.FeatureAPIC `json:"preferredApic,omitempty"` 404 405 // PreferredHyperv optionally enables and configures HyperV features 406 // 407 // +optional 408 PreferredHyperv *v1.FeatureHyperv `json:"preferredHyperv,omitempty"` 409 410 // PreferredKvm optionally enables and configures KVM features 411 // 412 // +optional 413 PreferredKvm *v1.FeatureKVM `json:"preferredKvm,omitempty"` 414 415 // PreferredPvspinlock optionally enables the Pvspinlock feature 416 // 417 // +optional 418 PreferredPvspinlock *v1.FeatureState `json:"preferredPvspinlock,omitempty"` 419 420 // PreferredSmm optionally enables the SMM feature 421 // 422 // +optional 423 PreferredSmm *v1.FeatureState `json:"preferredSmm,omitempty"` 424 } 425 426 // FirmwarePreferences contains various optional defaults for Firmware. 427 type FirmwarePreferences struct { 428 429 // PreferredUseBios optionally enables BIOS 430 // 431 // +optional 432 PreferredUseBios *bool `json:"preferredUseBios,omitempty"` 433 434 // PreferredUseBiosSerial optionally transmitts BIOS output over the serial. 435 // 436 // Requires PreferredUseBios to be enabled. 437 // 438 // +optional 439 PreferredUseBiosSerial *bool `json:"preferredUseBiosSerial,omitempty"` 440 441 // PreferredUseEfi optionally enables EFI 442 // 443 // +optional 444 PreferredUseEfi *bool `json:"preferredUseEfi,omitempty"` 445 446 // PreferredUseSecureBoot optionally enables SecureBoot and the OVMF roms will be swapped for SecureBoot-enabled ones. 447 // 448 // Requires PreferredUseEfi and PreferredSmm to be enabled. 449 // 450 // +optional 451 PreferredUseSecureBoot *bool `json:"preferredUseSecureBoot,omitempty"` 452 } 453 454 // MachinePreferences contains various optional defaults for Machine. 455 type MachinePreferences struct { 456 457 // PreferredMachineType optionally defines the preferred machine type to use. 458 // 459 // +optional 460 PreferredMachineType string `json:"preferredMachineType,omitempty"` 461 } 462 463 // ClockPreferences contains various optional defaults for Clock. 464 type ClockPreferences struct { 465 466 // ClockOffset allows specifying the UTC offset or the timezone of the guest clock. 467 // 468 // +optional 469 PreferredClockOffset *v1.ClockOffset `json:"preferredClockOffset,omitempty"` 470 471 // Timer specifies whih timers are attached to the vmi. 472 // 473 // +optional 474 PreferredTimer *v1.Timer `json:"preferredTimer,omitempty"` 475 } 476