k8s.io/kubernetes@v1.29.3/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/types" 22 "k8s.io/kubernetes/pkg/apis/core" 23 ) 24 25 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 26 27 // ResourceClaim describes which resources are needed by a resource consumer. 28 // Its status tracks whether the resource has been allocated and what the 29 // resulting attributes are. 30 // 31 // This is an alpha type and requires enabling the DynamicResourceAllocation 32 // feature gate. 33 type ResourceClaim struct { 34 metav1.TypeMeta 35 // Standard object metadata 36 // +optional 37 metav1.ObjectMeta 38 39 // Spec describes the desired attributes of a resource that then needs 40 // to be allocated. It can only be set once when creating the 41 // ResourceClaim. 42 Spec ResourceClaimSpec 43 44 // Status describes whether the resource is available and with which 45 // attributes. 46 // +optional 47 Status ResourceClaimStatus 48 } 49 50 // ResourceClaimSpec defines how a resource is to be allocated. 51 type ResourceClaimSpec struct { 52 // ResourceClassName references the driver and additional parameters 53 // via the name of a ResourceClass that was created as part of the 54 // driver deployment. 55 ResourceClassName string 56 57 // ParametersRef references a separate object with arbitrary parameters 58 // that will be used by the driver when allocating a resource for the 59 // claim. 60 // 61 // The object must be in the same namespace as the ResourceClaim. 62 // +optional 63 ParametersRef *ResourceClaimParametersReference 64 65 // Allocation can start immediately or when a Pod wants to use the 66 // resource. "WaitForFirstConsumer" is the default. 67 // +optional 68 AllocationMode AllocationMode 69 } 70 71 // AllocationMode describes whether a ResourceClaim gets allocated immediately 72 // when it gets created (AllocationModeImmediate) or whether allocation is 73 // delayed until it is needed for a Pod 74 // (AllocationModeWaitForFirstConsumer). Other modes might get added in the 75 // future. 76 type AllocationMode string 77 78 const ( 79 // When a ResourceClaim has AllocationModeWaitForFirstConsumer, allocation is 80 // delayed until a Pod gets scheduled that needs the ResourceClaim. The 81 // scheduler will consider all resource requirements of that Pod and 82 // trigger allocation for a node that fits the Pod. 83 AllocationModeWaitForFirstConsumer AllocationMode = "WaitForFirstConsumer" 84 85 // When a ResourceClaim has AllocationModeImmediate, allocation starts 86 // as soon as the ResourceClaim gets created. This is done without 87 // considering the needs of Pods that will use the ResourceClaim 88 // because those Pods are not known yet. 89 AllocationModeImmediate AllocationMode = "Immediate" 90 ) 91 92 // ResourceClaimStatus tracks whether the resource has been allocated and what 93 // the resulting attributes are. 94 type ResourceClaimStatus struct { 95 // DriverName is a copy of the driver name from the ResourceClass at 96 // the time when allocation started. 97 // +optional 98 DriverName string 99 100 // Allocation is set by the resource driver once a resource or set of 101 // resources has been allocated successfully. If this is not specified, the 102 // resources have not been allocated yet. 103 // +optional 104 Allocation *AllocationResult 105 106 // ReservedFor indicates which entities are currently allowed to use 107 // the claim. A Pod which references a ResourceClaim which is not 108 // reserved for that Pod will not be started. 109 // 110 // There can be at most 32 such reservations. This may get increased in 111 // the future, but not reduced. 112 // +optional 113 ReservedFor []ResourceClaimConsumerReference 114 115 // DeallocationRequested indicates that a ResourceClaim is to be 116 // deallocated. 117 // 118 // The driver then must deallocate this claim and reset the field 119 // together with clearing the Allocation field. 120 // 121 // While DeallocationRequested is set, no new consumers may be added to 122 // ReservedFor. 123 // +optional 124 DeallocationRequested bool 125 } 126 127 // ReservedForMaxSize is the maximum number of entries in 128 // claim.status.reservedFor. 129 const ResourceClaimReservedForMaxSize = 32 130 131 // AllocationResult contains attributes of an allocated resource. 132 type AllocationResult struct { 133 // ResourceHandles contain the state associated with an allocation that 134 // should be maintained throughout the lifetime of a claim. Each 135 // ResourceHandle contains data that should be passed to a specific kubelet 136 // plugin once it lands on a node. This data is returned by the driver 137 // after a successful allocation and is opaque to Kubernetes. Driver 138 // documentation may explain to users how to interpret this data if needed. 139 // 140 // Setting this field is optional. It has a maximum size of 32 entries. 141 // If null (or empty), it is assumed this allocation will be processed by a 142 // single kubelet plugin with no ResourceHandle data attached. The name of 143 // the kubelet plugin invoked will match the DriverName set in the 144 // ResourceClaimStatus this AllocationResult is embedded in. 145 // 146 // +listType=atomic 147 // +optional 148 ResourceHandles []ResourceHandle 149 150 // This field will get set by the resource driver after it has allocated 151 // the resource to inform the scheduler where it can schedule Pods using 152 // the ResourceClaim. 153 // 154 // Setting this field is optional. If null, the resource is available 155 // everywhere. 156 // +optional 157 AvailableOnNodes *core.NodeSelector 158 159 // Shareable determines whether the resource supports more 160 // than one consumer at a time. 161 // +optional 162 Shareable bool 163 } 164 165 // AllocationResultResourceHandlesMaxSize represents the maximum number of 166 // entries in allocation.resourceHandles. 167 const AllocationResultResourceHandlesMaxSize = 32 168 169 // ResourceHandle holds opaque resource data for processing by a specific kubelet plugin. 170 type ResourceHandle struct { 171 // DriverName specifies the name of the resource driver whose kubelet 172 // plugin should be invoked to process this ResourceHandle's data once it 173 // lands on a node. This may differ from the DriverName set in 174 // ResourceClaimStatus this ResourceHandle is embedded in. 175 DriverName string 176 177 // Data contains the opaque data associated with this ResourceHandle. It is 178 // set by the controller component of the resource driver whose name 179 // matches the DriverName set in the ResourceClaimStatus this 180 // ResourceHandle is embedded in. It is set at allocation time and is 181 // intended for processing by the kubelet plugin whose name matches 182 // the DriverName set in this ResourceHandle. 183 // 184 // The maximum size of this field is 16KiB. This may get increased in the 185 // future, but not reduced. 186 // +optional 187 Data string 188 } 189 190 // ResourceHandleDataMaxSize represents the maximum size of resourceHandle.data. 191 const ResourceHandleDataMaxSize = 16 * 1024 192 193 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 194 195 // ResourceClaimList is a collection of claims. 196 type ResourceClaimList struct { 197 metav1.TypeMeta 198 // Standard list metadata 199 // +optional 200 metav1.ListMeta 201 202 // Items is the list of resource claims. 203 Items []ResourceClaim 204 } 205 206 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 207 208 // PodSchedulingContext objects hold information that is needed to schedule 209 // a Pod with ResourceClaims that use "WaitForFirstConsumer" allocation 210 // mode. 211 // 212 // This is an alpha type and requires enabling the DynamicResourceAllocation 213 // feature gate. 214 type PodSchedulingContext struct { 215 metav1.TypeMeta 216 // Standard object metadata 217 // +optional 218 metav1.ObjectMeta 219 220 // Spec describes where resources for the Pod are needed. 221 Spec PodSchedulingContextSpec 222 223 // Status describes where resources for the Pod can be allocated. 224 Status PodSchedulingContextStatus 225 } 226 227 // PodSchedulingContextSpec describes where resources for the Pod are needed. 228 type PodSchedulingContextSpec struct { 229 // SelectedNode is the node for which allocation of ResourceClaims that 230 // are referenced by the Pod and that use "WaitForFirstConsumer" 231 // allocation is to be attempted. 232 SelectedNode string 233 234 // PotentialNodes lists nodes where the Pod might be able to run. 235 // 236 // The size of this field is limited to 128. This is large enough for 237 // many clusters. Larger clusters may need more attempts to find a node 238 // that suits all pending resources. This may get increased in the 239 // future, but not reduced. 240 // +optional 241 PotentialNodes []string 242 } 243 244 // PodSchedulingContextStatus describes where resources for the Pod can be allocated. 245 type PodSchedulingContextStatus struct { 246 // ResourceClaims describes resource availability for each 247 // pod.spec.resourceClaim entry where the corresponding ResourceClaim 248 // uses "WaitForFirstConsumer" allocation mode. 249 // +optional 250 ResourceClaims []ResourceClaimSchedulingStatus 251 252 // If there ever is a need to support other kinds of resources 253 // than ResourceClaim, then new fields could get added here 254 // for those other resources. 255 } 256 257 // ResourceClaimSchedulingStatus contains information about one particular 258 // ResourceClaim with "WaitForFirstConsumer" allocation mode. 259 type ResourceClaimSchedulingStatus struct { 260 // Name matches the pod.spec.resourceClaims[*].Name field. 261 Name string 262 263 // UnsuitableNodes lists nodes that the ResourceClaim cannot be 264 // allocated for. 265 // 266 // The size of this field is limited to 128, the same as for 267 // PodSchedulingSpec.PotentialNodes. This may get increased in the 268 // future, but not reduced. 269 // +optional 270 UnsuitableNodes []string 271 } 272 273 // PodSchedulingNodeListMaxSize defines the maximum number of entries in the 274 // node lists that are stored in PodSchedulingContext objects. This limit is part 275 // of the API. 276 const PodSchedulingNodeListMaxSize = 128 277 278 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 279 280 // PodSchedulingContextList is a collection of Pod scheduling objects. 281 type PodSchedulingContextList struct { 282 metav1.TypeMeta 283 // Standard list metadata 284 // +optional 285 metav1.ListMeta 286 287 // Items is the list of PodSchedulingContext objects. 288 Items []PodSchedulingContext 289 } 290 291 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 292 293 // ResourceClass is used by administrators to influence how resources 294 // are allocated. 295 // 296 // This is an alpha type and requires enabling the DynamicResourceAllocation 297 // feature gate. 298 type ResourceClass struct { 299 metav1.TypeMeta 300 // Standard object metadata 301 // +optional 302 metav1.ObjectMeta 303 304 // DriverName defines the name of the dynamic resource driver that is 305 // used for allocation of a ResourceClaim that uses this class. 306 // 307 // Resource drivers have a unique name in forward domain order 308 // (acme.example.com). 309 DriverName string 310 311 // ParametersRef references an arbitrary separate object that may hold 312 // parameters that will be used by the driver when allocating a 313 // resource that uses this class. A dynamic resource driver can 314 // distinguish between parameters stored here and and those stored in 315 // ResourceClaimSpec. 316 // +optional 317 ParametersRef *ResourceClassParametersReference 318 319 // Only nodes matching the selector will be considered by the scheduler 320 // when trying to find a Node that fits a Pod when that Pod uses 321 // a ResourceClaim that has not been allocated yet. 322 // 323 // Setting this field is optional. If null, all nodes are candidates. 324 // +optional 325 SuitableNodes *core.NodeSelector 326 } 327 328 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 329 330 // ResourceClassList is a collection of classes. 331 type ResourceClassList struct { 332 metav1.TypeMeta 333 // Standard list metadata 334 // +optional 335 metav1.ListMeta 336 337 // Items is the list of resource classes. 338 Items []ResourceClass 339 } 340 341 // ResourceClassParametersReference contains enough information to let you 342 // locate the parameters for a ResourceClass. 343 type ResourceClassParametersReference struct { 344 // APIGroup is the group for the resource being referenced. It is 345 // empty for the core API. This matches the group in the APIVersion 346 // that is used when creating the resources. 347 // +optional 348 APIGroup string 349 // Kind is the type of resource being referenced. This is the same 350 // value as in the parameter object's metadata. 351 Kind string 352 // Name is the name of resource being referenced. 353 Name string 354 // Namespace that contains the referenced resource. Must be empty 355 // for cluster-scoped resources and non-empty for namespaced 356 // resources. 357 // +optional 358 Namespace string 359 } 360 361 // ResourceClaimParametersReference contains enough information to let you 362 // locate the parameters for a ResourceClaim. The object must be in the same 363 // namespace as the ResourceClaim. 364 type ResourceClaimParametersReference struct { 365 // APIGroup is the group for the resource being referenced. It is 366 // empty for the core API. This matches the group in the APIVersion 367 // that is used when creating the resources. 368 // +optional 369 APIGroup string 370 // Kind is the type of resource being referenced. This is the same 371 // value as in the parameter object's metadata, for example "ConfigMap". 372 Kind string 373 // Name is the name of resource being referenced. 374 Name string 375 } 376 377 // ResourceClaimConsumerReference contains enough information to let you 378 // locate the consumer of a ResourceClaim. The user must be a resource in the same 379 // namespace as the ResourceClaim. 380 type ResourceClaimConsumerReference struct { 381 // APIGroup is the group for the resource being referenced. It is 382 // empty for the core API. This matches the group in the APIVersion 383 // that is used when creating the resources. 384 // +optional 385 APIGroup string 386 // Resource is the type of resource being referenced, for example "pods". 387 Resource string 388 // Name is the name of resource being referenced. 389 Name string 390 // UID identifies exactly one incarnation of the resource. 391 UID types.UID 392 } 393 394 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 395 396 // ResourceClaimTemplate is used to produce ResourceClaim objects. 397 type ResourceClaimTemplate struct { 398 metav1.TypeMeta 399 // Standard object metadata 400 // +optional 401 metav1.ObjectMeta 402 403 // Describes the ResourceClaim that is to be generated. 404 // 405 // This field is immutable. A ResourceClaim will get created by the 406 // control plane for a Pod when needed and then not get updated 407 // anymore. 408 Spec ResourceClaimTemplateSpec 409 } 410 411 // ResourceClaimTemplateSpec contains the metadata and fields for a ResourceClaim. 412 type ResourceClaimTemplateSpec struct { 413 // ObjectMeta may contain labels and annotations that will be copied into the PVC 414 // when creating it. No other fields are allowed and will be rejected during 415 // validation. 416 // +optional 417 metav1.ObjectMeta 418 419 // Spec for the ResourceClaim. The entire content is copied unchanged 420 // into the ResourceClaim that gets created from this template. The 421 // same fields as in a ResourceClaim are also valid here. 422 Spec ResourceClaimSpec 423 } 424 425 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 426 427 // ResourceClaimTemplateList is a collection of claim templates. 428 type ResourceClaimTemplateList struct { 429 metav1.TypeMeta 430 // Standard list metadata 431 // +optional 432 metav1.ListMeta 433 434 // Items is the list of resource claim templates. 435 Items []ResourceClaimTemplate 436 }