k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/pkg/apis/resource/types.go (about) 1 /* 2 Copyright 2022 The Kubernetes Authors. 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 17 package resource 18 19 import ( 20 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 "k8s.io/apimachinery/pkg/runtime" 22 "k8s.io/apimachinery/pkg/types" 23 "k8s.io/kubernetes/pkg/apis/core" 24 ) 25 26 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 27 28 // ResourceClaim describes which resources are needed by a resource consumer. 29 // Its status tracks whether the resource has been allocated and what the 30 // resulting attributes are. 31 // 32 // This is an alpha type and requires enabling the DynamicResourceAllocation 33 // feature gate. 34 type ResourceClaim struct { 35 metav1.TypeMeta 36 // Standard object metadata 37 // +optional 38 metav1.ObjectMeta 39 40 // Spec describes the desired attributes of a resource that then needs 41 // to be allocated. It can only be set once when creating the 42 // ResourceClaim. 43 Spec ResourceClaimSpec 44 45 // Status describes whether the resource is available and with which 46 // attributes. 47 // +optional 48 Status ResourceClaimStatus 49 } 50 51 // ResourceClaimSpec defines how a resource is to be allocated. 52 type ResourceClaimSpec struct { 53 // ResourceClassName references the driver and additional parameters 54 // via the name of a ResourceClass that was created as part of the 55 // driver deployment. 56 ResourceClassName string 57 58 // ParametersRef references a separate object with arbitrary parameters 59 // that will be used by the driver when allocating a resource for the 60 // claim. 61 // 62 // The object must be in the same namespace as the ResourceClaim. 63 // +optional 64 ParametersRef *ResourceClaimParametersReference 65 66 // Allocation can start immediately or when a Pod wants to use the 67 // resource. "WaitForFirstConsumer" is the default. 68 // +optional 69 AllocationMode AllocationMode 70 } 71 72 // AllocationMode describes whether a ResourceClaim gets allocated immediately 73 // when it gets created (AllocationModeImmediate) or whether allocation is 74 // delayed until it is needed for a Pod 75 // (AllocationModeWaitForFirstConsumer). Other modes might get added in the 76 // future. 77 type AllocationMode string 78 79 const ( 80 // When a ResourceClaim has AllocationModeWaitForFirstConsumer, allocation is 81 // delayed until a Pod gets scheduled that needs the ResourceClaim. The 82 // scheduler will consider all resource requirements of that Pod and 83 // trigger allocation for a node that fits the Pod. 84 AllocationModeWaitForFirstConsumer AllocationMode = "WaitForFirstConsumer" 85 86 // When a ResourceClaim has AllocationModeImmediate, allocation starts 87 // as soon as the ResourceClaim gets created. This is done without 88 // considering the needs of Pods that will use the ResourceClaim 89 // because those Pods are not known yet. 90 AllocationModeImmediate AllocationMode = "Immediate" 91 ) 92 93 // ResourceClaimStatus tracks whether the resource has been allocated and what 94 // the resulting attributes are. 95 type ResourceClaimStatus struct { 96 // DriverName is a copy of the driver name from the ResourceClass at 97 // the time when allocation started. 98 // +optional 99 DriverName string 100 101 // Allocation is set by the resource driver once a resource or set of 102 // resources has been allocated successfully. If this is not specified, the 103 // resources have not been allocated yet. 104 // +optional 105 Allocation *AllocationResult 106 107 // ReservedFor indicates which entities are currently allowed to use 108 // the claim. A Pod which references a ResourceClaim which is not 109 // reserved for that Pod will not be started. 110 // 111 // There can be at most 32 such reservations. This may get increased in 112 // the future, but not reduced. 113 // +optional 114 ReservedFor []ResourceClaimConsumerReference 115 116 // DeallocationRequested indicates that a ResourceClaim is to be 117 // deallocated. 118 // 119 // The driver then must deallocate this claim and reset the field 120 // together with clearing the Allocation field. 121 // 122 // While DeallocationRequested is set, no new consumers may be added to 123 // ReservedFor. 124 // +optional 125 DeallocationRequested bool 126 } 127 128 // ReservedForMaxSize is the maximum number of entries in 129 // claim.status.reservedFor. 130 const ResourceClaimReservedForMaxSize = 32 131 132 // AllocationResult contains attributes of an allocated resource. 133 type AllocationResult struct { 134 // ResourceHandles contain the state associated with an allocation that 135 // should be maintained throughout the lifetime of a claim. Each 136 // ResourceHandle contains data that should be passed to a specific kubelet 137 // plugin once it lands on a node. This data is returned by the driver 138 // after a successful allocation and is opaque to Kubernetes. Driver 139 // documentation may explain to users how to interpret this data if needed. 140 // 141 // Setting this field is optional. It has a maximum size of 32 entries. 142 // If null (or empty), it is assumed this allocation will be processed by a 143 // single kubelet plugin with no ResourceHandle data attached. The name of 144 // the kubelet plugin invoked will match the DriverName set in the 145 // ResourceClaimStatus this AllocationResult is embedded in. 146 // 147 // +listType=atomic 148 // +optional 149 ResourceHandles []ResourceHandle 150 151 // This field will get set by the resource driver after it has allocated 152 // the resource to inform the scheduler where it can schedule Pods using 153 // the ResourceClaim. 154 // 155 // Setting this field is optional. If null, the resource is available 156 // everywhere. 157 // +optional 158 AvailableOnNodes *core.NodeSelector 159 160 // Shareable determines whether the resource supports more 161 // than one consumer at a time. 162 // +optional 163 Shareable bool 164 } 165 166 // AllocationResultResourceHandlesMaxSize represents the maximum number of 167 // entries in allocation.resourceHandles. 168 const AllocationResultResourceHandlesMaxSize = 32 169 170 // ResourceHandle holds opaque resource data for processing by a specific kubelet plugin. 171 type ResourceHandle struct { 172 // DriverName specifies the name of the resource driver whose kubelet 173 // plugin should be invoked to process this ResourceHandle's data once it 174 // lands on a node. This may differ from the DriverName set in 175 // ResourceClaimStatus this ResourceHandle is embedded in. 176 DriverName string 177 178 // Data contains the opaque data associated with this ResourceHandle. It is 179 // set by the controller component of the resource driver whose name 180 // matches the DriverName set in the ResourceClaimStatus this 181 // ResourceHandle is embedded in. It is set at allocation time and is 182 // intended for processing by the kubelet plugin whose name matches 183 // the DriverName set in this ResourceHandle. 184 // 185 // The maximum size of this field is 16KiB. This may get increased in the 186 // future, but not reduced. 187 // +optional 188 Data string 189 190 // If StructuredData is set, then it needs to be used instead of Data. 191 StructuredData *StructuredResourceHandle 192 } 193 194 // ResourceHandleDataMaxSize represents the maximum size of resourceHandle.data. 195 const ResourceHandleDataMaxSize = 16 * 1024 196 197 // StructuredResourceHandle is the in-tree representation of the allocation result. 198 type StructuredResourceHandle struct { 199 // VendorClassParameters are the per-claim configuration parameters 200 // from the resource class at the time that the claim was allocated. 201 VendorClassParameters runtime.Object 202 203 // VendorClaimParameters are the per-claim configuration parameters 204 // from the resource claim parameters at the time that the claim was 205 // allocated. 206 VendorClaimParameters runtime.Object 207 208 // NodeName is the name of the node providing the necessary resources 209 // if the resources are local to a node. 210 NodeName string 211 212 // Results lists all allocated driver resources. 213 Results []DriverAllocationResult 214 } 215 216 // DriverAllocationResult contains vendor parameters and the allocation result for 217 // one request. 218 type DriverAllocationResult struct { 219 // VendorRequestParameters are the per-request configuration parameters 220 // from the time that the claim was allocated. 221 VendorRequestParameters runtime.Object 222 223 AllocationResultModel 224 } 225 226 // AllocationResultModel must have one and only one field set. 227 type AllocationResultModel struct { 228 // NamedResources describes the allocation result when using the named resources model. 229 NamedResources *NamedResourcesAllocationResult 230 } 231 232 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 233 234 // ResourceClaimList is a collection of claims. 235 type ResourceClaimList struct { 236 metav1.TypeMeta 237 // Standard list metadata 238 // +optional 239 metav1.ListMeta 240 241 // Items is the list of resource claims. 242 Items []ResourceClaim 243 } 244 245 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 246 247 // PodSchedulingContext objects hold information that is needed to schedule 248 // a Pod with ResourceClaims that use "WaitForFirstConsumer" allocation 249 // mode. 250 // 251 // This is an alpha type and requires enabling the DynamicResourceAllocation 252 // feature gate. 253 type PodSchedulingContext struct { 254 metav1.TypeMeta 255 // Standard object metadata 256 // +optional 257 metav1.ObjectMeta 258 259 // Spec describes where resources for the Pod are needed. 260 Spec PodSchedulingContextSpec 261 262 // Status describes where resources for the Pod can be allocated. 263 Status PodSchedulingContextStatus 264 } 265 266 // PodSchedulingContextSpec describes where resources for the Pod are needed. 267 type PodSchedulingContextSpec struct { 268 // SelectedNode is the node for which allocation of ResourceClaims that 269 // are referenced by the Pod and that use "WaitForFirstConsumer" 270 // allocation is to be attempted. 271 SelectedNode string 272 273 // PotentialNodes lists nodes where the Pod might be able to run. 274 // 275 // The size of this field is limited to 128. This is large enough for 276 // many clusters. Larger clusters may need more attempts to find a node 277 // that suits all pending resources. This may get increased in the 278 // future, but not reduced. 279 // +optional 280 PotentialNodes []string 281 } 282 283 // PodSchedulingContextStatus describes where resources for the Pod can be allocated. 284 type PodSchedulingContextStatus struct { 285 // ResourceClaims describes resource availability for each 286 // pod.spec.resourceClaim entry where the corresponding ResourceClaim 287 // uses "WaitForFirstConsumer" allocation mode. 288 // +optional 289 ResourceClaims []ResourceClaimSchedulingStatus 290 291 // If there ever is a need to support other kinds of resources 292 // than ResourceClaim, then new fields could get added here 293 // for those other resources. 294 } 295 296 // ResourceClaimSchedulingStatus contains information about one particular 297 // ResourceClaim with "WaitForFirstConsumer" allocation mode. 298 type ResourceClaimSchedulingStatus struct { 299 // Name matches the pod.spec.resourceClaims[*].Name field. 300 Name string 301 302 // UnsuitableNodes lists nodes that the ResourceClaim cannot be 303 // allocated for. 304 // 305 // The size of this field is limited to 128, the same as for 306 // PodSchedulingSpec.PotentialNodes. This may get increased in the 307 // future, but not reduced. 308 // +optional 309 UnsuitableNodes []string 310 } 311 312 // PodSchedulingNodeListMaxSize defines the maximum number of entries in the 313 // node lists that are stored in PodSchedulingContext objects. This limit is part 314 // of the API. 315 const PodSchedulingNodeListMaxSize = 128 316 317 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 318 319 // PodSchedulingContextList is a collection of Pod scheduling objects. 320 type PodSchedulingContextList struct { 321 metav1.TypeMeta 322 // Standard list metadata 323 // +optional 324 metav1.ListMeta 325 326 // Items is the list of PodSchedulingContext objects. 327 Items []PodSchedulingContext 328 } 329 330 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 331 332 // ResourceClass is used by administrators to influence how resources 333 // are allocated. 334 // 335 // This is an alpha type and requires enabling the DynamicResourceAllocation 336 // feature gate. 337 type ResourceClass struct { 338 metav1.TypeMeta 339 // Standard object metadata 340 // +optional 341 metav1.ObjectMeta 342 343 // DriverName defines the name of the dynamic resource driver that is 344 // used for allocation of a ResourceClaim that uses this class. 345 // 346 // Resource drivers have a unique name in forward domain order 347 // (acme.example.com). 348 DriverName string 349 350 // ParametersRef references an arbitrary separate object that may hold 351 // parameters that will be used by the driver when allocating a 352 // resource that uses this class. A dynamic resource driver can 353 // distinguish between parameters stored here and and those stored in 354 // ResourceClaimSpec. 355 // +optional 356 ParametersRef *ResourceClassParametersReference 357 358 // Only nodes matching the selector will be considered by the scheduler 359 // when trying to find a Node that fits a Pod when that Pod uses 360 // a ResourceClaim that has not been allocated yet. 361 // 362 // Setting this field is optional. If null, all nodes are candidates. 363 // +optional 364 SuitableNodes *core.NodeSelector 365 366 // If and only if allocation of claims using this class is handled 367 // via structured parameters, then StructuredParameters must be set to true. 368 StructuredParameters *bool 369 } 370 371 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 372 373 // ResourceClassList is a collection of classes. 374 type ResourceClassList struct { 375 metav1.TypeMeta 376 // Standard list metadata 377 // +optional 378 metav1.ListMeta 379 380 // Items is the list of resource classes. 381 Items []ResourceClass 382 } 383 384 // ResourceClassParametersReference contains enough information to let you 385 // locate the parameters for a ResourceClass. 386 type ResourceClassParametersReference struct { 387 // APIGroup is the group for the resource being referenced. It is 388 // empty for the core API. This matches the group in the APIVersion 389 // that is used when creating the resources. 390 // +optional 391 APIGroup string 392 // Kind is the type of resource being referenced. This is the same 393 // value as in the parameter object's metadata. 394 Kind string 395 // Name is the name of resource being referenced. 396 Name string 397 // Namespace that contains the referenced resource. Must be empty 398 // for cluster-scoped resources and non-empty for namespaced 399 // resources. 400 // +optional 401 Namespace string 402 } 403 404 // ResourceClaimParametersReference contains enough information to let you 405 // locate the parameters for a ResourceClaim. The object must be in the same 406 // namespace as the ResourceClaim. 407 type ResourceClaimParametersReference struct { 408 // APIGroup is the group for the resource being referenced. It is 409 // empty for the core API. This matches the group in the APIVersion 410 // that is used when creating the resources. 411 // +optional 412 APIGroup string 413 // Kind is the type of resource being referenced. This is the same 414 // value as in the parameter object's metadata, for example "ConfigMap". 415 Kind string 416 // Name is the name of resource being referenced. 417 Name string 418 } 419 420 // ResourceClaimConsumerReference contains enough information to let you 421 // locate the consumer of a ResourceClaim. The user must be a resource in the same 422 // namespace as the ResourceClaim. 423 type ResourceClaimConsumerReference struct { 424 // APIGroup is the group for the resource being referenced. It is 425 // empty for the core API. This matches the group in the APIVersion 426 // that is used when creating the resources. 427 // +optional 428 APIGroup string 429 // Resource is the type of resource being referenced, for example "pods". 430 Resource string 431 // Name is the name of resource being referenced. 432 Name string 433 // UID identifies exactly one incarnation of the resource. 434 UID types.UID 435 } 436 437 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 438 439 // ResourceClaimTemplate is used to produce ResourceClaim objects. 440 type ResourceClaimTemplate struct { 441 metav1.TypeMeta 442 // Standard object metadata 443 // +optional 444 metav1.ObjectMeta 445 446 // Describes the ResourceClaim that is to be generated. 447 // 448 // This field is immutable. A ResourceClaim will get created by the 449 // control plane for a Pod when needed and then not get updated 450 // anymore. 451 Spec ResourceClaimTemplateSpec 452 } 453 454 // ResourceClaimTemplateSpec contains the metadata and fields for a ResourceClaim. 455 type ResourceClaimTemplateSpec struct { 456 // ObjectMeta may contain labels and annotations that will be copied into the PVC 457 // when creating it. No other fields are allowed and will be rejected during 458 // validation. 459 // +optional 460 metav1.ObjectMeta 461 462 // Spec for the ResourceClaim. The entire content is copied unchanged 463 // into the ResourceClaim that gets created from this template. The 464 // same fields as in a ResourceClaim are also valid here. 465 Spec ResourceClaimSpec 466 } 467 468 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 469 470 // ResourceClaimTemplateList is a collection of claim templates. 471 type ResourceClaimTemplateList struct { 472 metav1.TypeMeta 473 // Standard list metadata 474 // +optional 475 metav1.ListMeta 476 477 // Items is the list of resource claim templates. 478 Items []ResourceClaimTemplate 479 } 480 481 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 482 483 // ResourceSlice provides information about available 484 // resources on individual nodes. 485 type ResourceSlice struct { 486 metav1.TypeMeta 487 // Standard object metadata 488 metav1.ObjectMeta 489 490 // NodeName identifies the node which provides the resources 491 // if they are local to a node. 492 // 493 // A field selector can be used to list only ResourceSlice 494 // objects with a certain node name. 495 NodeName string 496 497 // DriverName identifies the DRA driver providing the capacity information. 498 // A field selector can be used to list only ResourceSlice 499 // objects with a certain driver name. 500 DriverName string 501 502 ResourceModel 503 } 504 505 // ResourceModel must have one and only one field set. 506 type ResourceModel struct { 507 // NamedResources describes available resources using the named resources model. 508 NamedResources *NamedResourcesResources 509 } 510 511 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 512 513 // ResourceSliceList is a collection of ResourceSlices. 514 type ResourceSliceList struct { 515 metav1.TypeMeta 516 // Standard list metadata 517 metav1.ListMeta 518 519 // Items is the list of node resource capacity objects. 520 Items []ResourceSlice 521 } 522 523 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 524 525 // ResourceClaimParameters defines resource requests for a ResourceClaim in an 526 // in-tree format understood by Kubernetes. 527 type ResourceClaimParameters struct { 528 metav1.TypeMeta 529 // Standard object metadata 530 metav1.ObjectMeta 531 532 // If this object was created from some other resource, then this links 533 // back to that resource. This field is used to find the in-tree representation 534 // of the claim parameters when the parameter reference of the claim refers 535 // to some unknown type. 536 GeneratedFrom *ResourceClaimParametersReference 537 538 // Shareable indicates whether the allocated claim is meant to be shareable 539 // by multiple consumers at the same time. 540 Shareable bool 541 542 // DriverRequests describes all resources that are needed for the 543 // allocated claim. A single claim may use resources coming from 544 // different drivers. For each driver, this array has at most one 545 // entry which then may have one or more per-driver requests. 546 // 547 // May be empty, in which case the claim can always be allocated. 548 DriverRequests []DriverRequests 549 } 550 551 // DriverRequests describes all resources that are needed from one particular driver. 552 type DriverRequests struct { 553 // DriverName is the name used by the DRA driver kubelet plugin. 554 DriverName string 555 556 // VendorParameters are arbitrary setup parameters for all requests of the 557 // claim. They are ignored while allocating the claim. 558 VendorParameters runtime.Object 559 560 // Requests describes all resources that are needed from the driver. 561 Requests []ResourceRequest 562 } 563 564 // ResourceRequest is a request for resources from one particular driver. 565 type ResourceRequest struct { 566 // VendorParameters are arbitrary setup parameters for the requested 567 // resource. They are ignored while allocating a claim. 568 VendorParameters runtime.Object 569 570 ResourceRequestModel 571 } 572 573 // ResourceRequestModel must have one and only one field set. 574 type ResourceRequestModel struct { 575 // NamedResources describes a request for resources with the named resources model. 576 NamedResources *NamedResourcesRequest 577 } 578 579 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 580 581 // ResourceClaimParametersList is a collection of ResourceClaimParameters. 582 type ResourceClaimParametersList struct { 583 metav1.TypeMeta 584 // Standard list metadata 585 metav1.ListMeta 586 587 // Items is the list of node resource capacity objects. 588 Items []ResourceClaimParameters 589 } 590 591 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 592 593 // ResourceClassParameters defines resource requests for a ResourceClass in an 594 // in-tree format understood by Kubernetes. 595 type ResourceClassParameters struct { 596 metav1.TypeMeta 597 // Standard object metadata 598 metav1.ObjectMeta 599 600 // If this object was created from some other resource, then this links 601 // back to that resource. This field is used to find the in-tree representation 602 // of the class parameters when the parameter reference of the class refers 603 // to some unknown type. 604 GeneratedFrom *ResourceClassParametersReference 605 606 // VendorParameters are arbitrary setup parameters for all claims using 607 // this class. They are ignored while allocating the claim. There must 608 // not be more than one entry per driver. 609 VendorParameters []VendorParameters 610 611 // Filters describes additional contraints that must be met when using the class. 612 Filters []ResourceFilter 613 } 614 615 // ResourceFilter is a filter for resources from one particular driver. 616 type ResourceFilter struct { 617 // DriverName is the name used by the DRA driver kubelet plugin. 618 DriverName string 619 620 ResourceFilterModel 621 } 622 623 // ResourceFilterModel must have one and only one field set. 624 type ResourceFilterModel struct { 625 // NamedResources describes a resource filter using the named resources model. 626 NamedResources *NamedResourcesFilter 627 } 628 629 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 630 631 // ResourceClassParametersList is a collection of ResourceClassParameters. 632 type ResourceClassParametersList struct { 633 metav1.TypeMeta 634 // Standard list metadata 635 metav1.ListMeta 636 637 // Items is the list of node resource capacity objects. 638 Items []ResourceClassParameters 639 } 640 641 // VendorParameters are opaque parameters for one particular driver. 642 type VendorParameters struct { 643 // DriverName is the name used by the DRA driver kubelet plugin. 644 DriverName string 645 646 // Parameters can be arbitrary setup parameters. They are ignored while 647 // allocating a claim. 648 Parameters runtime.Object 649 }