Skip to content

Commit c87be91

Browse files
authored
Merge pull request #355 from alculquicondor/resourceflavor-metadata-label
Remove ResourceFlavor.labels and use ResourceFlavor.metadata.labels
2 parents 5839bd3 + 018fb8b commit c87be91

File tree

12 files changed

+82
-91
lines changed

12 files changed

+82
-91
lines changed

apis/kueue/v1alpha2/resourceflavor_types.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,15 @@ import (
2424
//+kubebuilder:object:root=true
2525
//+kubebuilder:resource:scope=Cluster
2626

27-
// ResourceFlavor is the Schema for the resourceflavors API
27+
// ResourceFlavor is the Schema for the resourceflavors API.
28+
//
29+
// .metadata.labels associated with this flavor are matched against or
30+
// converted to node affinity constraints on the workload’s pods.
31+
// .metadata.labels can be up to 8 elements.
2832
type ResourceFlavor struct {
2933
metav1.TypeMeta `json:",inline"`
3034
metav1.ObjectMeta `json:"metadata,omitempty"`
3135

32-
// labels associated with this flavor. They are matched against or
33-
// converted to node affinity constraints on the workload’s pods.
34-
// For example, cloud.provider.com/accelerator: nvidia-tesla-k80.
35-
// More info: http://kubernetes.io/docs/user-guide/labels
36-
//
37-
// labels can be up to 8 elements.
38-
Labels map[string]string `json:"labels,omitempty"`
39-
4036
// taints associated with this flavor that workloads must explicitly
4137
// “tolerate” to be able to use this flavor.
4238
// For example, cloud.provider.com/preemptible="true":NoSchedule

apis/kueue/v1alpha2/zz_generated.deepcopy.go

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apis/kueue/webhooks/resourceflavor_webhook.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,9 @@ func (w *ResourceFlavorWebhook) ValidateDelete(ctx context.Context, obj runtime.
8888
func ValidateResourceFlavor(rf *kueue.ResourceFlavor) field.ErrorList {
8989
var allErrs field.ErrorList
9090

91-
labelsPath := field.NewPath("labels")
9291
if len(rf.Labels) > 8 {
93-
allErrs = append(allErrs, field.TooMany(labelsPath, len(rf.Labels), 8))
92+
allErrs = append(allErrs, field.TooMany(field.NewPath("metadata", "labels"), len(rf.Labels), 8))
9493
}
95-
allErrs = append(allErrs, metavalidation.ValidateLabels(rf.Labels, labelsPath)...)
9694

9795
taintsPath := field.NewPath("taints")
9896
if len(rf.Taints) > 8 {

apis/kueue/webhooks/resourceflavor_webhook_test.go

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,6 @@ func TestValidateResourceFlavor(t *testing.T) {
5050
Effect: corev1.TaintEffectNoSchedule,
5151
}).Obj(),
5252
},
53-
{
54-
name: "invalid label name",
55-
rf: utiltesting.MakeResourceFlavor("resource-flavor").MultiLabels(map[string]string{
56-
"foo@bar": "",
57-
}).Obj(),
58-
wantErr: field.ErrorList{
59-
field.Invalid(field.NewPath("labels"), nil, ""),
60-
},
61-
},
62-
{
63-
name: "invalid label value",
64-
rf: utiltesting.MakeResourceFlavor("resource-flavor").MultiLabels(map[string]string{
65-
"foo": "@abcdefg",
66-
}).Obj(),
67-
wantErr: field.ErrorList{
68-
field.Invalid(field.NewPath("labels"), nil, ""),
69-
},
70-
},
7153
{
7254
// Taint validation is not exhaustively tested, because the code was copied from upstream k8s.
7355
name: "invalid taint",
@@ -88,7 +70,7 @@ func TestValidateResourceFlavor(t *testing.T) {
8870
return m
8971
}()).Obj(),
9072
wantErr: field.ErrorList{
91-
field.TooMany(field.NewPath("labels"), 9, 8),
73+
field.TooMany(field.NewPath("metadata", "labels"), 9, 8),
9274
},
9375
},
9476
{

config/components/crd/bases/kueue.x-k8s.io_resourceflavors.yaml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ spec:
1818
- name: v1alpha2
1919
schema:
2020
openAPIV3Schema:
21-
description: ResourceFlavor is the Schema for the resourceflavors API
21+
description: "ResourceFlavor is the Schema for the resourceflavors API. \n
22+
.metadata.labels associated with this flavor are matched against or converted
23+
to node affinity constraints on the workload’s pods. .metadata.labels can
24+
be up to 8 elements."
2225
properties:
2326
apiVersion:
2427
description: 'APIVersion defines the versioned schema of this representation
@@ -30,15 +33,6 @@ spec:
3033
object represents. Servers may infer this from the endpoint the client
3134
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
3235
type: string
33-
labels:
34-
additionalProperties:
35-
type: string
36-
description: "labels associated with this flavor. They are matched against
37-
or converted to node affinity constraints on the workload’s pods. For
38-
example, cloud.provider.com/accelerator: nvidia-tesla-k80. More info:
39-
http://kubernetes.io/docs/user-guide/labels \n labels can be up to 8
40-
elements."
41-
type: object
4236
metadata:
4337
type: object
4438
taints:

docs/concepts/cluster_queue.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ apiVersion: kueue.x-k8s.io/v1alpha1
163163
kind: ResourceFlavor
164164
metadata:
165165
name: spot
166-
labels:
167-
instance-type: spot
166+
labels:
167+
instance-type: spot
168168
taints:
169169
- effect: NoSchedule
170170
key: spot
@@ -177,7 +177,7 @@ ClusterQueue in the `.spec.resources[*].flavors[*].name` field.
177177
### ResourceFlavor labels
178178

179179
To associate a ResourceFlavor with a subset of nodes of you cluster, you can
180-
configure the `.labels` field with matching node labels that uniquely identify
180+
configure the `.metadata.labels` field with matching node labels that uniquely identify
181181
the nodes. If you are using [cluster autoscaler](https://github.com/kubernetes/autoscaler/tree/master/cluster-autoscaler)
182182
(or equivalent controllers), make sure it is configured to add those labels when
183183
adding new nodes.

docs/tasks/administer_cluster_quotas.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ apiVersion: kueue.x-k8s.io/v1alpha1
143143
kind: ResourceFlavor
144144
metadata:
145145
name: x86
146-
labels:
147-
cpu-arch: x86
146+
labels:
147+
cpu-arch: x86
148148
```
149149
150150
```yaml
@@ -153,8 +153,8 @@ apiVersion: kueue.x-k8s.io/v1alpha1
153153
kind: ResourceFlavor
154154
metadata:
155155
name: arm
156-
labels:
157-
cpu-arch: arm
156+
labels:
157+
cpu-arch: arm
158158
```
159159
160160
To create the ResourceFlavors, run the following command:

pkg/cache/cache_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,10 @@ func TestCacheClusterQueueOperations(t *testing.T) {
103103
}
104104
setup := func(cache *Cache) {
105105
cache.AddOrUpdateResourceFlavor(&kueue.ResourceFlavor{
106-
ObjectMeta: metav1.ObjectMeta{Name: "default"},
107-
Labels: map[string]string{"cpuType": "default"},
106+
ObjectMeta: metav1.ObjectMeta{
107+
Name: "default",
108+
Labels: map[string]string{"cpuType": "default"},
109+
},
108110
})
109111
for _, c := range initialClusterQueues {
110112
if err := cache.AddClusterQueue(context.Background(), &c); err != nil {
@@ -189,8 +191,10 @@ func TestCacheClusterQueueOperations(t *testing.T) {
189191
}
190192
}
191193
cache.AddOrUpdateResourceFlavor(&kueue.ResourceFlavor{
192-
ObjectMeta: metav1.ObjectMeta{Name: "default"},
193-
Labels: map[string]string{"cpuType": "default"},
194+
ObjectMeta: metav1.ObjectMeta{
195+
Name: "default",
196+
Labels: map[string]string{"cpuType": "default"},
197+
},
194198
})
195199
},
196200
wantClusterQueues: map[string]*ClusterQueue{
@@ -302,8 +306,10 @@ func TestCacheClusterQueueOperations(t *testing.T) {
302306
}
303307
}
304308
cache.AddOrUpdateResourceFlavor(&kueue.ResourceFlavor{
305-
ObjectMeta: metav1.ObjectMeta{Name: "default"},
306-
Labels: map[string]string{"cpuType": "default", "region": "central"},
309+
ObjectMeta: metav1.ObjectMeta{
310+
Name: "default",
311+
Labels: map[string]string{"cpuType": "default", "region": "central"},
312+
},
307313
})
308314
},
309315
wantClusterQueues: map[string]*ClusterQueue{

pkg/cache/snapshot_test.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,19 @@ func TestSnapshot(t *testing.T) {
152152
}
153153
flavors := []kueue.ResourceFlavor{
154154
{
155-
ObjectMeta: metav1.ObjectMeta{Name: "demand"},
156-
Labels: map[string]string{"foo": "bar", "instance": "demand"},
155+
ObjectMeta: metav1.ObjectMeta{
156+
Name: "demand",
157+
Labels: map[string]string{"foo": "bar", "instance": "demand"},
158+
},
157159
},
158160
{
159-
ObjectMeta: metav1.ObjectMeta{Name: "spot"},
160-
Labels: map[string]string{"baz": "bar", "instance": "spot"},
161+
ObjectMeta: metav1.ObjectMeta{
162+
Name: "spot",
163+
Labels: map[string]string{"baz": "bar", "instance": "spot"},
164+
},
161165
},
162166
{
163167
ObjectMeta: metav1.ObjectMeta{Name: "default"},
164-
Labels: nil,
165168
},
166169
}
167170

@@ -381,15 +384,18 @@ func TestSnapshot(t *testing.T) {
381384
ResourceFlavors: map[string]*kueue.ResourceFlavor{
382385
"default": {
383386
ObjectMeta: metav1.ObjectMeta{Name: "default"},
384-
Labels: nil,
385387
},
386388
"demand": {
387-
ObjectMeta: metav1.ObjectMeta{Name: "demand"},
388-
Labels: map[string]string{"foo": "bar", "instance": "demand"},
389+
ObjectMeta: metav1.ObjectMeta{
390+
Name: "demand",
391+
Labels: map[string]string{"foo": "bar", "instance": "demand"},
392+
},
389393
},
390394
"spot": {
391-
ObjectMeta: metav1.ObjectMeta{Name: "spot"},
392-
Labels: map[string]string{"baz": "bar", "instance": "spot"},
395+
ObjectMeta: metav1.ObjectMeta{
396+
Name: "spot",
397+
Labels: map[string]string{"baz": "bar", "instance": "spot"},
398+
},
393399
},
394400
},
395401
InactiveClusterQueueSets: sets.String{"flavor-nonexistent-cq": {}},

pkg/scheduler/scheduler_test.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -885,20 +885,28 @@ func TestEntryAssignFlavors(t *testing.T) {
885885
ObjectMeta: metav1.ObjectMeta{Name: "default"},
886886
},
887887
"one": {
888-
ObjectMeta: metav1.ObjectMeta{Name: "one"},
889-
Labels: map[string]string{"type": "one"},
888+
ObjectMeta: metav1.ObjectMeta{
889+
Name: "one",
890+
Labels: map[string]string{"type": "one"},
891+
},
890892
},
891893
"two": {
892-
ObjectMeta: metav1.ObjectMeta{Name: "two"},
893-
Labels: map[string]string{"type": "two"},
894+
ObjectMeta: metav1.ObjectMeta{
895+
Name: "two",
896+
Labels: map[string]string{"type": "two"},
897+
},
894898
},
895899
"b_one": {
896-
ObjectMeta: metav1.ObjectMeta{Name: "b_one"},
897-
Labels: map[string]string{"b_type": "one"},
900+
ObjectMeta: metav1.ObjectMeta{
901+
Name: "b_one",
902+
Labels: map[string]string{"b_type": "one"},
903+
},
898904
},
899905
"b_two": {
900-
ObjectMeta: metav1.ObjectMeta{Name: "b_two"},
901-
Labels: map[string]string{"b_type": "two"},
906+
ObjectMeta: metav1.ObjectMeta{
907+
Name: "b_two",
908+
Labels: map[string]string{"b_type": "two"},
909+
},
902910
},
903911
"tainted": {
904912
ObjectMeta: metav1.ObjectMeta{Name: "tainted"},

0 commit comments

Comments
 (0)