Skip to content

Commit 139d42b

Browse files
committed
Enhance validation rules and constraints in SandboxPool API
- Added maximum length constraints for RuntimeHandler, SlotProfile, WorkerTemplate names, and AppliedSlot profile. - Updated immutability validation rules for SlotProfiles and WorkerTemplates to ensure consistency during updates. - Enhanced CRD definitions to reflect new validation requirements for resource specifications and limits. - Improved overall API structure for better resource management and validation compliance.
1 parent 10a903a commit 139d42b

2 files changed

Lines changed: 30 additions & 5 deletions

File tree

api/v1alpha1/sandboxpool_types.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type CRIRuntimeConfig struct {
1414
// containerd. It is an opaque string (for example "runsc" or "runc");
1515
// SandboxFleet does not interpret runtime-specific values.
1616
// +kubebuilder:validation:MinLength=1
17+
// +kubebuilder:validation:MaxLength=253
1718
RuntimeHandler string `json:"runtimeHandler"`
1819
}
1920

@@ -29,43 +30,54 @@ type RuntimeConfig struct {
2930
// SlotProfile is a named, fixed resource specification for Slots.
3031
type SlotProfile struct {
3132
// +kubebuilder:validation:MinLength=1
33+
// +kubebuilder:validation:MaxLength=63
3234
Name string `json:"name"`
3335

3436
// Resources is the per-Slot budget. Immutable after the Profile is created.
37+
// Resource changes are rejected by Worker ApplySlots for existing Slot IDs.
3538
Resources corev1.ResourceRequirements `json:"resources"`
3639
}
3740

3841
// SlotGroup declares how many Slots of one Profile each Worker of a Template has.
3942
type SlotGroup struct {
4043
// +kubebuilder:validation:MinLength=1
44+
// +kubebuilder:validation:MaxLength=63
4145
Profile string `json:"profile"`
4246

4347
// +kubebuilder:validation:Minimum=1
48+
// +kubebuilder:validation:Maximum=256
4449
Count int32 `json:"count"`
4550
}
4651

4752
// WorkerTemplate defines a homogeneous set of Worker Pods and their Slot layout.
4853
type WorkerTemplate struct {
4954
// +kubebuilder:validation:MinLength=1
55+
// +kubebuilder:validation:MaxLength=63
5056
Name string `json:"name"`
5157

5258
// +kubebuilder:validation:Minimum=0
59+
// +kubebuilder:validation:Maximum=1000
5360
Replicas int32 `json:"replicas"`
5461

5562
// +kubebuilder:validation:MinItems=1
63+
// +kubebuilder:validation:MaxItems=32
5664
Slots []SlotGroup `json:"slots"`
5765
}
5866

67+
// Runtime and profile/template names are immutable. Profile resources are enforced
68+
// at apply time (existing Slot IDs cannot change resources).
5969
// +kubebuilder:validation:XValidation:rule="self.runtime == oldSelf.runtime",message="runtime is immutable"
60-
// +kubebuilder:validation:XValidation:rule="oldSelf.slotProfiles.all(o, self.slotProfiles.exists(p, p.name == o.name && p.resources == o.resources))",message="slotProfile names and resources are immutable"
61-
// +kubebuilder:validation:XValidation:rule="oldSelf.workerTemplates.all(o, self.workerTemplates.exists(t, t.name == o.name))",message="workerTemplate names are immutable"
70+
// +kubebuilder:validation:XValidation:rule="size(self.slotProfiles) == size(oldSelf.slotProfiles) && oldSelf.slotProfiles.all(o, self.slotProfiles.exists(p, p.name == o.name))",message="slotProfile names are immutable"
71+
// +kubebuilder:validation:XValidation:rule="size(self.workerTemplates) == size(oldSelf.workerTemplates) && oldSelf.workerTemplates.all(o, self.workerTemplates.exists(t, t.name == o.name))",message="workerTemplate names are immutable"
6272
type SandboxPoolSpec struct {
6373
Runtime RuntimeConfig `json:"runtime"`
6474

6575
// +kubebuilder:validation:MinItems=1
76+
// +kubebuilder:validation:MaxItems=32
6677
SlotProfiles []SlotProfile `json:"slotProfiles"`
6778

6879
// +kubebuilder:validation:MinItems=1
80+
// +kubebuilder:validation:MaxItems=32
6981
WorkerTemplates []WorkerTemplate `json:"workerTemplates"`
7082
}
7183

@@ -77,13 +89,15 @@ type WorkerTemplateStatus struct {
7789

7890
// AppliedSlots is the Slot layout currently applied for this Template's Workers.
7991
// +optional
92+
// +kubebuilder:validation:MaxItems=256
8093
AppliedSlots []AppliedSlot `json:"appliedSlots,omitempty"`
8194
}
8295

8396
// AppliedSlot is one Slot in a Template's applied topology.
8497
type AppliedSlot struct {
8598
ID int32 `json:"id"`
8699
// +kubebuilder:validation:MinLength=1
100+
// +kubebuilder:validation:MaxLength=63
87101
Profile string `json:"profile"`
88102
}
89103

config/crd/sandboxpools.yaml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ spec:
4141
x-kubernetes-validations:
4242
- rule: "self.runtime == oldSelf.runtime"
4343
message: runtime is immutable
44-
- rule: "oldSelf.slotProfiles.all(o, self.slotProfiles.exists(p, p.name == o.name && p.resources == o.resources))"
45-
message: slotProfile names and resources are immutable
46-
- rule: "oldSelf.workerTemplates.all(o, self.workerTemplates.exists(t, t.name == o.name))"
44+
- rule: "size(self.slotProfiles) == size(oldSelf.slotProfiles) && oldSelf.slotProfiles.all(o, self.slotProfiles.exists(p, p.name == o.name))"
45+
message: slotProfile names are immutable
46+
- rule: "size(self.workerTemplates) == size(oldSelf.workerTemplates) && oldSelf.workerTemplates.all(o, self.workerTemplates.exists(t, t.name == o.name))"
4747
message: workerTemplate names are immutable
4848
properties:
4949
runtime:
@@ -63,12 +63,14 @@ spec:
6363
runtimeHandler:
6464
type: string
6565
minLength: 1
66+
maxLength: 253
6667
x-kubernetes-validations:
6768
- rule: "self.backend != 'cri' || has(self.cri)"
6869
message: cri configuration is required for the cri backend
6970
slotProfiles:
7071
type: array
7172
minItems: 1
73+
maxItems: 32
7274
items:
7375
type: object
7476
required:
@@ -78,6 +80,7 @@ spec:
7880
name:
7981
type: string
8082
minLength: 1
83+
maxLength: 63
8184
resources:
8285
type: object
8386
properties:
@@ -98,6 +101,7 @@ spec:
98101
workerTemplates:
99102
type: array
100103
minItems: 1
104+
maxItems: 32
101105
items:
102106
type: object
103107
required:
@@ -108,13 +112,16 @@ spec:
108112
name:
109113
type: string
110114
minLength: 1
115+
maxLength: 63
111116
replicas:
112117
type: integer
113118
format: int32
114119
minimum: 0
120+
maximum: 1000
115121
slots:
116122
type: array
117123
minItems: 1
124+
maxItems: 32
118125
items:
119126
type: object
120127
required:
@@ -124,10 +131,12 @@ spec:
124131
profile:
125132
type: string
126133
minLength: 1
134+
maxLength: 63
127135
count:
128136
type: integer
129137
format: int32
130138
minimum: 1
139+
maximum: 256
131140
status:
132141
type: object
133142
properties:
@@ -161,6 +170,7 @@ spec:
161170
format: int32
162171
appliedSlots:
163172
type: array
173+
maxItems: 256
164174
items:
165175
type: object
166176
required:
@@ -173,6 +183,7 @@ spec:
173183
profile:
174184
type: string
175185
minLength: 1
186+
maxLength: 63
176187
profiles:
177188
type: array
178189
items:

0 commit comments

Comments
 (0)