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