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
This commit is contained in:
Patrick Ohly 2024-09-26 16:56:48 +02:00 committed by Kubernetes Publisher
parent 98e4506ad9
commit f65974c297
4 changed files with 55 additions and 5 deletions

View File

@ -12754,7 +12754,7 @@ var schemaYAML = typed.YAMLObject(`types:
type: type:
map: map:
elementType: elementType:
namedType: io.k8s.apimachinery.pkg.api.resource.Quantity namedType: io.k8s.api.resource.v1beta1.DeviceCapacity
- name: io.k8s.api.resource.v1beta1.CELDeviceSelector - name: io.k8s.api.resource.v1beta1.CELDeviceSelector
map: map:
fields: fields:
@ -12818,6 +12818,12 @@ var schemaYAML = typed.YAMLObject(`types:
- name: version - name: version
type: type:
scalar: string 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 - name: io.k8s.api.resource.v1beta1.DeviceClaim
map: map:
fields: fields:

View File

@ -20,14 +20,13 @@ package v1beta1
import ( import (
resourcev1beta1 "k8s.io/api/resource/v1beta1" resourcev1beta1 "k8s.io/api/resource/v1beta1"
resource "k8s.io/apimachinery/pkg/api/resource"
) )
// BasicDeviceApplyConfiguration represents a declarative configuration of the BasicDevice type for use // BasicDeviceApplyConfiguration represents a declarative configuration of the BasicDevice type for use
// with apply. // with apply.
type BasicDeviceApplyConfiguration struct { type BasicDeviceApplyConfiguration struct {
Attributes map[resourcev1beta1.QualifiedName]DeviceAttributeApplyConfiguration `json:"attributes,omitempty"` 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 // 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. // 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, // 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. // 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 { 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 { for k, v := range entries {
b.Capacity[k] = v b.Capacity[k] = v

View File

@ -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
}

View File

@ -1652,6 +1652,8 @@ func ForKind(kind schema.GroupVersionKind) interface{} {
return &applyconfigurationsresourcev1beta1.DeviceAllocationResultApplyConfiguration{} return &applyconfigurationsresourcev1beta1.DeviceAllocationResultApplyConfiguration{}
case resourcev1beta1.SchemeGroupVersion.WithKind("DeviceAttribute"): case resourcev1beta1.SchemeGroupVersion.WithKind("DeviceAttribute"):
return &applyconfigurationsresourcev1beta1.DeviceAttributeApplyConfiguration{} return &applyconfigurationsresourcev1beta1.DeviceAttributeApplyConfiguration{}
case resourcev1beta1.SchemeGroupVersion.WithKind("DeviceCapacity"):
return &applyconfigurationsresourcev1beta1.DeviceCapacityApplyConfiguration{}
case resourcev1beta1.SchemeGroupVersion.WithKind("DeviceClaim"): case resourcev1beta1.SchemeGroupVersion.WithKind("DeviceClaim"):
return &applyconfigurationsresourcev1beta1.DeviceClaimApplyConfiguration{} return &applyconfigurationsresourcev1beta1.DeviceClaimApplyConfiguration{}
case resourcev1beta1.SchemeGroupVersion.WithKind("DeviceClaimConfiguration"): case resourcev1beta1.SchemeGroupVersion.WithKind("DeviceClaimConfiguration"):