From b2267f3d7500398bd8651bbd8dfed3c58b0747e7 Mon Sep 17 00:00:00 2001 From: Praveen Krishna Date: Wed, 18 Mar 2026 14:18:22 +0000 Subject: [PATCH] make update Kubernetes-commit: f266fe4118e52605ba9cf02e1ab2ed68988d56e9 --- .../v1/nodeallocatableresourceclaimstatus.go | 75 +++++++++++++++++ applyconfigurations/core/v1/podstatus.go | 19 +++++ applyconfigurations/internal/internal.go | 66 +++++++++++++++ applyconfigurations/resource/v1/device.go | 27 ++++++ .../v1/nodeallocatableresourcemapping.go | 84 +++++++++++++++++++ .../resource/v1beta1/basicdevice.go | 27 ++++++ .../v1beta1/nodeallocatableresourcemapping.go | 84 +++++++++++++++++++ .../resource/v1beta2/device.go | 27 ++++++ .../v1beta2/nodeallocatableresourcemapping.go | 84 +++++++++++++++++++ applyconfigurations/utils.go | 8 ++ 10 files changed, 501 insertions(+) create mode 100644 applyconfigurations/core/v1/nodeallocatableresourceclaimstatus.go create mode 100644 applyconfigurations/resource/v1/nodeallocatableresourcemapping.go create mode 100644 applyconfigurations/resource/v1beta1/nodeallocatableresourcemapping.go create mode 100644 applyconfigurations/resource/v1beta2/nodeallocatableresourcemapping.go diff --git a/applyconfigurations/core/v1/nodeallocatableresourceclaimstatus.go b/applyconfigurations/core/v1/nodeallocatableresourceclaimstatus.go new file mode 100644 index 000000000..6e384b002 --- /dev/null +++ b/applyconfigurations/core/v1/nodeallocatableresourceclaimstatus.go @@ -0,0 +1,75 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1 + +import ( + corev1 "k8s.io/api/core/v1" + resource "k8s.io/apimachinery/pkg/api/resource" +) + +// NodeAllocatableResourceClaimStatusApplyConfiguration represents a declarative configuration of the NodeAllocatableResourceClaimStatus type for use +// with apply. +// +// NodeAllocatableResourceClaimStatus describes the status of node allocatable resources allocated via DRA. +type NodeAllocatableResourceClaimStatusApplyConfiguration struct { + // ResourceClaimName is the resource claim referenced by the pod that resulted in this node allocatable resource allocation. + ResourceClaimName *string `json:"resourceClaimName,omitempty"` + // Containers lists the names of all containers in this pod that reference the claim. + Containers []string `json:"containers,omitempty"` + // Resources is a map of the node-allocatable resource name to the aggregate quantity allocated to the claim. + Resources map[corev1.ResourceName]resource.Quantity `json:"resources,omitempty"` +} + +// NodeAllocatableResourceClaimStatusApplyConfiguration constructs a declarative configuration of the NodeAllocatableResourceClaimStatus type for use with +// apply. +func NodeAllocatableResourceClaimStatus() *NodeAllocatableResourceClaimStatusApplyConfiguration { + return &NodeAllocatableResourceClaimStatusApplyConfiguration{} +} + +// WithResourceClaimName sets the ResourceClaimName field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ResourceClaimName field is set to the value of the last call. +func (b *NodeAllocatableResourceClaimStatusApplyConfiguration) WithResourceClaimName(value string) *NodeAllocatableResourceClaimStatusApplyConfiguration { + b.ResourceClaimName = &value + return b +} + +// WithContainers adds the given value to the Containers field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the Containers field. +func (b *NodeAllocatableResourceClaimStatusApplyConfiguration) WithContainers(values ...string) *NodeAllocatableResourceClaimStatusApplyConfiguration { + for i := range values { + b.Containers = append(b.Containers, values[i]) + } + return b +} + +// WithResources puts the entries into the Resources field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Resources field, +// overwriting an existing map entries in Resources field with the same key. +func (b *NodeAllocatableResourceClaimStatusApplyConfiguration) WithResources(entries map[corev1.ResourceName]resource.Quantity) *NodeAllocatableResourceClaimStatusApplyConfiguration { + if b.Resources == nil && len(entries) > 0 { + b.Resources = make(map[corev1.ResourceName]resource.Quantity, len(entries)) + } + for k, v := range entries { + b.Resources[k] = v + } + return b +} diff --git a/applyconfigurations/core/v1/podstatus.go b/applyconfigurations/core/v1/podstatus.go index e50ca9335..8328d9cdb 100644 --- a/applyconfigurations/core/v1/podstatus.go +++ b/applyconfigurations/core/v1/podstatus.go @@ -139,6 +139,12 @@ type PodStatusApplyConfiguration struct { // applied at the pod level if pod-level requests or limits are set in // PodSpec.Resources Resources *ResourceRequirementsApplyConfiguration `json:"resources,omitempty"` + // NodeAllocatableResourceClaimStatuses contains the status of node-allocatable resources + // that were allocated for this pod through DRA claims. This includes resources currently + // reported in v1.Node `status.allocatable` that are not extended resources + // (see https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#extended-resources). + // Examples include "cpu", "memory", "ephemeral-storage", and hugepages. + NodeAllocatableResourceClaimStatuses []NodeAllocatableResourceClaimStatusApplyConfiguration `json:"nodeAllocatableResourceClaimStatuses,omitempty"` } // PodStatusApplyConfiguration constructs a declarative configuration of the PodStatus type for use with @@ -341,3 +347,16 @@ func (b *PodStatusApplyConfiguration) WithResources(value *ResourceRequirementsA b.Resources = value return b } + +// WithNodeAllocatableResourceClaimStatuses adds the given value to the NodeAllocatableResourceClaimStatuses field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the NodeAllocatableResourceClaimStatuses field. +func (b *PodStatusApplyConfiguration) WithNodeAllocatableResourceClaimStatuses(values ...*NodeAllocatableResourceClaimStatusApplyConfiguration) *PodStatusApplyConfiguration { + for i := range values { + if values[i] == nil { + panic("nil value passed to WithNodeAllocatableResourceClaimStatuses") + } + b.NodeAllocatableResourceClaimStatuses = append(b.NodeAllocatableResourceClaimStatuses, *values[i]) + } + return b +} diff --git a/applyconfigurations/internal/internal.go b/applyconfigurations/internal/internal.go index 8911efc64..fac88a011 100644 --- a/applyconfigurations/internal/internal.go +++ b/applyconfigurations/internal/internal.go @@ -6040,6 +6040,24 @@ var schemaYAML = typed.YAMLObject(`types: - name: requiredDuringSchedulingIgnoredDuringExecution type: namedType: io.k8s.api.core.v1.NodeSelector +- name: io.k8s.api.core.v1.NodeAllocatableResourceClaimStatus + map: + fields: + - name: containers + type: + list: + elementType: + scalar: string + elementRelationship: associative + - name: resourceClaimName + type: + scalar: string + default: "" + - name: resources + type: + map: + elementType: + namedType: io.k8s.apimachinery.pkg.api.resource.Quantity - name: io.k8s.api.core.v1.NodeCondition map: fields: @@ -7166,6 +7184,12 @@ var schemaYAML = typed.YAMLObject(`types: - name: message type: scalar: string + - name: nodeAllocatableResourceClaimStatuses + type: + list: + elementType: + namedType: io.k8s.api.core.v1.NodeAllocatableResourceClaimStatus + elementRelationship: atomic - name: nominatedNodeName type: scalar: string @@ -12452,6 +12476,11 @@ var schemaYAML = typed.YAMLObject(`types: type: scalar: string default: "" + - name: nodeAllocatableResourceMappings + type: + map: + elementType: + namedType: io.k8s.api.resource.v1.NodeAllocatableResourceMapping - name: nodeName type: scalar: string @@ -12804,6 +12833,15 @@ var schemaYAML = typed.YAMLObject(`types: elementType: scalar: string elementRelationship: atomic +- name: io.k8s.api.resource.v1.NodeAllocatableResourceMapping + map: + fields: + - name: allocationMultiplier + type: + namedType: io.k8s.apimachinery.pkg.api.resource.Quantity + - name: capacityKey + type: + scalar: string - name: io.k8s.api.resource.v1.OpaqueDeviceConfiguration map: fields: @@ -13136,6 +13174,11 @@ var schemaYAML = typed.YAMLObject(`types: elementType: namedType: io.k8s.api.resource.v1beta1.DeviceCounterConsumption elementRelationship: atomic + - name: nodeAllocatableResourceMappings + type: + map: + elementType: + namedType: io.k8s.api.resource.v1beta1.NodeAllocatableResourceMapping - name: nodeName type: scalar: string @@ -13552,6 +13595,15 @@ var schemaYAML = typed.YAMLObject(`types: elementType: scalar: string elementRelationship: atomic +- name: io.k8s.api.resource.v1beta1.NodeAllocatableResourceMapping + map: + fields: + - name: allocationMultiplier + type: + namedType: io.k8s.apimachinery.pkg.api.resource.Quantity + - name: capacityKey + type: + scalar: string - name: io.k8s.api.resource.v1beta1.OpaqueDeviceConfiguration map: fields: @@ -13877,6 +13929,11 @@ var schemaYAML = typed.YAMLObject(`types: type: scalar: string default: "" + - name: nodeAllocatableResourceMappings + type: + map: + elementType: + namedType: io.k8s.api.resource.v1beta2.NodeAllocatableResourceMapping - name: nodeName type: scalar: string @@ -14283,6 +14340,15 @@ var schemaYAML = typed.YAMLObject(`types: elementType: scalar: string elementRelationship: atomic +- name: io.k8s.api.resource.v1beta2.NodeAllocatableResourceMapping + map: + fields: + - name: allocationMultiplier + type: + namedType: io.k8s.apimachinery.pkg.api.resource.Quantity + - name: capacityKey + type: + scalar: string - name: io.k8s.api.resource.v1beta2.OpaqueDeviceConfiguration map: fields: diff --git a/applyconfigurations/resource/v1/device.go b/applyconfigurations/resource/v1/device.go index 73a01d642..f19b9000c 100644 --- a/applyconfigurations/resource/v1/device.go +++ b/applyconfigurations/resource/v1/device.go @@ -19,6 +19,7 @@ limitations under the License. package v1 import ( + apicorev1 "k8s.io/api/core/v1" resourcev1 "k8s.io/api/resource/v1" corev1 "k8s.io/client-go/applyconfigurations/core/v1" ) @@ -113,6 +114,18 @@ type DeviceApplyConfiguration struct { // If AllowMultipleAllocations is set to true, the device can be allocated more than once, // and all of its capacity is consumable, regardless of whether the requestPolicy is defined or not. AllowMultipleAllocations *bool `json:"allowMultipleAllocations,omitempty"` + // NodeAllocatableResourceMappings defines the mapping of node resources + // that are managed by the DRA driver exposing this device. This includes resources currently + // reported in v1.Node `status.allocatable` that are not extended resources + // (see https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#extended-resources). + // Examples include "cpu", "memory", "ephemeral-storage", and hugepages. + // In addition to standard requests made through the Pod `spec`, these resources + // can also be requested through claims and allocated by the DRA driver. + // For example, a CPU DRA driver might allocate exclusive CPUs or auxiliary node memory + // dependencies of an accelerator device. + // The keys of this map are the node-allocatable resource names (e.g., "cpu", "memory"). + // Extended resource names are not permitted as keys. + NodeAllocatableResourceMappings map[apicorev1.ResourceName]NodeAllocatableResourceMappingApplyConfiguration `json:"nodeAllocatableResourceMappings,omitempty"` } // DeviceApplyConfiguration constructs a declarative configuration of the Device type for use with @@ -242,3 +255,17 @@ func (b *DeviceApplyConfiguration) WithAllowMultipleAllocations(value bool) *Dev b.AllowMultipleAllocations = &value return b } + +// WithNodeAllocatableResourceMappings puts the entries into the NodeAllocatableResourceMappings field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the NodeAllocatableResourceMappings field, +// overwriting an existing map entries in NodeAllocatableResourceMappings field with the same key. +func (b *DeviceApplyConfiguration) WithNodeAllocatableResourceMappings(entries map[apicorev1.ResourceName]NodeAllocatableResourceMappingApplyConfiguration) *DeviceApplyConfiguration { + if b.NodeAllocatableResourceMappings == nil && len(entries) > 0 { + b.NodeAllocatableResourceMappings = make(map[apicorev1.ResourceName]NodeAllocatableResourceMappingApplyConfiguration, len(entries)) + } + for k, v := range entries { + b.NodeAllocatableResourceMappings[k] = v + } + return b +} diff --git a/applyconfigurations/resource/v1/nodeallocatableresourcemapping.go b/applyconfigurations/resource/v1/nodeallocatableresourcemapping.go new file mode 100644 index 000000000..600d96af8 --- /dev/null +++ b/applyconfigurations/resource/v1/nodeallocatableresourcemapping.go @@ -0,0 +1,84 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1 + +import ( + resourcev1 "k8s.io/api/resource/v1" + resource "k8s.io/apimachinery/pkg/api/resource" +) + +// NodeAllocatableResourceMappingApplyConfiguration represents a declarative configuration of the NodeAllocatableResourceMapping type for use +// with apply. +// +// NodeAllocatableResourceMapping defines the translation between the DRA device/capacity +// units requested to the corresponding quantity of the node allocatable resource. +type NodeAllocatableResourceMappingApplyConfiguration struct { + // CapacityKey references a capacity name defined as a key in the + // `spec.devices[*].capacity` map. When this field is set, the value associated with + // this key in the `status.allocation.devices.results[*].consumedCapacity` map + // (for a specific claim allocation) determines the base quantity for + // the node allocatable resource. If `allocationMultiplier` is also set, it is + // multiplied with the base quantity. + // For example, if `spec.devices[*].capacity` has an entry "dra.example.com/memory": "128Gi", + // and this field is set to "dra.example.com/memory", then for a claim allocation + // that consumes { "dra.example.com/memory": "4Gi" } the base quantity for the + // node allocatable resource mapping will be "4Gi", and `allocationMultiplier` should + // be omitted or set to "1". + CapacityKey *resourcev1.QualifiedName `json:"capacityKey,omitempty"` + // AllocationMultiplier is used as a multiplier for the allocated device count or the allocated capacity in the claim. + // It defaults to 1 if not specified. How the field is used also depends on whether `capacityKey` is set. + // 1. If `capacityKey` is NOT set: `allocationMultiplier` multiplies the device count allocated to the claim. + // a. A DRA driver representing each CPU core as a device would have + // {ResourceName: "cpu", allocationMultiplier: "2"} in its + // `nodeAllocatableResourceMappings`. If 4 devices are allocated to the claim, + // 4 * 2 CPUs would be considered as allocated and subtracted from the node's capacity. + // b. A GPU device that needs additional node memory per GPU allocation would + // have {ResourceName: "memory", allocationMultiplier: "2Gi"}. Each allocated + // GPU device instance of this type will account for 2Gi of memory. + // + // 2. If `capacityKey` IS set: `allocationMultiplier` is multiplied by the amount of that capacity consumed. + // The final node allocatable resource amount is `consumedCapacity[capacityKey]` * `allocationMultiplier`. + // For example, if a Device's capacity "dra.example.com/cores" is consumed, + // and each "core" provides 2 "cpu"s, the mapping would be: + // {ResourceName: "cpu", capacityKey: "dra.example.com/cores", allocationMultiplier: "2"}. + // If a claim consumes 8 "dra.example.com/cores", the CPU footprint is 8 * 2 = 16. + AllocationMultiplier *resource.Quantity `json:"allocationMultiplier,omitempty"` +} + +// NodeAllocatableResourceMappingApplyConfiguration constructs a declarative configuration of the NodeAllocatableResourceMapping type for use with +// apply. +func NodeAllocatableResourceMapping() *NodeAllocatableResourceMappingApplyConfiguration { + return &NodeAllocatableResourceMappingApplyConfiguration{} +} + +// WithCapacityKey sets the CapacityKey field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the CapacityKey field is set to the value of the last call. +func (b *NodeAllocatableResourceMappingApplyConfiguration) WithCapacityKey(value resourcev1.QualifiedName) *NodeAllocatableResourceMappingApplyConfiguration { + b.CapacityKey = &value + return b +} + +// WithAllocationMultiplier sets the AllocationMultiplier field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the AllocationMultiplier field is set to the value of the last call. +func (b *NodeAllocatableResourceMappingApplyConfiguration) WithAllocationMultiplier(value resource.Quantity) *NodeAllocatableResourceMappingApplyConfiguration { + b.AllocationMultiplier = &value + return b +} diff --git a/applyconfigurations/resource/v1beta1/basicdevice.go b/applyconfigurations/resource/v1beta1/basicdevice.go index 8a43a284c..64527b293 100644 --- a/applyconfigurations/resource/v1beta1/basicdevice.go +++ b/applyconfigurations/resource/v1beta1/basicdevice.go @@ -19,6 +19,7 @@ limitations under the License. package v1beta1 import ( + corev1 "k8s.io/api/core/v1" resourcev1beta1 "k8s.io/api/resource/v1beta1" v1 "k8s.io/client-go/applyconfigurations/core/v1" ) @@ -109,6 +110,18 @@ type BasicDeviceApplyConfiguration struct { // If AllowMultipleAllocations is set to true, the device can be allocated more than once, // and all of its capacity is consumable, regardless of whether the requestPolicy is defined or not. AllowMultipleAllocations *bool `json:"allowMultipleAllocations,omitempty"` + // NodeAllocatableResourceMappings defines the mapping of node resources + // that are managed by the DRA driver exposing this device. This includes resources currently + // reported in v1.Node `status.allocatable` that are not extended resources + // (see https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#extended-resources). + // Examples include "cpu", "memory", "ephemeral-storage", and hugepages. + // In addition to standard requests made through the Pod `spec`, these resources + // can also be requested through claims and allocated by the DRA driver. + // For example, a CPU DRA driver might allocate exclusive CPUs or auxiliary node memory + // dependencies of an accelerator device. + // The keys of this map are the node-allocatable resource names (e.g., "cpu", "memory"). + // Extended resource names are not permitted as keys. + NodeAllocatableResourceMappings map[corev1.ResourceName]NodeAllocatableResourceMappingApplyConfiguration `json:"nodeAllocatableResourceMappings,omitempty"` } // BasicDeviceApplyConfiguration constructs a declarative configuration of the BasicDevice type for use with @@ -230,3 +243,17 @@ func (b *BasicDeviceApplyConfiguration) WithAllowMultipleAllocations(value bool) b.AllowMultipleAllocations = &value return b } + +// WithNodeAllocatableResourceMappings puts the entries into the NodeAllocatableResourceMappings field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the NodeAllocatableResourceMappings field, +// overwriting an existing map entries in NodeAllocatableResourceMappings field with the same key. +func (b *BasicDeviceApplyConfiguration) WithNodeAllocatableResourceMappings(entries map[corev1.ResourceName]NodeAllocatableResourceMappingApplyConfiguration) *BasicDeviceApplyConfiguration { + if b.NodeAllocatableResourceMappings == nil && len(entries) > 0 { + b.NodeAllocatableResourceMappings = make(map[corev1.ResourceName]NodeAllocatableResourceMappingApplyConfiguration, len(entries)) + } + for k, v := range entries { + b.NodeAllocatableResourceMappings[k] = v + } + return b +} diff --git a/applyconfigurations/resource/v1beta1/nodeallocatableresourcemapping.go b/applyconfigurations/resource/v1beta1/nodeallocatableresourcemapping.go new file mode 100644 index 000000000..5cdc2c751 --- /dev/null +++ b/applyconfigurations/resource/v1beta1/nodeallocatableresourcemapping.go @@ -0,0 +1,84 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1beta1 + +import ( + resourcev1beta1 "k8s.io/api/resource/v1beta1" + resource "k8s.io/apimachinery/pkg/api/resource" +) + +// NodeAllocatableResourceMappingApplyConfiguration represents a declarative configuration of the NodeAllocatableResourceMapping type for use +// with apply. +// +// NodeAllocatableResourceMapping defines the translation between the DRA device/capacity +// units requested to the corresponding quantity of the node allocatable resource. +type NodeAllocatableResourceMappingApplyConfiguration struct { + // CapacityKey references a capacity name defined as a key in the + // `spec.devices[*].capacity` map. When this field is set, the value associated with + // this key in the `status.allocation.devices.results[*].consumedCapacity` map + // (for a specific claim allocation) determines the base quantity for + // the node allocatable resource. If `allocationMultiplier` is also set, it is + // multiplied with the base quantity. + // For example, if `spec.devices[*].capacity` has an entry "dra.example.com/memory": "128Gi", + // and this field is set to "dra.example.com/memory", then for a claim allocation + // that consumes { "dra.example.com/memory": "4Gi" } the base quantity for the + // node allocatable resource mapping will be "4Gi", and `allocationMultiplier` should + // be omitted or set to "1". + CapacityKey *resourcev1beta1.QualifiedName `json:"capacityKey,omitempty"` + // AllocationMultiplier is used as a multiplier for the allocated device count or the allocated capacity in the claim. + // It defaults to 1 if not specified. How the field is used also depends on whether `capacityKey` is set. + // 1. If `capacityKey` is NOT set: `allocationMultiplier` multiplies the device count allocated to the claim. + // a. A DRA driver representing each CPU core as a device would have + // {ResourceName: "cpu", allocationMultiplier: "2"} in its + // `nodeAllocatableResourceMappings`. If 4 devices are allocated to the claim, + // 4 * 2 CPUs would be considered as allocated and subtracted from the node's capacity. + // b. A GPU device that needs additional node memory per GPU allocation would + // have {ResourceName: "memory", allocationMultiplier: "2Gi"}. Each allocated + // GPU device instance of this type will account for 2Gi of memory. + // + // 2. If `capacityKey` IS set: `allocationMultiplier` is multiplied by the amount of that capacity consumed. + // The final node allocatable resource amount is `consumedCapacity[capacityKey]` * `allocationMultiplier`. + // For example, if a Device's capacity "dra.example.com/cores" is consumed, + // and each "core" provides 2 "cpu"s, the mapping would be: + // {ResourceName: "cpu", capacityKey: "dra.example.com/cores", allocationMultiplier: "2"}. + // If a claim consumes 8 "dra.example.com/cores", the CPU footprint is 8 * 2 = 16. + AllocationMultiplier *resource.Quantity `json:"allocationMultiplier,omitempty"` +} + +// NodeAllocatableResourceMappingApplyConfiguration constructs a declarative configuration of the NodeAllocatableResourceMapping type for use with +// apply. +func NodeAllocatableResourceMapping() *NodeAllocatableResourceMappingApplyConfiguration { + return &NodeAllocatableResourceMappingApplyConfiguration{} +} + +// WithCapacityKey sets the CapacityKey field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the CapacityKey field is set to the value of the last call. +func (b *NodeAllocatableResourceMappingApplyConfiguration) WithCapacityKey(value resourcev1beta1.QualifiedName) *NodeAllocatableResourceMappingApplyConfiguration { + b.CapacityKey = &value + return b +} + +// WithAllocationMultiplier sets the AllocationMultiplier field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the AllocationMultiplier field is set to the value of the last call. +func (b *NodeAllocatableResourceMappingApplyConfiguration) WithAllocationMultiplier(value resource.Quantity) *NodeAllocatableResourceMappingApplyConfiguration { + b.AllocationMultiplier = &value + return b +} diff --git a/applyconfigurations/resource/v1beta2/device.go b/applyconfigurations/resource/v1beta2/device.go index 7bd0cf15d..b3985b0ca 100644 --- a/applyconfigurations/resource/v1beta2/device.go +++ b/applyconfigurations/resource/v1beta2/device.go @@ -19,6 +19,7 @@ limitations under the License. package v1beta2 import ( + corev1 "k8s.io/api/core/v1" resourcev1beta2 "k8s.io/api/resource/v1beta2" v1 "k8s.io/client-go/applyconfigurations/core/v1" ) @@ -113,6 +114,18 @@ type DeviceApplyConfiguration struct { // If AllowMultipleAllocations is set to true, the device can be allocated more than once, // and all of its capacity is consumable, regardless of whether the requestPolicy is defined or not. AllowMultipleAllocations *bool `json:"allowMultipleAllocations,omitempty"` + // NodeAllocatableResourceMappings defines the mapping of node resources + // that are managed by the DRA driver exposing this device. This includes resources currently + // reported in v1.Node `status.allocatable` that are not extended resources + // (see https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#extended-resources). + // Examples include "cpu", "memory", "ephemeral-storage", and hugepages. + // In addition to standard requests made through the Pod `spec`, these resources + // can also be requested through claims and allocated by the DRA driver. + // For example, a CPU DRA driver might allocate exclusive CPUs or auxiliary node memory + // dependencies of an accelerator device. + // The keys of this map are the node-allocatable resource names (e.g., "cpu", "memory"). + // Extended resource names are not permitted as keys. + NodeAllocatableResourceMappings map[corev1.ResourceName]NodeAllocatableResourceMappingApplyConfiguration `json:"nodeAllocatableResourceMappings,omitempty"` } // DeviceApplyConfiguration constructs a declarative configuration of the Device type for use with @@ -242,3 +255,17 @@ func (b *DeviceApplyConfiguration) WithAllowMultipleAllocations(value bool) *Dev b.AllowMultipleAllocations = &value return b } + +// WithNodeAllocatableResourceMappings puts the entries into the NodeAllocatableResourceMappings field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the NodeAllocatableResourceMappings field, +// overwriting an existing map entries in NodeAllocatableResourceMappings field with the same key. +func (b *DeviceApplyConfiguration) WithNodeAllocatableResourceMappings(entries map[corev1.ResourceName]NodeAllocatableResourceMappingApplyConfiguration) *DeviceApplyConfiguration { + if b.NodeAllocatableResourceMappings == nil && len(entries) > 0 { + b.NodeAllocatableResourceMappings = make(map[corev1.ResourceName]NodeAllocatableResourceMappingApplyConfiguration, len(entries)) + } + for k, v := range entries { + b.NodeAllocatableResourceMappings[k] = v + } + return b +} diff --git a/applyconfigurations/resource/v1beta2/nodeallocatableresourcemapping.go b/applyconfigurations/resource/v1beta2/nodeallocatableresourcemapping.go new file mode 100644 index 000000000..b1490b5e7 --- /dev/null +++ b/applyconfigurations/resource/v1beta2/nodeallocatableresourcemapping.go @@ -0,0 +1,84 @@ +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1beta2 + +import ( + resourcev1beta2 "k8s.io/api/resource/v1beta2" + resource "k8s.io/apimachinery/pkg/api/resource" +) + +// NodeAllocatableResourceMappingApplyConfiguration represents a declarative configuration of the NodeAllocatableResourceMapping type for use +// with apply. +// +// NodeAllocatableResourceMapping defines the translation between the DRA device/capacity +// units requested to the corresponding quantity of the node allocatable resource. +type NodeAllocatableResourceMappingApplyConfiguration struct { + // CapacityKey references a capacity name defined as a key in the + // `spec.devices[*].capacity` map. When this field is set, the value associated with + // this key in the `status.allocation.devices.results[*].consumedCapacity` map + // (for a specific claim allocation) determines the base quantity for + // the node allocatable resource. If `allocationMultiplier` is also set, it is + // multiplied with the base quantity. + // For example, if `spec.devices[*].capacity` has an entry "dra.example.com/memory": "128Gi", + // and this field is set to "dra.example.com/memory", then for a claim allocation + // that consumes { "dra.example.com/memory": "4Gi" } the base quantity for the + // node allocatable resource mapping will be "4Gi", and `allocationMultiplier` should + // be omitted or set to "1". + CapacityKey *resourcev1beta2.QualifiedName `json:"capacityKey,omitempty"` + // AllocationMultiplier is used as a multiplier for the allocated device count or the allocated capacity in the claim. + // It defaults to 1 if not specified. How the field is used also depends on whether `capacityKey` is set. + // 1. If `capacityKey` is NOT set: `allocationMultiplier` multiplies the device count allocated to the claim. + // a. A DRA driver representing each CPU core as a device would have + // {ResourceName: "cpu", allocationMultiplier: "2"} in its + // `nodeAllocatableResourceMappings`. If 4 devices are allocated to the claim, + // 4 * 2 CPUs would be considered as allocated and subtracted from the node's capacity. + // b. A GPU device that needs additional node memory per GPU allocation would + // have {ResourceName: "memory", allocationMultiplier: "2Gi"}. Each allocated + // GPU device instance of this type will account for 2Gi of memory. + // + // 2. If `capacityKey` IS set: `allocationMultiplier` is multiplied by the amount of that capacity consumed. + // The final node allocatable resource amount is `consumedCapacity[capacityKey]` * `allocationMultiplier`. + // For example, if a Device's capacity "dra.example.com/cores" is consumed, + // and each "core" provides 2 "cpu"s, the mapping would be: + // {ResourceName: "cpu", capacityKey: "dra.example.com/cores", allocationMultiplier: "2"}. + // If a claim consumes 8 "dra.example.com/cores", the CPU footprint is 8 * 2 = 16. + AllocationMultiplier *resource.Quantity `json:"allocationMultiplier,omitempty"` +} + +// NodeAllocatableResourceMappingApplyConfiguration constructs a declarative configuration of the NodeAllocatableResourceMapping type for use with +// apply. +func NodeAllocatableResourceMapping() *NodeAllocatableResourceMappingApplyConfiguration { + return &NodeAllocatableResourceMappingApplyConfiguration{} +} + +// WithCapacityKey sets the CapacityKey field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the CapacityKey field is set to the value of the last call. +func (b *NodeAllocatableResourceMappingApplyConfiguration) WithCapacityKey(value resourcev1beta2.QualifiedName) *NodeAllocatableResourceMappingApplyConfiguration { + b.CapacityKey = &value + return b +} + +// WithAllocationMultiplier sets the AllocationMultiplier field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the AllocationMultiplier field is set to the value of the last call. +func (b *NodeAllocatableResourceMappingApplyConfiguration) WithAllocationMultiplier(value resource.Quantity) *NodeAllocatableResourceMappingApplyConfiguration { + b.AllocationMultiplier = &value + return b +} diff --git a/applyconfigurations/utils.go b/applyconfigurations/utils.go index 59d56b2fd..b6b7bae98 100644 --- a/applyconfigurations/utils.go +++ b/applyconfigurations/utils.go @@ -790,6 +790,8 @@ func ForKind(kind schema.GroupVersionKind) interface{} { return &applyconfigurationscorev1.NodeAddressApplyConfiguration{} case corev1.SchemeGroupVersion.WithKind("NodeAffinity"): return &applyconfigurationscorev1.NodeAffinityApplyConfiguration{} + case corev1.SchemeGroupVersion.WithKind("NodeAllocatableResourceClaimStatus"): + return &applyconfigurationscorev1.NodeAllocatableResourceClaimStatusApplyConfiguration{} case corev1.SchemeGroupVersion.WithKind("NodeCondition"): return &applyconfigurationscorev1.NodeConditionApplyConfiguration{} case corev1.SchemeGroupVersion.WithKind("NodeConfigSource"): @@ -1620,6 +1622,8 @@ func ForKind(kind schema.GroupVersionKind) interface{} { return &applyconfigurationsresourcev1.ExactDeviceRequestApplyConfiguration{} case resourcev1.SchemeGroupVersion.WithKind("NetworkDeviceData"): return &applyconfigurationsresourcev1.NetworkDeviceDataApplyConfiguration{} + case resourcev1.SchemeGroupVersion.WithKind("NodeAllocatableResourceMapping"): + return &applyconfigurationsresourcev1.NodeAllocatableResourceMappingApplyConfiguration{} case resourcev1.SchemeGroupVersion.WithKind("OpaqueDeviceConfiguration"): return &applyconfigurationsresourcev1.OpaqueDeviceConfigurationApplyConfiguration{} case resourcev1.SchemeGroupVersion.WithKind("ResourceClaim"): @@ -1712,6 +1716,8 @@ func ForKind(kind schema.GroupVersionKind) interface{} { return &applyconfigurationsresourcev1beta1.DeviceTolerationApplyConfiguration{} case resourcev1beta1.SchemeGroupVersion.WithKind("NetworkDeviceData"): return &applyconfigurationsresourcev1beta1.NetworkDeviceDataApplyConfiguration{} + case resourcev1beta1.SchemeGroupVersion.WithKind("NodeAllocatableResourceMapping"): + return &applyconfigurationsresourcev1beta1.NodeAllocatableResourceMappingApplyConfiguration{} case resourcev1beta1.SchemeGroupVersion.WithKind("OpaqueDeviceConfiguration"): return &applyconfigurationsresourcev1beta1.OpaqueDeviceConfigurationApplyConfiguration{} case resourcev1beta1.SchemeGroupVersion.WithKind("ResourceClaim"): @@ -1800,6 +1806,8 @@ func ForKind(kind schema.GroupVersionKind) interface{} { return &applyconfigurationsresourcev1beta2.ExactDeviceRequestApplyConfiguration{} case resourcev1beta2.SchemeGroupVersion.WithKind("NetworkDeviceData"): return &applyconfigurationsresourcev1beta2.NetworkDeviceDataApplyConfiguration{} + case resourcev1beta2.SchemeGroupVersion.WithKind("NodeAllocatableResourceMapping"): + return &applyconfigurationsresourcev1beta2.NodeAllocatableResourceMappingApplyConfiguration{} case resourcev1beta2.SchemeGroupVersion.WithKind("OpaqueDeviceConfiguration"): return &applyconfigurationsresourcev1beta2.OpaqueDeviceConfigurationApplyConfiguration{} case resourcev1beta2.SchemeGroupVersion.WithKind("ResourceClaim"):