kubevirt.io/api@v1.2.0/instancetype/v1beta1/types.go (about) 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 2023 Red Hat, Inc. 17 * 18 */ 19 20 package v1beta1 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 // NodeSelector is a selector which must be true for the vmi to fit on a node. 78 // Selector which must match a node's labels for the vmi to be scheduled on that node. 79 // More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/ 80 // 81 // NodeSelector is the name of the custom node selector for the instancetype. 82 // +optional 83 NodeSelector map[string]string `json:"nodeSelector,omitempty"` 84 85 // If specified, the VMI will be dispatched by specified scheduler. 86 // If not specified, the VMI will be dispatched by default scheduler. 87 // 88 // SchedulerName is the name of the custom K8s scheduler for the instancetype. 89 // +optional 90 SchedulerName string `json:"schedulerName,omitempty"` 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 // Optionally defines the required Annotations to be used by the instance type and applied to the VirtualMachineInstance 121 // 122 // +optional 123 Annotations map[string]string `json:"annotations,omitempty"` 124 } 125 126 // CPUInstancetype contains the CPU related configuration of a given VirtualMachineInstancetypeSpec. 127 // 128 // Guest is a required attribute and defines the number of vCPUs to be exposed to the guest by the instancetype. 129 type CPUInstancetype struct { 130 131 // Required number of vCPUs to expose to the guest. 132 // 133 // The resulting CPU topology being derived from the optional PreferredCPUTopology attribute of CPUPreferences that itself defaults to PreferSockets. 134 Guest uint32 `json:"guest"` 135 136 // Model specifies the CPU model inside the VMI. 137 // List of available models https://github.com/libvirt/libvirt/tree/master/src/cpu_map. 138 // It is possible to specify special cases like "host-passthrough" to get the same CPU as the node 139 // and "host-model" to get CPU closest to the node one. 140 // Defaults to host-model. 141 // +optional 142 Model *string `json:"model,omitempty"` 143 144 // DedicatedCPUPlacement requests the scheduler to place the VirtualMachineInstance on a node 145 // with enough dedicated pCPUs and pin the vCPUs to it. 146 // +optional 147 DedicatedCPUPlacement *bool `json:"dedicatedCPUPlacement,omitempty"` 148 149 // NUMA allows specifying settings for the guest NUMA topology 150 // +optional 151 NUMA *v1.NUMA `json:"numa,omitempty"` 152 153 // IsolateEmulatorThread requests one more dedicated pCPU to be allocated for the VMI to place 154 // the emulator thread on it. 155 // +optional 156 IsolateEmulatorThread *bool `json:"isolateEmulatorThread,omitempty"` 157 158 // Realtime instructs the virt-launcher to tune the VMI for lower latency, optional for real time workloads 159 // +optional 160 Realtime *v1.Realtime `json:"realtime,omitempty"` 161 } 162 163 // MemoryInstancetype contains the Memory related configuration of a given VirtualMachineInstancetypeSpec. 164 // 165 // Guest is a required attribute and defines the amount of RAM to be exposed to the guest by the instancetype. 166 type MemoryInstancetype struct { 167 168 // Required amount of memory which is visible inside the guest OS. 169 Guest resource.Quantity `json:"guest"` 170 171 // Optionally enables the use of hugepages for the VirtualMachineInstance instead of regular memory. 172 // +optional 173 Hugepages *v1.Hugepages `json:"hugepages,omitempty"` 174 // OvercommitPercent is the percentage of the guest memory which will be overcommitted. 175 // This means that the VMIs parent pod (virt-launcher) will request less 176 // physical memory by a factor specified by the OvercommitPercent. 177 // Overcommits can lead to memory exhaustion, which in turn can lead to crashes. Use carefully. 178 // Defaults to 0 179 // +optional 180 // +kubebuilder:validation:Maximum=100 181 // +kubebuilder:validation:Minimum=0 182 OvercommitPercent int `json:"overcommitPercent,omitempty"` 183 } 184 185 // VirtualMachinePreference resource contains optional preferences related to the VirtualMachine. 186 // 187 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 188 // +genclient 189 type VirtualMachinePreference struct { 190 metav1.TypeMeta `json:",inline"` 191 metav1.ObjectMeta `json:"metadata,omitempty"` 192 193 // Required spec describing the preferences 194 Spec VirtualMachinePreferenceSpec `json:"spec"` 195 } 196 197 // VirtualMachinePreferenceList is a list of VirtualMachinePreference resources. 198 // 199 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 200 type VirtualMachinePreferenceList struct { 201 metav1.TypeMeta `json:",inline"` 202 metav1.ListMeta `json:"metadata,omitempty"` 203 // +listType=set 204 Items []VirtualMachinePreference `json:"items"` 205 } 206 207 // VirtualMachineClusterPreference is a cluster scoped version of the VirtualMachinePreference resource. 208 // 209 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 210 // +genclient 211 // +genclient:nonNamespaced 212 type VirtualMachineClusterPreference struct { 213 metav1.TypeMeta `json:",inline"` 214 metav1.ObjectMeta `json:"metadata,omitempty"` 215 216 // Required spec describing the preferences 217 Spec VirtualMachinePreferenceSpec `json:"spec"` 218 } 219 220 // VirtualMachineClusterPreferenceList is a list of VirtualMachineClusterPreference resources. 221 // 222 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 223 type VirtualMachineClusterPreferenceList struct { 224 metav1.TypeMeta `json:",inline"` 225 metav1.ListMeta `json:"metadata,omitempty"` 226 // +listType=set 227 Items []VirtualMachineClusterPreference `json:"items"` 228 } 229 230 // VirtualMachinePreferenceSpec is a description of the VirtualMachinePreference or VirtualMachineClusterPreference. 231 type VirtualMachinePreferenceSpec struct { 232 233 // Clock optionally defines preferences associated with the Clock attribute of a VirtualMachineInstance DomainSpec 234 // 235 //+optional 236 Clock *ClockPreferences `json:"clock,omitempty"` 237 238 // CPU optionally defines preferences associated with the CPU attribute of a VirtualMachineInstance DomainSpec 239 // 240 //+optional 241 CPU *CPUPreferences `json:"cpu,omitempty"` 242 243 // Devices optionally defines preferences associated with the Devices attribute of a VirtualMachineInstance DomainSpec 244 // 245 //+optional 246 Devices *DevicePreferences `json:"devices,omitempty"` 247 248 // Features optionally defines preferences associated with the Features attribute of a VirtualMachineInstance DomainSpec 249 // 250 //+optional 251 Features *FeaturePreferences `json:"features,omitempty"` 252 253 // Firmware optionally defines preferences associated with the Firmware attribute of a VirtualMachineInstance DomainSpec 254 // 255 //+optional 256 Firmware *FirmwarePreferences `json:"firmware,omitempty"` 257 258 // Machine optionally defines preferences associated with the Machine attribute of a VirtualMachineInstance DomainSpec 259 // 260 //+optional 261 Machine *MachinePreferences `json:"machine,omitempty"` 262 263 // Volumes optionally defines preferences associated with the Volumes attribute of a VirtualMachineInstace DomainSpec 264 // 265 //+optional 266 Volumes *VolumePreferences `json:"volumes,omitempty"` 267 268 // Subdomain of the VirtualMachineInstance 269 // 270 //+optional 271 PreferredSubdomain *string `json:"preferredSubdomain,omitempty"` 272 273 // Grace period observed after signalling a VirtualMachineInstance to stop after which the VirtualMachineInstance is force terminated. 274 // 275 //+optional 276 PreferredTerminationGracePeriodSeconds *int64 `json:"preferredTerminationGracePeriodSeconds,omitempty"` 277 278 // Requirements defines the minium amount of instance type defined resources required by a set of preferences 279 // 280 //+optional 281 Requirements *PreferenceRequirements `json:"requirements,omitempty"` 282 283 // Optionally defines preferred Annotations to be applied to the VirtualMachineInstance 284 // 285 //+optional 286 Annotations map[string]string `json:"annotations,omitempty"` 287 288 // PreferSpreadSocketToCoreRatio defines the ratio to spread vCPUs between cores and sockets, it defaults to 2. 289 // 290 //+optional 291 PreferSpreadSocketToCoreRatio uint32 `json:"preferSpreadSocketToCoreRatio,omitempty"` 292 } 293 294 type VolumePreferences struct { 295 296 // PreffereedStorageClassName optionally defines the preferred storageClass 297 // 298 //+optional 299 PreferredStorageClassName string `json:"preferredStorageClassName,omitempty"` 300 } 301 302 // PreferredCPUTopology defines a preferred CPU topology to be exposed to the guest 303 type PreferredCPUTopology string 304 305 const ( 306 307 // Prefer vCPUs to be exposed as cores to the guest 308 PreferCores PreferredCPUTopology = "preferCores" 309 310 // Prefer vCPUs to be exposed as sockets to the guest, this is the default for the PreferredCPUTopology attribute of CPUPreferences. 311 PreferSockets PreferredCPUTopology = "preferSockets" 312 313 // Prefer vCPUs to be exposed as threads to the guest 314 PreferThreads PreferredCPUTopology = "preferThreads" 315 316 // Prefer vCPUs to be spread evenly between cores and sockets with any remaining vCPUs being presented as cores 317 PreferSpread PreferredCPUTopology = "preferSpread" 318 319 // Prefer vCPUs to be spread according to VirtualMachineInstanceTemplateSpec 320 // 321 // If used with VirtualMachineInstanceType it will use sockets as default 322 PreferAny PreferredCPUTopology = "preferAny" 323 ) 324 325 // CPUPreferences contains various optional CPU preferences. 326 type CPUPreferences struct { 327 328 // PreferredCPUTopology optionally defines the preferred guest visible CPU topology, defaults to PreferSockets. 329 // 330 //+optional 331 PreferredCPUTopology *PreferredCPUTopology `json:"preferredCPUTopology,omitempty"` 332 333 // PreferredCPUFeatures optionally defines a slice of preferred CPU features. 334 // 335 //+optional 336 PreferredCPUFeatures []v1.CPUFeature `json:"preferredCPUFeatures,omitempty"` 337 } 338 339 // DevicePreferences contains various optional Device preferences. 340 type DevicePreferences struct { 341 342 // PreferredAutoattachGraphicsDevice optionally defines the preferred value of AutoattachGraphicsDevice 343 // 344 // +optional 345 PreferredAutoattachGraphicsDevice *bool `json:"preferredAutoattachGraphicsDevice,omitempty"` 346 347 // PreferredAutoattachMemBalloon optionally defines the preferred value of AutoattachMemBalloon 348 // 349 // +optional 350 PreferredAutoattachMemBalloon *bool `json:"preferredAutoattachMemBalloon,omitempty"` 351 352 // PreferredAutoattachPodInterface optionally defines the preferred value of AutoattachPodInterface 353 // 354 // +optional 355 PreferredAutoattachPodInterface *bool `json:"preferredAutoattachPodInterface,omitempty"` 356 357 // PreferredAutoattachSerialConsole optionally defines the preferred value of AutoattachSerialConsole 358 // 359 // +optional 360 PreferredAutoattachSerialConsole *bool `json:"preferredAutoattachSerialConsole,omitempty"` 361 362 // PreferredAutoattachInputDevice optionally defines the preferred value of AutoattachInputDevice 363 // 364 // +optional 365 PreferredAutoattachInputDevice *bool `json:"preferredAutoattachInputDevice,omitempty"` 366 367 // PreferredDisableHotplug optionally defines the preferred value of DisableHotplug 368 // 369 // +optional 370 PreferredDisableHotplug *bool `json:"preferredDisableHotplug,omitempty"` 371 372 // PreferredVirtualGPUOptions optionally defines the preferred value of VirtualGPUOptions 373 // 374 // +optional 375 PreferredVirtualGPUOptions *v1.VGPUOptions `json:"preferredVirtualGPUOptions,omitempty"` 376 377 // PreferredSoundModel optionally defines the preferred model for Sound devices. 378 // 379 // +optional 380 PreferredSoundModel string `json:"preferredSoundModel,omitempty"` 381 382 // PreferredUseVirtioTransitional optionally defines the preferred value of UseVirtioTransitional 383 // 384 // +optional 385 PreferredUseVirtioTransitional *bool `json:"preferredUseVirtioTransitional,omitempty"` 386 387 // PreferredInputBus optionally defines the preferred bus for Input devices. 388 // 389 // +optional 390 PreferredInputBus v1.InputBus `json:"preferredInputBus,omitempty"` 391 392 // PreferredInputType optionally defines the preferred type for Input devices. 393 // 394 // +optional 395 PreferredInputType v1.InputType `json:"preferredInputType,omitempty"` 396 397 // PreferredDiskBus optionally defines the preferred bus for Disk Disk devices. 398 // 399 // +optional 400 PreferredDiskBus v1.DiskBus `json:"preferredDiskBus,omitempty"` 401 402 // PreferredLunBus optionally defines the preferred bus for Lun Disk devices. 403 // 404 // +optional 405 PreferredLunBus v1.DiskBus `json:"preferredLunBus,omitempty"` 406 407 // PreferredCdromBus optionally defines the preferred bus for Cdrom Disk devices. 408 // 409 // +optional 410 PreferredCdromBus v1.DiskBus `json:"preferredCdromBus,omitempty"` 411 412 // PreferredDedicatedIoThread optionally enables dedicated IO threads for Disk devices. 413 // 414 // +optional 415 PreferredDiskDedicatedIoThread *bool `json:"preferredDiskDedicatedIoThread,omitempty"` 416 417 // PreferredCache optionally defines the DriverCache to be used by Disk devices. 418 // 419 // +optional 420 PreferredDiskCache v1.DriverCache `json:"preferredDiskCache,omitempty"` 421 422 // PreferredIo optionally defines the QEMU disk IO mode to be used by Disk devices. 423 // 424 // +optional 425 PreferredDiskIO v1.DriverIO `json:"preferredDiskIO,omitempty"` 426 427 // PreferredBlockSize optionally defines the block size of Disk devices. 428 // 429 // +optional 430 PreferredDiskBlockSize *v1.BlockSize `json:"preferredDiskBlockSize,omitempty"` 431 432 // PreferredInterfaceModel optionally defines the preferred model to be used by Interface devices. 433 // 434 // +optional 435 PreferredInterfaceModel string `json:"preferredInterfaceModel,omitempty"` 436 437 // PreferredRng optionally defines the preferred rng device to be used. 438 // 439 // +optional 440 PreferredRng *v1.Rng `json:"preferredRng,omitempty"` 441 442 // PreferredBlockMultiQueue optionally enables the vhost multiqueue feature for virtio disks. 443 // 444 // +optional 445 PreferredBlockMultiQueue *bool `json:"preferredBlockMultiQueue,omitempty"` 446 447 // PreferredNetworkInterfaceMultiQueue optionally enables the vhost multiqueue feature for virtio interfaces. 448 // 449 // +optional 450 PreferredNetworkInterfaceMultiQueue *bool `json:"preferredNetworkInterfaceMultiQueue,omitempty"` 451 452 // PreferredTPM optionally defines the preferred TPM device to be used. 453 // 454 // +optional 455 PreferredTPM *v1.TPMDevice `json:"preferredTPM,omitempty"` 456 457 // PreferredInterfaceMasquerade optionally defines the preferred masquerade configuration to use with each network interface. 458 // 459 // +optional 460 PreferredInterfaceMasquerade *v1.InterfaceMasquerade `json:"preferredInterfaceMasquerade,omitempty"` 461 } 462 463 // FeaturePreferences contains various optional defaults for Features. 464 type FeaturePreferences struct { 465 466 // PreferredAcpi optionally enables the ACPI feature 467 // 468 // +optional 469 PreferredAcpi *v1.FeatureState `json:"preferredAcpi,omitempty"` 470 471 // PreferredApic optionally enables and configures the APIC feature 472 // 473 // +optional 474 PreferredApic *v1.FeatureAPIC `json:"preferredApic,omitempty"` 475 476 // PreferredHyperv optionally enables and configures HyperV features 477 // 478 // +optional 479 PreferredHyperv *v1.FeatureHyperv `json:"preferredHyperv,omitempty"` 480 481 // PreferredKvm optionally enables and configures KVM features 482 // 483 // +optional 484 PreferredKvm *v1.FeatureKVM `json:"preferredKvm,omitempty"` 485 486 // PreferredPvspinlock optionally enables the Pvspinlock feature 487 // 488 // +optional 489 PreferredPvspinlock *v1.FeatureState `json:"preferredPvspinlock,omitempty"` 490 491 // PreferredSmm optionally enables the SMM feature 492 // 493 // +optional 494 PreferredSmm *v1.FeatureState `json:"preferredSmm,omitempty"` 495 } 496 497 // FirmwarePreferences contains various optional defaults for Firmware. 498 type FirmwarePreferences struct { 499 500 // PreferredUseBios optionally enables BIOS 501 // 502 // +optional 503 PreferredUseBios *bool `json:"preferredUseBios,omitempty"` 504 505 // PreferredUseBiosSerial optionally transmitts BIOS output over the serial. 506 // 507 // Requires PreferredUseBios to be enabled. 508 // 509 // +optional 510 PreferredUseBiosSerial *bool `json:"preferredUseBiosSerial,omitempty"` 511 512 // PreferredUseEfi optionally enables EFI 513 // 514 // +optional 515 PreferredUseEfi *bool `json:"preferredUseEfi,omitempty"` 516 517 // PreferredUseSecureBoot optionally enables SecureBoot and the OVMF roms will be swapped for SecureBoot-enabled ones. 518 // 519 // Requires PreferredUseEfi and PreferredSmm to be enabled. 520 // 521 // +optional 522 PreferredUseSecureBoot *bool `json:"preferredUseSecureBoot,omitempty"` 523 } 524 525 // MachinePreferences contains various optional defaults for Machine. 526 type MachinePreferences struct { 527 528 // PreferredMachineType optionally defines the preferred machine type to use. 529 // 530 // +optional 531 PreferredMachineType string `json:"preferredMachineType,omitempty"` 532 } 533 534 // ClockPreferences contains various optional defaults for Clock. 535 type ClockPreferences struct { 536 537 // ClockOffset allows specifying the UTC offset or the timezone of the guest clock. 538 // 539 // +optional 540 PreferredClockOffset *v1.ClockOffset `json:"preferredClockOffset,omitempty"` 541 542 // Timer specifies whih timers are attached to the vmi. 543 // 544 // +optional 545 PreferredTimer *v1.Timer `json:"preferredTimer,omitempty"` 546 } 547 548 type PreferenceRequirements struct { 549 550 // Required CPU related attributes of the instancetype. 551 // 552 //+optional 553 CPU *CPUPreferenceRequirement `json:"cpu,omitempty"` 554 555 // Required Memory related attributes of the instancetype. 556 // 557 //+optional 558 Memory *MemoryPreferenceRequirement `json:"memory,omitempty"` 559 } 560 561 type CPUPreferenceRequirement struct { 562 563 // Minimal number of vCPUs required by the preference. 564 Guest uint32 `json:"guest"` 565 } 566 567 type MemoryPreferenceRequirement struct { 568 569 // Minimal amount of memory required by the preference. 570 Guest resource.Quantity `json:"guest"` 571 }