Skip to content

Commit 4c693bb

Browse files
committed
Add Resource Usage API
1 parent 55e6ab3 commit 4c693bb

32 files changed

+3354
-113
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
controller-gen.kubebuilder.io/version: v0.13.0
7+
name: clusterresourceusages.kwok.x-k8s.io
8+
spec:
9+
group: kwok.x-k8s.io
10+
names:
11+
kind: ClusterResourceUsage
12+
listKind: ClusterResourceUsageList
13+
plural: clusterresourceusages
14+
singular: clusterresourceusage
15+
scope: Cluster
16+
versions:
17+
- name: v1alpha1
18+
schema:
19+
openAPIV3Schema:
20+
description: ClusterResourceUsage provides cluster-wide resource usage.
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+
description: Spec holds spec for cluster resource usage.
36+
properties:
37+
selector:
38+
description: Selector is a selector to filter pods to configure.
39+
properties:
40+
matchNames:
41+
description: MatchNames is a list of names to match. if not set,
42+
all names will be matched.
43+
items:
44+
type: string
45+
type: array
46+
matchNamespaces:
47+
description: MatchNamespaces is a list of namespaces to match.
48+
if not set, all namespaces will be matched.
49+
items:
50+
type: string
51+
type: array
52+
type: object
53+
usages:
54+
description: Usages is a list of resource usage for the pod.
55+
items:
56+
description: ResourceUsageContainer holds spec for resource usage
57+
container.
58+
properties:
59+
containers:
60+
description: Containers is list of container names.
61+
items:
62+
type: string
63+
type: array
64+
usage:
65+
additionalProperties:
66+
description: ResourceUsageValue holds value for resource usage.
67+
properties:
68+
expression:
69+
description: Expression is the expression for resource
70+
usage.
71+
type: string
72+
value:
73+
anyOf:
74+
- type: integer
75+
- type: string
76+
description: Value is the value for resource usage.
77+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
78+
x-kubernetes-int-or-string: true
79+
type: object
80+
description: Usage is a list of resource usage for the container.
81+
type: object
82+
type: object
83+
type: array
84+
type: object
85+
status:
86+
description: Status holds status for cluster resource usage
87+
properties:
88+
conditions:
89+
description: Conditions holds conditions for cluster resource usage
90+
items:
91+
description: Condition contains details for one aspect of the current
92+
state of this API Resource.
93+
properties:
94+
lastTransitionTime:
95+
description: LastTransitionTime is the last time the condition
96+
transitioned from one status to another. This should be when
97+
the underlying condition changed. If that is not known, then
98+
using the time when the API field changed is acceptable.
99+
format: date-time
100+
type: string
101+
message:
102+
description: Message is a human readable message indicating
103+
details about the transition. This may be an empty string.
104+
maxLength: 32768
105+
type: string
106+
reason:
107+
description: Reason contains a programmatic identifier indicating
108+
the reason for the condition's last transition. Producers
109+
of specific condition types may define expected values and
110+
meanings for this field, and whether the values are considered
111+
a guaranteed API. The value should be a CamelCase string.
112+
This field may not be empty.
113+
maxLength: 1024
114+
minLength: 1
115+
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
116+
type: string
117+
status:
118+
description: Status of the condition
119+
type: string
120+
type:
121+
description: Type of condition in CamelCase or in foo.example.com/CamelCase.
122+
Many .condition.type values are consistent across resources
123+
like Available, but because arbitrary conditions can be useful
124+
(see .node.status.conditions), the ability to deconflict is
125+
important. The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
126+
maxLength: 316
127+
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
128+
type: string
129+
required:
130+
- lastTransitionTime
131+
- message
132+
- reason
133+
- status
134+
- type
135+
type: object
136+
type: array
137+
x-kubernetes-list-map-keys:
138+
- type
139+
x-kubernetes-list-type: map
140+
type: object
141+
required:
142+
- metadata
143+
- spec
144+
type: object
145+
served: true
146+
storage: true
147+
subresources:
148+
status: {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
controller-gen.kubebuilder.io/version: v0.13.0
7+
name: resourceusages.kwok.x-k8s.io
8+
spec:
9+
group: kwok.x-k8s.io
10+
names:
11+
kind: ResourceUsage
12+
listKind: ResourceUsageList
13+
plural: resourceusages
14+
singular: resourceusage
15+
scope: Namespaced
16+
versions:
17+
- name: v1alpha1
18+
schema:
19+
openAPIV3Schema:
20+
description: ResourceUsage provides resource usage for a single pod.
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+
description: Spec holds spec for resource usage.
36+
properties:
37+
usages:
38+
description: Usages is a list of resource usage for the pod.
39+
items:
40+
description: ResourceUsageContainer holds spec for resource usage
41+
container.
42+
properties:
43+
containers:
44+
description: Containers is list of container names.
45+
items:
46+
type: string
47+
type: array
48+
usage:
49+
additionalProperties:
50+
description: ResourceUsageValue holds value for resource usage.
51+
properties:
52+
expression:
53+
description: Expression is the expression for resource
54+
usage.
55+
type: string
56+
value:
57+
anyOf:
58+
- type: integer
59+
- type: string
60+
description: Value is the value for resource usage.
61+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
62+
x-kubernetes-int-or-string: true
63+
type: object
64+
description: Usage is a list of resource usage for the container.
65+
type: object
66+
type: object
67+
type: array
68+
type: object
69+
status:
70+
description: Status holds status for resource usage
71+
properties:
72+
conditions:
73+
description: Conditions holds conditions for resource usage
74+
items:
75+
description: Condition contains details for one aspect of the current
76+
state of this API Resource.
77+
properties:
78+
lastTransitionTime:
79+
description: LastTransitionTime is the last time the condition
80+
transitioned from one status to another. This should be when
81+
the underlying condition changed. If that is not known, then
82+
using the time when the API field changed is acceptable.
83+
format: date-time
84+
type: string
85+
message:
86+
description: Message is a human readable message indicating
87+
details about the transition. This may be an empty string.
88+
maxLength: 32768
89+
type: string
90+
reason:
91+
description: Reason contains a programmatic identifier indicating
92+
the reason for the condition's last transition. Producers
93+
of specific condition types may define expected values and
94+
meanings for this field, and whether the values are considered
95+
a guaranteed API. The value should be a CamelCase string.
96+
This field may not be empty.
97+
maxLength: 1024
98+
minLength: 1
99+
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
100+
type: string
101+
status:
102+
description: Status of the condition
103+
type: string
104+
type:
105+
description: Type of condition in CamelCase or in foo.example.com/CamelCase.
106+
Many .condition.type values are consistent across resources
107+
like Available, but because arbitrary conditions can be useful
108+
(see .node.status.conditions), the ability to deconflict is
109+
important. The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
110+
maxLength: 316
111+
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
112+
type: string
113+
required:
114+
- lastTransitionTime
115+
- message
116+
- reason
117+
- status
118+
- type
119+
type: object
120+
type: array
121+
x-kubernetes-list-map-keys:
122+
- type
123+
x-kubernetes-list-type: map
124+
type: object
125+
required:
126+
- metadata
127+
- spec
128+
type: object
129+
served: true
130+
storage: true
131+
subresources:
132+
status: {}

kustomize/crd/embed.go

+8
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ var (
5858
//go:embed bases/kwok.x-k8s.io_clusterportforwards.yaml
5959
ClusterPortForward []byte
6060

61+
// ResourceUsage is the custom resource definition for resource usage.
62+
//go:embed bases/kwok.x-k8s.io_resourceusages.yaml
63+
ResourceUsage []byte
64+
65+
// ClusterResourceUsage is the custom resource definition for cluster resource usage.
66+
//go:embed bases/kwok.x-k8s.io_clusterresourceusages.yaml
67+
ClusterResourceUsage []byte
68+
6169
// Metric is the custom resource definition for metrics.
6270
//go:embed bases/kwok.x-k8s.io_metrics.yaml
6371
Metric []byte

kustomize/kwokctl/resource/pod.yaml

+37
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,48 @@ template: |-
2020
{{ range $index, $container := .containers }}
2121
- name: {{ $container.name }}
2222
image: {{ $container.image }}
23+
{{ if and $container $container.resources }}
24+
{{ $resources := $container.resources }}
25+
resources:
26+
requests:
27+
{{ range $key, $value := $resources.requests }}
28+
{{ $key }}: {{ $value }}
29+
{{ end }}
30+
limits:
31+
{{ if $resources.limits }}
32+
{{ range $key, $value := $resources.requests }}
33+
{{ $key }}: {{ or ( index $resources.limits $key ) $value }}
34+
{{ end }}
35+
{{ else }}
36+
{{ range $key, $value := $resources.requests }}
37+
{{ $key }}: {{ $value }}
38+
{{ end }}
39+
{{ end }}
40+
{{ end }}
2341
{{ end }}
42+
2443
initContainers:
2544
{{ range $index, $container := .initContainers }}
2645
- name: {{ $container.name }}
2746
image: {{ $container.image }}
47+
{{ if and $container $container.resources }}
48+
{{ $resources := $container.resources }}
49+
resources:
50+
requests:
51+
{{ range $key, $value := $resources.requests }}
52+
{{ $key }}: {{ $value }}
53+
{{ end }}
54+
limits:
55+
{{ if $resources.limits }}
56+
{{ range $key, $value := $resources.requests }}
57+
{{ $key }}: {{ or ( index $resources.limits $key ) $value }}
58+
{{ end }}
59+
{{ else }}
60+
{{ range $key, $value := $resources.requests }}
61+
{{ $key }}: {{ $value }}
62+
{{ end }}
63+
{{ end }}
64+
{{ end }}
2865
{{ end }}
2966
hostNetwork: {{ .hostNetwork }}
3067
nodeName: {{ .nodeName }}

kustomize/rbac/role.yaml

+31
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,18 @@ rules:
155155
verbs:
156156
- patch
157157
- update
158+
- apiGroups:
159+
- kwok.x-k8s.io
160+
resources:
161+
- clusterresourceusages
162+
verbs:
163+
- create
164+
- delete
165+
- get
166+
- list
167+
- patch
168+
- update
169+
- watch
158170
- apiGroups:
159171
- kwok.x-k8s.io
160172
resources:
@@ -231,6 +243,25 @@ rules:
231243
verbs:
232244
- patch
233245
- update
246+
- apiGroups:
247+
- kwok.x-k8s.io
248+
resources:
249+
- resourceusages
250+
verbs:
251+
- create
252+
- delete
253+
- get
254+
- list
255+
- patch
256+
- update
257+
- watch
258+
- apiGroups:
259+
- kwok.x-k8s.io
260+
resources:
261+
- resourceusages/status
262+
verbs:
263+
- patch
264+
- update
234265
- apiGroups:
235266
- kwok.x-k8s.io
236267
resources:

0 commit comments

Comments
 (0)