Skip to content

Commit 2a95fcf

Browse files
committed
Addressing the feedback and making more CEL changes
Signed-off-by: Yetkin Timocin <ytimocin@microsoft.com>
1 parent d1ac6b5 commit 2a95fcf

17 files changed

Lines changed: 413 additions & 1480 deletions

apis/placement/v1/clusterresourceplacement_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,12 @@ type ResourceSelectorTerm struct {
171171
// Group name of the resource to be selected.
172172
// Use an empty string to select resources under the core API group (e.g., namespaces).
173173
// +kubebuilder:validation:Required
174+
// +kubebuilder:validation:MaxLength=253
174175
Group string `json:"group"`
175176

176177
// Version of the resource to be selected.
177178
// +kubebuilder:validation:Required
179+
// +kubebuilder:validation:MaxLength=63
178180
Version string `json:"version"`
179181

180182
// Kind of the resource to be selected.
@@ -187,13 +189,15 @@ type ResourceSelectorTerm struct {
187189
// - NamespaceWithResources: The namespace AND all resources within it (default)
188190
//
189191
// +kubebuilder:validation:Required
192+
// +kubebuilder:validation:MaxLength=63
190193
Kind string `json:"kind"`
191194

192195
// You can only specify at most one of the following two fields: Name and LabelSelector.
193196
// If none is specified, all resources with the given group, version, and kind are selected.
194197

195198
// Name of the resource to be selected.
196199
// +kubebuilder:validation:Optional
200+
// +kubebuilder:validation:MaxLength=253
197201
Name string `json:"name,omitempty"`
198202

199203
// A label query over all the resources to be selected. Resources matching the query are selected.

apis/placement/v1/override_types.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ type ClusterResourceOverride struct {
4444
// If the resource is selected by both ClusterResourceOverride and ResourceOverride, ResourceOverride will win when resolving
4545
// conflicts.
4646
// +kubebuilder:validation:XValidation:rule="(has(oldSelf.placement) && has(self.placement) && oldSelf.placement == self.placement) || (!has(oldSelf.placement) && !has(self.placement))",message="The placement field is immutable"
47+
// +kubebuilder:validation:XValidation:rule="self.clusterResourceSelectors.all(s, !has(s.labelSelector))",message="labelSelector is not supported for cluster resource override selectors"
48+
// +kubebuilder:validation:XValidation:rule="self.clusterResourceSelectors.all(s, s.name.size() > 0)",message="resource name is required for cluster resource override selectors"
49+
// +kubebuilder:validation:XValidation:rule="self.clusterResourceSelectors.all(x, self.clusterResourceSelectors.exists_one(y, x.group == y.group && x.version == y.version && x.kind == y.kind && x.name == y.name))",message="cluster resource override selectors must be unique"
4750
type ClusterResourceOverrideSpec struct {
4851
// Placement defines whether the override is applied to a specific placement or not.
4952
// If set, the override will trigger the placement rollout immediately when the rollout strategy type is RollingUpdate.
@@ -111,8 +114,10 @@ type OverridePolicy struct {
111114
}
112115

113116
// OverrideRule defines how to override the selected resources on the target clusters.
114-
// +kubebuilder:validation:XValidation:rule="self.overrideType != 'Delete' || !has(self.jsonPatchOverrides) || size(self.jsonPatchOverrides) == 0",message="jsonPatchOverrides must be empty when overrideType is Delete"
117+
// +kubebuilder:validation:XValidation:rule="self.overrideType != 'Delete' || !has(self.jsonPatchOverrides) || size(self.jsonPatchOverrides) == 0",message="jsonPatchOverrides must not be set when overrideType is Delete"
115118
// +kubebuilder:validation:XValidation:rule="self.overrideType != 'JSONPatch' || (has(self.jsonPatchOverrides) && size(self.jsonPatchOverrides) > 0)",message="jsonPatchOverrides must not be empty when overrideType is JSONPatch"
119+
// +kubebuilder:validation:XValidation:rule="!has(self.clusterSelector) || !has(self.clusterSelector.clusterSelectorTerms) || self.clusterSelector.clusterSelectorTerms.all(t, !has(t.propertySelector) && !has(t.propertySorter))",message="only labelSelector is supported for override cluster selectors"
120+
// +kubebuilder:validation:XValidation:rule="!has(self.clusterSelector) || !has(self.clusterSelector.clusterSelectorTerms) || self.clusterSelector.clusterSelectorTerms.all(t, has(t.labelSelector))",message="labelSelector is required for override cluster selector terms"
116121
type OverrideRule struct {
117122
// ClusterSelectors selects the target clusters.
118123
// The resources will be overridden before applying to the matching clusters.
@@ -130,7 +135,6 @@ type OverrideRule struct {
130135

131136
// JSONPatchOverrides defines a list of JSON patch override rules.
132137
// This field is only allowed when OverrideType is JSONPatch.
133-
// +kubebuilder:validation:MinItems=1
134138
// +kubebuilder:validation:MaxItems=20
135139
// +optional
136140
JSONPatchOverrides []JSONPatchOverride `json:"jsonPatchOverrides,omitempty"`
@@ -169,6 +173,7 @@ type ResourceOverride struct {
169173
// If the resource is selected by both ClusterResourceOverride and ResourceOverride, ResourceOverride will win when resolving
170174
// conflicts.
171175
// +kubebuilder:validation:XValidation:rule="(has(oldSelf.placement) && has(self.placement) && oldSelf.placement == self.placement) || (!has(oldSelf.placement) && !has(self.placement))",message="The placement field is immutable"
176+
// +kubebuilder:validation:XValidation:rule="self.resourceSelectors.all(x, self.resourceSelectors.exists_one(y, x.group == y.group && x.version == y.version && x.kind == y.kind && x.name == y.name))",message="resource override selectors must be unique"
172177
type ResourceOverrideSpec struct {
173178
// Placement defines whether the override is applied to a specific placement or not.
174179
// If set, the override will trigger the placement rollout immediately when the rollout strategy type is RollingUpdate.
@@ -196,18 +201,22 @@ type ResourceOverrideSpec struct {
196201
type ResourceSelector struct {
197202
// Group name of the namespace-scoped resource.
198203
// Use an empty string to select resources under the core API group (e.g., services).
204+
// +kubebuilder:validation:MaxLength=253
199205
// +required
200206
Group string `json:"group"`
201207

202208
// Version of the namespace-scoped resource.
209+
// +kubebuilder:validation:MaxLength=63
203210
// +required
204211
Version string `json:"version"`
205212

206213
// Kind of the namespace-scoped resource.
214+
// +kubebuilder:validation:MaxLength=63
207215
// +required
208216
Kind string `json:"kind"`
209217

210218
// Name of the namespace-scoped resource.
219+
// +kubebuilder:validation:MaxLength=253
211220
// +required
212221
Name string `json:"name"`
213222
}

apis/placement/v1beta1/clusterresourceplacement_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,12 @@ type ResourceSelectorTerm struct {
181181
// Group name of the be selected resource.
182182
// Use an empty string to select resources under the core API group (e.g., namespaces).
183183
// +kubebuilder:validation:Required
184+
// +kubebuilder:validation:MaxLength=253
184185
Group string `json:"group"`
185186

186187
// Version of the to be selected resource.
187188
// +kubebuilder:validation:Required
189+
// +kubebuilder:validation:MaxLength=63
188190
Version string `json:"version"`
189191

190192
// Kind of the to be selected resource.
@@ -215,13 +217,15 @@ type ResourceSelectorTerm struct {
215217
// This selects: the "prod" namespace, all Deployments with label app=frontend in "prod", and the "admin" ClusterRole.
216218
//
217219
// +kubebuilder:validation:Required
220+
// +kubebuilder:validation:MaxLength=63
218221
Kind string `json:"kind"`
219222

220223
// You can only specify at most one of the following two fields: Name and LabelSelector.
221224
// If none is specified, all the be selected resources with the given group, version and kind are selected.
222225

223226
// Name of the be selected resource.
224227
// +kubebuilder:validation:Optional
228+
// +kubebuilder:validation:MaxLength=253
225229
Name string `json:"name,omitempty"`
226230

227231
// A label query over all the be selected resources. Resources matching the query are selected.

apis/placement/v1beta1/override_types.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ type ClusterResourceOverride struct {
4545
// If the resource is selected by both ClusterResourceOverride and ResourceOverride, ResourceOverride will win when resolving
4646
// conflicts.
4747
// +kubebuilder:validation:XValidation:rule="(has(oldSelf.placement) && has(self.placement) && oldSelf.placement == self.placement) || (!has(oldSelf.placement) && !has(self.placement))",message="The placement field is immutable"
48+
// +kubebuilder:validation:XValidation:rule="self.clusterResourceSelectors.all(s, !has(s.labelSelector))",message="labelSelector is not supported for cluster resource override selectors"
49+
// +kubebuilder:validation:XValidation:rule="self.clusterResourceSelectors.all(s, s.name.size() > 0)",message="resource name is required for cluster resource override selectors"
50+
// +kubebuilder:validation:XValidation:rule="self.clusterResourceSelectors.all(x, self.clusterResourceSelectors.exists_one(y, x.group == y.group && x.version == y.version && x.kind == y.kind && x.name == y.name))",message="cluster resource override selectors must be unique"
4851
type ClusterResourceOverrideSpec struct {
4952
// Placement defines whether the override is applied to a specific placement or not.
5053
// If set, the override will trigger the placement rollout immediately when the rollout strategy type is RollingUpdate.
@@ -112,8 +115,10 @@ type OverridePolicy struct {
112115
}
113116

114117
// OverrideRule defines how to override the selected resources on the target clusters.
115-
// +kubebuilder:validation:XValidation:rule="self.overrideType != 'Delete' || !has(self.jsonPatchOverrides) || size(self.jsonPatchOverrides) == 0",message="jsonPatchOverrides must be empty when overrideType is Delete"
118+
// +kubebuilder:validation:XValidation:rule="self.overrideType != 'Delete' || !has(self.jsonPatchOverrides) || size(self.jsonPatchOverrides) == 0",message="jsonPatchOverrides must not be set when overrideType is Delete"
116119
// +kubebuilder:validation:XValidation:rule="self.overrideType != 'JSONPatch' || (has(self.jsonPatchOverrides) && size(self.jsonPatchOverrides) > 0)",message="jsonPatchOverrides must not be empty when overrideType is JSONPatch"
120+
// +kubebuilder:validation:XValidation:rule="!has(self.clusterSelector) || !has(self.clusterSelector.clusterSelectorTerms) || self.clusterSelector.clusterSelectorTerms.all(t, !has(t.propertySelector) && !has(t.propertySorter))",message="only labelSelector is supported for override cluster selectors"
121+
// +kubebuilder:validation:XValidation:rule="!has(self.clusterSelector) || !has(self.clusterSelector.clusterSelectorTerms) || self.clusterSelector.clusterSelectorTerms.all(t, has(t.labelSelector))",message="labelSelector is required for override cluster selector terms"
117122
type OverrideRule struct {
118123
// ClusterSelectors selects the target clusters.
119124
// The resources will be overridden before applying to the matching clusters.
@@ -131,7 +136,6 @@ type OverrideRule struct {
131136

132137
// JSONPatchOverrides defines a list of JSON patch override rules.
133138
// This field is only allowed when OverrideType is JSONPatch.
134-
// +kubebuilder:validation:MinItems=1
135139
// +kubebuilder:validation:MaxItems=20
136140
// +optional
137141
JSONPatchOverrides []JSONPatchOverride `json:"jsonPatchOverrides,omitempty"`
@@ -171,6 +175,7 @@ type ResourceOverride struct {
171175
// If the resource is selected by both ClusterResourceOverride and ResourceOverride, ResourceOverride will win when resolving
172176
// conflicts.
173177
// +kubebuilder:validation:XValidation:rule="(has(oldSelf.placement) && has(self.placement) && oldSelf.placement == self.placement) || (!has(oldSelf.placement) && !has(self.placement))",message="The placement field is immutable"
178+
// +kubebuilder:validation:XValidation:rule="self.resourceSelectors.all(x, self.resourceSelectors.exists_one(y, x.group == y.group && x.version == y.version && x.kind == y.kind && x.name == y.name))",message="resource override selectors must be unique"
174179
type ResourceOverrideSpec struct {
175180
// Placement defines whether the override is applied to a specific placement or not.
176181
// If set, the override will trigger the placement rollout immediately when the rollout strategy type is RollingUpdate.
@@ -198,18 +203,22 @@ type ResourceOverrideSpec struct {
198203
type ResourceSelector struct {
199204
// Group name of the namespace-scoped resource.
200205
// Use an empty string to select resources under the core API group (e.g., services).
206+
// +kubebuilder:validation:MaxLength=253
201207
// +required
202208
Group string `json:"group"`
203209

204210
// Version of the namespace-scoped resource.
211+
// +kubebuilder:validation:MaxLength=63
205212
// +required
206213
Version string `json:"version"`
207214

208215
// Kind of the namespace-scoped resource.
216+
// +kubebuilder:validation:MaxLength=63
209217
// +required
210218
Kind string `json:"kind"`
211219

212220
// Name of the namespace-scoped resource.
221+
// +kubebuilder:validation:MaxLength=253
213222
// +required
214223
Name string `json:"name"`
215224
}

0 commit comments

Comments
 (0)