Skip to content

Commit 9f5e16d

Browse files
mortentk8s-publishing-bot
authored andcommitted
Add resource v1beta2 API
Kubernetes-commit: 39507d911f33d148dd8130468b5f35cfe9fb05bd
1 parent 118546d commit 9f5e16d

File tree

7 files changed

+1725
-29
lines changed

7 files changed

+1725
-29
lines changed

resource/v1alpha3/types.go

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,13 @@ type ResourceSliceSpec struct {
178178
// the portion of counters it uses will no longer be available for use
179179
// by other devices.
180180
type CounterSet struct {
181-
// Name defines the name of the counter set.
182-
// It must be a DNS label.
181+
// CounterSet is the name of the set from which the
182+
// counters defined will be consumed.
183183
//
184184
// +required
185185
Name string `json:"name" protobuf:"bytes,1,name=name"`
186186

187-
// Counters defines the set of counters for this CounterSet
187+
// Counters defines the counters that will be consumed by the device.
188188
// The name of each counter must be unique in that set and must be a DNS label.
189189
//
190190
// To ensure this uniqueness, capacities defined by the vendor
@@ -284,20 +284,21 @@ type BasicDevice struct {
284284
// +optional
285285
Capacity map[QualifiedName]resource.Quantity `json:"capacity,omitempty" protobuf:"bytes,2,rep,name=capacity"`
286286

287-
// ConsumesCounter defines a list of references to sharedCounters
287+
// ConsumesCounters defines a list of references to sharedCounters
288288
// and the set of counters that the device will
289289
// consume from those counter sets.
290290
//
291291
// There can only be a single entry per counterSet.
292292
//
293-
// The maximum number of device counter consumption entries
294-
// is 32. This is the same as the maximum number of shared counters
295-
// allowed in a ResourceSlice.
293+
// The total number of device counter consumption entries
294+
// must be <= 32. In addition, the total number in the
295+
// entire ResourceSlice must be <= 1024 (for example,
296+
// 64 devices with 16 counters each).
296297
//
297298
// +optional
298299
// +listType=atomic
299300
// +featureGate=DRAPartitionableDevices
300-
ConsumesCounter []DeviceCounterConsumption `json:"consumesCounter,omitempty" protobuf:"bytes,3,rep,name=consumesCounter"`
301+
ConsumesCounters []DeviceCounterConsumption `json:"consumesCounters,omitempty" protobuf:"bytes,3,rep,name=consumesCounters"`
301302

302303
// NodeName identifies the node where the device is available.
303304
//
@@ -331,7 +332,7 @@ type BasicDevice struct {
331332

332333
// If specified, these are the driver-defined taints.
333334
//
334-
// The maximum number of taints is 8.
335+
// The maximum number of taints is 4.
335336
//
336337
// This is an alpha field and requires enabling the DRADeviceTaints
337338
// feature gate.
@@ -345,17 +346,19 @@ type BasicDevice struct {
345346
// DeviceCounterConsumption defines a set of counters that
346347
// a device will consume from a CounterSet.
347348
type DeviceCounterConsumption struct {
348-
// SharedCounter defines the shared counter from which the
349+
// CounterSet defines the set from which the
349350
// counters defined will be consumed.
350351
//
351352
// +required
352-
SharedCounter string `json:"sharedCounter" protobuf:"bytes,1,opt,name=sharedCounter"`
353+
CounterSet string `json:"counterSet" protobuf:"bytes,1,opt,name=counterSet"`
353354

354355
// Counters defines the Counter that will be consumed by
355356
// the device.
356357
//
357-
//
358-
// The maximum number of Counters is 32.
358+
// The maximum number counters in a device is 32.
359+
// In addition, the maximum number of all counters
360+
// in all devices is 1024 (for example, 64 devices with
361+
// 16 counters each).
359362
//
360363
// +required
361364
Counters map[string]Counter `json:"counters,omitempty" protobuf:"bytes,2,opt,name=counters"`
@@ -364,6 +367,14 @@ type DeviceCounterConsumption struct {
364367
// Limit for the sum of the number of entries in both attributes and capacity.
365368
const ResourceSliceMaxAttributesAndCapacitiesPerDevice = 32
366369

370+
// Limit for the total number of counters in each device.
371+
const ResourceSliceMaxCountersPerDevice = 32
372+
373+
// Limit for the total number of counters defined in devices in
374+
// a ResourceSlice. We want to allow up to 64 devices to specify
375+
// up to 16 counters, so the limit for the ResourceSlice will be 1024.
376+
const ResourceSliceMaxDeviceCountersPerSlice = 1024 // 64 * 16
377+
367378
// QualifiedName is the name of a device attribute or capacity.
368379
//
369380
// Attributes and capacities are defined either by the owner of the specific
@@ -427,7 +438,7 @@ type DeviceAttribute struct {
427438
const DeviceAttributeMaxValueLength = 64
428439

429440
// DeviceTaintsMaxLength is the maximum number of taints per device.
430-
const DeviceTaintsMaxLength = 8
441+
const DeviceTaintsMaxLength = 4
431442

432443
// The device this taint is attached to has the "effect" on
433444
// any claim which does not tolerate the taint and, through the claim,
@@ -784,7 +795,7 @@ type DeviceSubRequest struct {
784795
// Allocation will fail if some devices are already allocated,
785796
// unless adminAccess is requested.
786797
//
787-
// If AlloctionMode is not specified, the default mode is ExactCount. If
798+
// If AllocationMode is not specified, the default mode is ExactCount. If
788799
// the mode is ExactCount and count is not specified, the default count is
789800
// one. Any other requests must specify this field.
790801
//

resource/v1beta1/types.go

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -279,20 +279,21 @@ type BasicDevice struct {
279279
// +optional
280280
Capacity map[QualifiedName]DeviceCapacity `json:"capacity,omitempty" protobuf:"bytes,2,rep,name=capacity"`
281281

282-
// ConsumesCounter defines a list of references to sharedCounters
282+
// ConsumesCounters defines a list of references to sharedCounters
283283
// and the set of counters that the device will
284284
// consume from those counter sets.
285285
//
286286
// There can only be a single entry per counterSet.
287287
//
288-
// The maximum number of device counter consumption entries
289-
// is 32. This is the same as the maximum number of shared counters
290-
// allowed in a ResourceSlice.
288+
// The total number of device counter consumption entries
289+
// must be <= 32. In addition, the total number in the
290+
// entire ResourceSlice must be <= 1024 (for example,
291+
// 64 devices with 16 counters each).
291292
//
292293
// +optional
293294
// +listType=atomic
294295
// +featureGate=DRAPartitionableDevices
295-
ConsumesCounter []DeviceCounterConsumption `json:"consumesCounter,omitempty" protobuf:"bytes,3,rep,name=consumesCounter"`
296+
ConsumesCounters []DeviceCounterConsumption `json:"consumesCounters,omitempty" protobuf:"bytes,3,rep,name=consumesCounters"`
296297

297298
// NodeName identifies the node where the device is available.
298299
//
@@ -306,6 +307,8 @@ type BasicDevice struct {
306307

307308
// NodeSelector defines the nodes where the device is available.
308309
//
310+
// Must use exactly one term.
311+
//
309312
// Must only be set if Spec.PerDeviceNodeSelection is set to true.
310313
// At most one of NodeName, NodeSelector and AllNodes can be set.
311314
//
@@ -325,7 +328,7 @@ type BasicDevice struct {
325328

326329
// If specified, these are the driver-defined taints.
327330
//
328-
// The maximum number of taints is 8.
331+
// The maximum number of taints is 4.
329332
//
330333
// This is an alpha field and requires enabling the DRADeviceTaints
331334
// feature gate.
@@ -339,17 +342,18 @@ type BasicDevice struct {
339342
// DeviceCounterConsumption defines a set of counters that
340343
// a device will consume from a CounterSet.
341344
type DeviceCounterConsumption struct {
342-
// SharedCounter defines the shared counter from which the
345+
// CounterSet is the name of the set from which the
343346
// counters defined will be consumed.
344347
//
345348
// +required
346-
SharedCounter string `json:"sharedCounter" protobuf:"bytes,1,opt,name=sharedCounter"`
349+
CounterSet string `json:"counterSet" protobuf:"bytes,1,opt,name=counterSet"`
347350

348-
// Counters defines the Counter that will be consumed by
349-
// the device.
350-
//
351+
// Counters defines the counters that will be consumed by the device.
351352
//
352-
// The maximum number of Counters is 32.
353+
// The maximum number counters in a device is 32.
354+
// In addition, the maximum number of all counters
355+
// in all devices is 1024 (for example, 64 devices with
356+
// 16 counters each).
353357
//
354358
// +required
355359
Counters map[string]Counter `json:"counters,omitempty" protobuf:"bytes,2,opt,name=counters"`
@@ -369,6 +373,14 @@ type DeviceCapacity struct {
369373
// Limit for the sum of the number of entries in both attributes and capacity.
370374
const ResourceSliceMaxAttributesAndCapacitiesPerDevice = 32
371375

376+
// Limit for the total number of counters in each device.
377+
const ResourceSliceMaxCountersPerDevice = 32
378+
379+
// Limit for the total number of counters defined in devices in
380+
// a ResourceSlice. We want to allow up to 64 devices to specify
381+
// up to 16 counters, so the limit for the ResourceSlice will be 1024.
382+
const ResourceSliceMaxDeviceCountersPerSlice = 1024 // 64 * 16
383+
372384
// QualifiedName is the name of a device attribute or capacity.
373385
//
374386
// Attributes and capacities are defined either by the owner of the specific
@@ -432,7 +444,7 @@ type DeviceAttribute struct {
432444
const DeviceAttributeMaxValueLength = 64
433445

434446
// DeviceTaintsMaxLength is the maximum number of taints per device.
435-
const DeviceTaintsMaxLength = 8
447+
const DeviceTaintsMaxLength = 4
436448

437449
// The device this taint is attached to has the "effect" on
438450
// any claim which does not tolerate the taint and, through the claim,
@@ -790,7 +802,7 @@ type DeviceSubRequest struct {
790802
// Allocation will fail if some devices are already allocated,
791803
// unless adminAccess is requested.
792804
//
793-
// If AlloctionMode is not specified, the default mode is ExactCount. If
805+
// If AllocationMode is not specified, the default mode is ExactCount. If
794806
// the mode is ExactCount and count is not specified, the default count is
795807
// one. Any other subrequests must specify this field.
796808
//

resource/v1beta2/devicetaint.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Copyright 2025 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 v1beta2
18+
19+
import "fmt"
20+
21+
var _ fmt.Stringer = DeviceTaint{}
22+
23+
// String converts to a string in the format '<key>=<value>:<effect>', '<key>=<value>:', '<key>:<effect>', or '<key>'.
24+
func (t DeviceTaint) String() string {
25+
if len(t.Effect) == 0 {
26+
if len(t.Value) == 0 {
27+
return fmt.Sprintf("%v", t.Key)
28+
}
29+
return fmt.Sprintf("%v=%v:", t.Key, t.Value)
30+
}
31+
if len(t.Value) == 0 {
32+
return fmt.Sprintf("%v:%v", t.Key, t.Effect)
33+
}
34+
return fmt.Sprintf("%v=%v:%v", t.Key, t.Value, t.Effect)
35+
}

resource/v1beta2/doc.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
Copyright 2025 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+
// +k8s:openapi-gen=true
18+
// +k8s:deepcopy-gen=package
19+
// +k8s:protobuf-gen=package
20+
// +k8s:prerelease-lifecycle-gen=true
21+
// +groupName=resource.k8s.io
22+
23+
// Package v1beta2 is the v1beta2 version of the resource API.
24+
package v1beta2

resource/v1beta2/register.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
Copyright 2025 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 v1beta2
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
"k8s.io/apimachinery/pkg/runtime"
22+
"k8s.io/apimachinery/pkg/runtime/schema"
23+
)
24+
25+
// GroupName is the group name use in this package
26+
const GroupName = "resource.k8s.io"
27+
28+
// SchemeGroupVersion is group version used to register these objects
29+
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1beta2"}
30+
31+
// Resource takes an unqualified resource and returns a Group qualified GroupResource
32+
func Resource(resource string) schema.GroupResource {
33+
return SchemeGroupVersion.WithResource(resource).GroupResource()
34+
}
35+
36+
var (
37+
// We only register manually written functions here. The registration of the
38+
// generated functions takes place in the generated files. The separation
39+
// makes the code compile even when the generated files are missing.
40+
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
41+
AddToScheme = SchemeBuilder.AddToScheme
42+
)
43+
44+
// Adds the list of known types to the given scheme.
45+
func addKnownTypes(scheme *runtime.Scheme) error {
46+
scheme.AddKnownTypes(SchemeGroupVersion,
47+
&DeviceClass{},
48+
&DeviceClassList{},
49+
&ResourceClaim{},
50+
&ResourceClaimList{},
51+
&ResourceClaimTemplate{},
52+
&ResourceClaimTemplateList{},
53+
&ResourceSlice{},
54+
&ResourceSliceList{},
55+
)
56+
57+
// Add the watch version that applies
58+
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
59+
return nil
60+
}

0 commit comments

Comments
 (0)