Skip to content

Commit 1e6e52f

Browse files
committed
feat: consumable capacity
Signed-off-by: Sunyanan Choochotkaew <[email protected]>
1 parent 640489a commit 1e6e52f

File tree

73 files changed

+8904
-1182
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+8904
-1182
lines changed

.github/workflows/build_push.yaml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Build Kubernetes image
2+
3+
on:
4+
push:
5+
6+
env:
7+
VERSION: "kep-5075"
8+
IMAGE_REGISTRY: ghcr.io/${{ github.repository_owner }}
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
env:
14+
IMAGE_NAME: kindest/node
15+
KUBE_GIT_VERSION: v1.34.0-alpha.0.2276+6f3400c755b5e1-dirty
16+
steps:
17+
- name: Install Kind
18+
run: |
19+
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.27.0/kind-linux-amd64
20+
chmod +x ./kind
21+
mv ./kind /usr/local/bin
22+
- name: Set up Docker
23+
uses: docker/setup-buildx-action@v1
24+
- name: Login to Docker
25+
uses: docker/login-action@v1
26+
with:
27+
registry: ghcr.io
28+
username: ${{ secrets.GH_USERNAME }}
29+
password: ${{ secrets.GH_TOKEN }}
30+
- uses: actions/checkout@v3
31+
- name: Build and Push custom KIND node image
32+
run: |
33+
hack/print-workspace-status.sh
34+
kind build node-image --image ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} .
35+
docker push ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}

go.sum

-159
Large diffs are not rendered by default.

pkg/apis/resource/types.go

+109-2
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,15 @@ type Device struct {
322322
// +listType=atomic
323323
// +featureGate=DRADeviceTaints
324324
Taints []DeviceTaint
325+
326+
// Shared marks whether the device is shared.
327+
//
328+
// The device with shared="true" can be allocated to more than one resource claim,
329+
//
330+
// +optional
331+
// +default=false
332+
// +featureGate=DRAConsumableCapacity
333+
Shared *bool
325334
}
326335

327336
// DeviceCounterConsumption defines a set of counters that
@@ -351,8 +360,60 @@ type DeviceCapacity struct {
351360
// +required
352361
Value resource.Quantity
353362

354-
// potential future addition: fields which define how to "consume"
355-
// capacity (= share a single device between different consumers).
363+
// ClaimPolicy specifies that this device capacity must be consumed
364+
// by each resource claim according to the defined consumption policy.
365+
//
366+
// +optional
367+
// +featureGate=DRAConsumableCapacity
368+
ClaimPolicy *CapacityClaimPolicy
369+
}
370+
371+
// CapacityClaimPolicy defines consumption policy for consumable capacity.
372+
// Either one of the consumption policies must be defined.
373+
type CapacityClaimPolicy struct {
374+
// Set defines a set of acceptable quantities of consuming requests.
375+
//
376+
// +optional
377+
// +oneOf=CapacityClaimPolicy
378+
Set *CapacityClaimPolicySet
379+
380+
// Range defines an acceptable quantity range of consuming requests.
381+
// +optional
382+
// +oneOf=CapacityClaimPolicy
383+
Range *CapacityClaimPolicyRange
384+
}
385+
386+
// CapacityClaimPolicySet defines a discrete set of allowable capacity values for consumption.
387+
type CapacityClaimPolicySet struct {
388+
// Default specifies the default capacity to be used for a consumption request
389+
// if no value is explicitly provided.
390+
//
391+
// +required
392+
Default resource.Quantity
393+
394+
// Options defines a discrete set of additional valid capacity values that can be requested.
395+
// +optional
396+
// +listType=atomic
397+
Options []resource.Quantity
398+
}
399+
400+
// CapacityClaimPolicyRange defines a valid range of consuming capacity.
401+
type CapacityClaimPolicyRange struct {
402+
// Minimum specifies the minimum capacity required for a consumption request.
403+
// This field is required and serves as the default capacity to be consumed.
404+
//
405+
// +required
406+
Minimum resource.Quantity
407+
408+
// Maximum specifies the maximum capacity that can be requested in a consumption request.
409+
//
410+
// +optional
411+
Maximum *resource.Quantity
412+
413+
// Step defines the incremental block size by which capacity can increase from the minimum.
414+
//
415+
// +optional
416+
Step *resource.Quantity
356417
}
357418

358419
// Counter describes a quantity associated with a device.
@@ -640,6 +701,18 @@ type DeviceRequest struct {
640701
FirstAvailable []DeviceSubRequest
641702
}
642703

704+
// CapacityRequirements defines the capacity requirements for a specific device request.
705+
type CapacityRequirements struct {
706+
// Requests specifies the requested quantity of device capacities for a device request,
707+
// keyed by qualified resource names.
708+
// +optional
709+
Requests map[QualifiedName]resource.Quantity
710+
711+
// Potentially enhancement field.
712+
// Limits define the maximum amount of per-device resources allowed.
713+
// This enables burstable usage when applicable.
714+
}
715+
643716
// ExactDeviceRequest is a request for one or more identical devices.
644717
type ExactDeviceRequest struct {
645718
// DeviceClassName references a specific DeviceClass, which can define
@@ -731,6 +804,12 @@ type ExactDeviceRequest struct {
731804
// +listType=atomic
732805
// +featureGate=DRADeviceTaints
733806
Tolerations []DeviceToleration
807+
808+
// Capacities defines resource requirements against each capacity.
809+
//
810+
// +optional
811+
// +featureGate=DRAConsumableCapacity
812+
Capacities *CapacityRequirements
734813
}
735814

736815
// DeviceSubRequest describes a request for device provided in the
@@ -825,6 +904,12 @@ type DeviceSubRequest struct {
825904
// +listType=atomic
826905
// +featureGate=DRADeviceTaints
827906
Tolerations []DeviceToleration
907+
908+
// Capacities defines requirements against capacity.
909+
//
910+
// +optional
911+
// +featureGate=DRAConsumableCapacity
912+
Capacities *CapacityRequirements
828913
}
829914

830915
const (
@@ -968,6 +1053,15 @@ type DeviceConstraint struct {
9681053
// +oneOf=ConstraintType
9691054
MatchAttribute *FullyQualifiedName
9701055

1056+
// DistinctAttribute requires that all devices in question have this
1057+
// attribute and that its type and value are unique across those devices.
1058+
//
1059+
// For example, specify attribute name to get virtual devices from distinct shared physical devices.
1060+
//
1061+
// +optional
1062+
// +oneOf=ConstraintType
1063+
DistinctAttribute *FullyQualifiedName
1064+
9711065
// Potential future extension, not part of the current design:
9721066
// A CEL expression which compares different devices and returns
9731067
// true if they match.
@@ -1272,6 +1366,19 @@ type DeviceRequestAllocationResult struct {
12721366
// +listType=atomic
12731367
// +featureGate=DRADeviceTaints
12741368
Tolerations []DeviceToleration
1369+
1370+
// Shared indicates whether the allocated device can be shared by multiple claims.
1371+
//
1372+
// +optional
1373+
// +featureGate=DRAConsumableCapacity
1374+
Shared *bool
1375+
1376+
// ConsumedCapacities is used for tracking the capacity consumed per device by the claim request.
1377+
// The total consumed capacity for each device must not exceed its corresponding available capacity.
1378+
//
1379+
// +optional
1380+
// +featureGate=DRAConsumableCapacity
1381+
ConsumedCapacities map[QualifiedName]resource.Quantity
12751382
}
12761383

12771384
// DeviceAllocationConfiguration gets embedded in an AllocationResult.

pkg/apis/resource/v1alpha3/zz_generated.conversion.go

+40
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/resource/v1alpha3/zz_generated.defaults.go

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/resource/v1beta1/conversion.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ func convert_v1beta1_Attributes_To_resource_Attributes(in map[resourcev1beta1.Qu
284284
func convert_v1beta1_Capacity_To_resource_Capacity(in map[resourcev1beta1.QualifiedName]resourcev1beta1.DeviceCapacity, out map[resource.QualifiedName]resource.DeviceCapacity, s conversion.Scope) error {
285285
for k, v := range in {
286286
var c resource.DeviceCapacity
287-
if err := Convert_v1beta1_DeviceCapacity_To_resource_DeviceCapacity(&v, &c, s); err != nil {
287+
if err := autoConvert_v1beta1_DeviceCapacity_To_resource_DeviceCapacity(&v, &c, s); err != nil {
288288
return err
289289
}
290290
out[resource.QualifiedName(k)] = c

0 commit comments

Comments
 (0)