From f65974c297096a6b4e47ea831554ca9b6ee3673d Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Thu, 26 Sep 2024 16:56:48 +0200 Subject: [PATCH] DRA API: use DeviceCapacity struct instead of plain Quantity This enables a future extension where capacity of a single device gets consumed by different claims. The semantic without any additional fields is the same as before: a capacity cannot be split up and is only an attribute of a device. Because its semantically the same as before, two-way conversion to v1alpha3 is possible. Kubernetes-commit: 81fd64256c9cfca47385997e06a694bf98bfb799 --- applyconfigurations/internal/internal.go | 8 +++- .../resource/v1beta1/basicdevice.go | 7 ++- .../resource/v1beta1/devicecapacity.go | 43 +++++++++++++++++++ applyconfigurations/utils.go | 2 + 4 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 applyconfigurations/resource/v1beta1/devicecapacity.go diff --git a/applyconfigurations/internal/internal.go b/applyconfigurations/internal/internal.go index 08a3ec41..4c6dbd01 100644 --- a/applyconfigurations/internal/internal.go +++ b/applyconfigurations/internal/internal.go @@ -12754,7 +12754,7 @@ var schemaYAML = typed.YAMLObject(`types: type: map: elementType: - namedType: io.k8s.apimachinery.pkg.api.resource.Quantity + namedType: io.k8s.api.resource.v1beta1.DeviceCapacity - name: io.k8s.api.resource.v1beta1.CELDeviceSelector map: fields: @@ -12818,6 +12818,12 @@ var schemaYAML = typed.YAMLObject(`types: - name: version type: scalar: string +- name: io.k8s.api.resource.v1beta1.DeviceCapacity + map: + fields: + - name: quantity + type: + namedType: io.k8s.apimachinery.pkg.api.resource.Quantity - name: io.k8s.api.resource.v1beta1.DeviceClaim map: fields: diff --git a/applyconfigurations/resource/v1beta1/basicdevice.go b/applyconfigurations/resource/v1beta1/basicdevice.go index 0c1662c8..691a8f15 100644 --- a/applyconfigurations/resource/v1beta1/basicdevice.go +++ b/applyconfigurations/resource/v1beta1/basicdevice.go @@ -20,14 +20,13 @@ package v1beta1 import ( resourcev1beta1 "k8s.io/api/resource/v1beta1" - resource "k8s.io/apimachinery/pkg/api/resource" ) // BasicDeviceApplyConfiguration represents a declarative configuration of the BasicDevice type for use // with apply. type BasicDeviceApplyConfiguration struct { Attributes map[resourcev1beta1.QualifiedName]DeviceAttributeApplyConfiguration `json:"attributes,omitempty"` - Capacity map[resourcev1beta1.QualifiedName]resource.Quantity `json:"capacity,omitempty"` + Capacity map[resourcev1beta1.QualifiedName]DeviceCapacityApplyConfiguration `json:"capacity,omitempty"` } // BasicDeviceApplyConfiguration constructs a declarative configuration of the BasicDevice type for use with @@ -54,9 +53,9 @@ func (b *BasicDeviceApplyConfiguration) WithAttributes(entries map[resourcev1bet // 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 Capacity field, // overwriting an existing map entries in Capacity field with the same key. -func (b *BasicDeviceApplyConfiguration) WithCapacity(entries map[resourcev1beta1.QualifiedName]resource.Quantity) *BasicDeviceApplyConfiguration { +func (b *BasicDeviceApplyConfiguration) WithCapacity(entries map[resourcev1beta1.QualifiedName]DeviceCapacityApplyConfiguration) *BasicDeviceApplyConfiguration { if b.Capacity == nil && len(entries) > 0 { - b.Capacity = make(map[resourcev1beta1.QualifiedName]resource.Quantity, len(entries)) + b.Capacity = make(map[resourcev1beta1.QualifiedName]DeviceCapacityApplyConfiguration, len(entries)) } for k, v := range entries { b.Capacity[k] = v diff --git a/applyconfigurations/resource/v1beta1/devicecapacity.go b/applyconfigurations/resource/v1beta1/devicecapacity.go new file mode 100644 index 00000000..89c61b12 --- /dev/null +++ b/applyconfigurations/resource/v1beta1/devicecapacity.go @@ -0,0 +1,43 @@ +/* +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 ( + resource "k8s.io/apimachinery/pkg/api/resource" +) + +// DeviceCapacityApplyConfiguration represents a declarative configuration of the DeviceCapacity type for use +// with apply. +type DeviceCapacityApplyConfiguration struct { + Quantity *resource.Quantity `json:"quantity,omitempty"` +} + +// DeviceCapacityApplyConfiguration constructs a declarative configuration of the DeviceCapacity type for use with +// apply. +func DeviceCapacity() *DeviceCapacityApplyConfiguration { + return &DeviceCapacityApplyConfiguration{} +} + +// WithQuantity sets the Quantity 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 Quantity field is set to the value of the last call. +func (b *DeviceCapacityApplyConfiguration) WithQuantity(value resource.Quantity) *DeviceCapacityApplyConfiguration { + b.Quantity = &value + return b +} diff --git a/applyconfigurations/utils.go b/applyconfigurations/utils.go index 0e93baf2..c6b4e120 100644 --- a/applyconfigurations/utils.go +++ b/applyconfigurations/utils.go @@ -1652,6 +1652,8 @@ func ForKind(kind schema.GroupVersionKind) interface{} { return &applyconfigurationsresourcev1beta1.DeviceAllocationResultApplyConfiguration{} case resourcev1beta1.SchemeGroupVersion.WithKind("DeviceAttribute"): return &applyconfigurationsresourcev1beta1.DeviceAttributeApplyConfiguration{} + case resourcev1beta1.SchemeGroupVersion.WithKind("DeviceCapacity"): + return &applyconfigurationsresourcev1beta1.DeviceCapacityApplyConfiguration{} case resourcev1beta1.SchemeGroupVersion.WithKind("DeviceClaim"): return &applyconfigurationsresourcev1beta1.DeviceClaimApplyConfiguration{} case resourcev1beta1.SchemeGroupVersion.WithKind("DeviceClaimConfiguration"):