Skip to content

Commit 91cacc4

Browse files
authored
api: add device crd in scheduling group (#376)
Signed-off-by: Jason Liu <jasonliu747@gmail.com>
1 parent f2ed65d commit 91cacc4

File tree

13 files changed

+866
-0
lines changed

13 files changed

+866
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
Copyright 2022 The Koordinator 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 v1alpha1
18+
19+
import (
20+
"k8s.io/apimachinery/pkg/api/resource"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
type DeviceType string
25+
26+
const (
27+
GPU DeviceType = "gpu"
28+
FPGA DeviceType = "fpga"
29+
RDMA DeviceType = "rdma"
30+
)
31+
32+
type DeviceSpec struct {
33+
Devices []DeviceInfo `json:"devices"`
34+
}
35+
36+
type DeviceInfo struct {
37+
// UUID represents the UUID of device
38+
UUID string `json:"id,omitempty"`
39+
// Minor represents the Minor number of Device, starting from 0
40+
Minor int32 `json:"minor,omitempty"`
41+
// Type represents the type of device
42+
Type DeviceType `json:"deviceType,omitempty"`
43+
// Health indicates whether the device is normal
44+
Health bool `json:"health,omitempty"`
45+
// Resources represents the total capacity of various resources of the device
46+
Resources map[string]resource.Quantity `json:"resource,omitempty"`
47+
}
48+
49+
type DeviceStatus struct {
50+
Allocations []DeviceAllocation `json:"allocations"`
51+
}
52+
53+
type DeviceAllocation struct {
54+
Type DeviceType `json:"type"`
55+
Entries []DeviceAllocationItem `json:"entries"`
56+
}
57+
58+
type DeviceAllocationItem struct {
59+
Name string `json:"name"`
60+
Namespace string `json:"namespace"`
61+
UUID string `json:"uuid"`
62+
Devices []string `json:"devices"`
63+
}
64+
65+
// +genclient
66+
// +genclient:nonNamespaced
67+
// +kubebuilder:object:root=true
68+
// +kubebuilder:resource:scope=Cluster
69+
70+
type Device struct {
71+
metav1.TypeMeta `json:",inline"`
72+
metav1.ObjectMeta `json:"metadata,omitempty"`
73+
74+
Spec DeviceSpec `json:"spec,omitempty"`
75+
Status DeviceStatus `json:"status,omitempty"`
76+
}
77+
78+
// +kubebuilder:object:root=true
79+
80+
type DeviceList struct {
81+
metav1.TypeMeta `json:",inline"`
82+
metav1.ListMeta `json:"metadata,omitempty"`
83+
84+
Items []Device `json:"items"`
85+
}
86+
87+
func init() {
88+
SchemeBuilder.Register(&Device{}, &DeviceList{})
89+
}

apis/scheduling/v1alpha1/zz_generated.deepcopy.go

Lines changed: 168 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
controller-gen.kubebuilder.io/version: v0.8.0
7+
creationTimestamp: null
8+
name: devices.scheduling.koordinator.sh
9+
spec:
10+
group: scheduling.koordinator.sh
11+
names:
12+
kind: Device
13+
listKind: DeviceList
14+
plural: devices
15+
singular: device
16+
scope: Cluster
17+
versions:
18+
- name: v1alpha1
19+
schema:
20+
openAPIV3Schema:
21+
properties:
22+
apiVersion:
23+
description: 'APIVersion defines the versioned schema of this representation
24+
of an object. Servers should convert recognized schemas to the latest
25+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
26+
type: string
27+
kind:
28+
description: 'Kind is a string value representing the REST resource this
29+
object represents. Servers may infer this from the endpoint the client
30+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
31+
type: string
32+
metadata:
33+
type: object
34+
spec:
35+
properties:
36+
devices:
37+
items:
38+
properties:
39+
deviceType:
40+
description: Type represents the type of device
41+
type: string
42+
health:
43+
description: Health indicates whether the device is normal
44+
type: boolean
45+
id:
46+
description: UUID represents the UUID of device
47+
type: string
48+
minor:
49+
description: Minor represents the Minor number of Device, starting
50+
from 0
51+
format: int32
52+
type: integer
53+
resource:
54+
additionalProperties:
55+
anyOf:
56+
- type: integer
57+
- type: string
58+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
59+
x-kubernetes-int-or-string: true
60+
description: Resources represents the total capacity of various
61+
resources of the device
62+
type: object
63+
type: object
64+
type: array
65+
required:
66+
- devices
67+
type: object
68+
status:
69+
properties:
70+
allocations:
71+
items:
72+
properties:
73+
entries:
74+
items:
75+
properties:
76+
devices:
77+
items:
78+
type: string
79+
type: array
80+
name:
81+
type: string
82+
namespace:
83+
type: string
84+
uuid:
85+
type: string
86+
required:
87+
- devices
88+
- name
89+
- namespace
90+
- uuid
91+
type: object
92+
type: array
93+
type:
94+
type: string
95+
required:
96+
- entries
97+
- type
98+
type: object
99+
type: array
100+
required:
101+
- allocations
102+
type: object
103+
type: object
104+
served: true
105+
storage: true
106+
status:
107+
acceptedNames:
108+
kind: ""
109+
plural: ""
110+
conditions: []
111+
storedVersions: []

0 commit comments

Comments
 (0)