Skip to content

Commit 4bf46f3

Browse files
feat(tenant): let an administrator list the classes applications may pick
An application's spec.schedulingClass replaces the tenant class for its pods, and the tenant class is the administrator's placement constraint. Without a list of permitted alternatives, anyone who can create an application in the tenant can move it onto any class the cluster defines. allowedSchedulingClasses names those alternatives and defaults to empty, so per-application placement stays off until an administrator opts in. The tenant chart writes it to a namespace annotation, the place the admission policy and the lineage webhook can read it from. A parent that constrains placement passes its list down unchanged, so a child tenant cannot allow a class its parent does not, the same way it cannot replace the parent's class. Assisted-by: LLM Signed-off-by: Mattia Eleuteri <[email protected]>
1 parent 164419b commit 4bf46f3

8 files changed

Lines changed: 134 additions & 15 deletions

File tree

‎api/apps/v1alpha1/tenant/types.go‎

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

‎api/apps/v1alpha1/tenant/zz_generated.deepcopy.go‎

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

‎packages/apps/tenant/README.md‎

Lines changed: 14 additions & 13 deletions
Large diffs are not rendered by default.

‎packages/apps/tenant/templates/namespace.yaml‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@
7676
{{- if and (not $schedulingClass) .Values.schedulingClass }}
7777
{{- $schedulingClass = .Values.schedulingClass }}
7878
{{- end }}
79+
80+
{{/*
81+
Classes an application may pick in place of the tenant class. A parent that
82+
constrains placement passes its list down unchanged, so a child tenant
83+
cannot allow what its parent does not.
84+
*/}}
85+
{{- $allowedSchedulingClasses := .Values.allowedSchedulingClasses | default list }}
86+
{{- if or $parentNamespace.schedulingClass $parentNamespace.allowedSchedulingClasses }}
87+
{{- $allowedSchedulingClasses = $parentNamespace.allowedSchedulingClasses | default list }}
88+
{{- end }}
7989
---
8090
apiVersion: v1
8191
kind: Namespace
@@ -95,6 +105,10 @@ metadata:
95105
scheduler.cozystack.io/scheduling-class: {{ . | quote }}
96106
{{- end }}
97107
alpha.kubevirt.io/auto-memory-limits-ratio: "1.0"
108+
{{- with $allowedSchedulingClasses }}
109+
annotations:
110+
namespace.cozystack.io/allowed-scheduling-classes: {{ join "," . | quote }}
111+
{{- end }}
98112
{{- if $existingNS }}
99113
ownerReferences:
100114
- apiVersion: v1
@@ -131,4 +145,7 @@ stringData:
131145
{{- with $schedulingClass }}
132146
schedulingClass: {{ . | quote }}
133147
{{- end }}
148+
{{- with $allowedSchedulingClasses }}
149+
allowedSchedulingClasses: {{ toJson . }}
150+
{{- end }}
134151
{{- end }}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
suite: tenant allowed scheduling classes
2+
# The namespace annotation is what the scheduling-class admission policy and
3+
# the lineage webhook read to decide which SchedulingClass an application may
4+
# select instead of the tenant's own. A parent that constrains placement must
5+
# pass its list down unchanged, or a child tenant could allow a class its
6+
# parent does not.
7+
templates:
8+
- templates/namespace.yaml
9+
set:
10+
_cluster:
11+
root-host: example.com
12+
release:
13+
name: tenant-child
14+
namespace: tenant-parent
15+
tests:
16+
- it: allows no class by default
17+
asserts:
18+
- documentIndex: 0
19+
notExists:
20+
path: metadata.annotations["namespace.cozystack.io/allowed-scheduling-classes"]
21+
- documentIndex: 1
22+
notMatchRegex:
23+
path: stringData["values.yaml"]
24+
pattern: allowedSchedulingClasses
25+
26+
- it: writes the tenant's own list when the parent constrains nothing
27+
set:
28+
allowedSchedulingClasses: [co-region-a, co-region-b]
29+
asserts:
30+
- documentIndex: 0
31+
equal:
32+
path: metadata.annotations["namespace.cozystack.io/allowed-scheduling-classes"]
33+
value: co-region-a,co-region-b
34+
- documentIndex: 1
35+
matchRegex:
36+
path: stringData["values.yaml"]
37+
pattern: 'allowedSchedulingClasses: \["co-region-a","co-region-b"\]'
38+
39+
- it: ignores the tenant's own list under a parent class with no list
40+
set:
41+
_namespace:
42+
schedulingClass: parent-class
43+
allowedSchedulingClasses: [co-region-a]
44+
asserts:
45+
- documentIndex: 0
46+
equal:
47+
path: metadata.labels["scheduler.cozystack.io/scheduling-class"]
48+
value: parent-class
49+
- documentIndex: 0
50+
notExists:
51+
path: metadata.annotations["namespace.cozystack.io/allowed-scheduling-classes"]
52+
- documentIndex: 1
53+
notMatchRegex:
54+
path: stringData["values.yaml"]
55+
pattern: allowedSchedulingClasses
56+
57+
- it: inherits the parent's list in place of its own
58+
set:
59+
_namespace:
60+
schedulingClass: parent-class
61+
allowedSchedulingClasses: [co-region-a]
62+
allowedSchedulingClasses: [co-region-a, co-region-b]
63+
asserts:
64+
- documentIndex: 0
65+
equal:
66+
path: metadata.annotations["namespace.cozystack.io/allowed-scheduling-classes"]
67+
value: co-region-a
68+
- documentIndex: 1
69+
matchRegex:
70+
path: stringData["values.yaml"]
71+
pattern: 'allowedSchedulingClasses: \["co-region-a"\]'
72+
73+
- it: inherits the parent's list when the parent has a list but no class
74+
set:
75+
_namespace:
76+
allowedSchedulingClasses: [co-region-a]
77+
allowedSchedulingClasses: [co-region-b]
78+
asserts:
79+
- documentIndex: 0
80+
equal:
81+
path: metadata.annotations["namespace.cozystack.io/allowed-scheduling-classes"]
82+
value: co-region-a

‎packages/apps/tenant/values.schema.json‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@
5151
"type": "string",
5252
"default": ""
5353
},
54+
"allowedSchedulingClasses": {
55+
"description": "SchedulingClasses an application in this tenant may select through its own `schedulingClass`, in place of the tenant's. Empty allows none, so every application runs under the tenant's class. Inherited from the parent tenant, and not settable here, when the parent has a `schedulingClass` or a non-empty list.",
56+
"type": "array",
57+
"default": [],
58+
"items": {
59+
"type": "string"
60+
}
61+
},
5462
"resourceQuotas": {
5563
"description": "Define resource quotas for the tenant.",
5664
"type": "object",

‎packages/apps/tenant/values.yaml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,8 @@ computeplane: false
3131
## @param {string} [schedulingClass] - The name of a SchedulingClass CR to apply scheduling constraints for this tenant's workloads.
3232
schedulingClass: ""
3333

34+
## @param {[]string} allowedSchedulingClasses - SchedulingClasses an application in this tenant may select through its own `schedulingClass`, in place of the tenant's. Empty allows none, so every application runs under the tenant's class. Inherited from the parent tenant, and not settable here, when the parent has a `schedulingClass` or a non-empty list.
35+
allowedSchedulingClasses: []
36+
3437
## @param {map[string]quantity} resourceQuotas - Define resource quotas for the tenant.
3538
resourceQuotas: {}

‎packages/system/tenant-rd/cozyrds/tenant.yaml‎

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

0 commit comments

Comments
 (0)