Skip to content

Commit 3bdcd7a

Browse files
committed
Use CEL validations
Since the new format library is not avaiable in 4.18, use similar validations to what we were doing for v1alpha1. Signed-off-by: Urvashi <[email protected]>
1 parent c90359b commit 3bdcd7a

16 files changed

+142
-1095
lines changed

machineconfiguration/v1/types_machineosbuild.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ type MachineConfigReference struct {
165165
// alphanumeric characters, hyphens and periods, and should start and end with an alphanumeric character.
166166
// +kubebuilder:validation:MinLength:=10
167167
// +kubebuilder:validation:MaxLength:=253
168-
// +kubebuilder:validation:XValidation:rule="!format.dns1123Subdomain().validate(self).hasValue()",message="a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character."
168+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$`
169169
// +required
170170
Name string `json:"name"`
171171
}
@@ -175,32 +175,32 @@ type ObjectReference struct {
175175
// group of the referent.
176176
// The name must contain only lowercase alphanumeric characters, '-' or '.' and start/end with an alphanumeric character.
177177
// Example: "", "apps", "build.openshift.io", etc.
178-
// +kubebuilder:validation:XValidation:rule="!format.dns1123Subdomain().validate(self).hasValue()",message="a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character."
179178
// +kubebuilder:validation:MaxLength:=253
179+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$`
180180
// +required
181181
Group string `json:"group"`
182182
// resource of the referent.
183183
// This value should consist of at most 63 characters, and of only lowercase alphanumeric characters and hyphens,
184184
// and should start and end with an alphanumeric character.
185185
// Example: "deployments", "deploymentconfigs", "pods", etc.
186186
// +required
187-
// +kubebuilder:validation:XValidation:rule=`!format.dns1123Label().validate(self).hasValue()`,message="the value must consist of only lowercase alphanumeric characters and hyphens"
188187
// +kubebuilder:validation:MinLength=1
189188
// +kubebuilder:validation:MaxLength=63
189+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$`
190190
Resource string `json:"resource"`
191191
// namespace of the referent.
192192
// This value should consist of at most 63 characters, and of only lowercase alphanumeric characters and hyphens,
193193
// and should start and end with an alphanumeric character.
194-
// +kubebuilder:validation:XValidation:rule=`!format.dns1123Label().validate(self).hasValue()`,message="the value must consist of only lowercase alphanumeric characters and hyphens"
195194
// +kubebuilder:validation:MinLength=1
196195
// +kubebuilder:validation:MaxLength=63
196+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$`
197197
// +optional
198198
Namespace string `json:"namespace,omitempty"`
199199
// name of the referent.
200200
// The name must contain only lowercase alphanumeric characters, '-' or '.' and start/end with an alphanumeric character.
201-
// +kubebuilder:validation:XValidation:rule="!format.dns1123Subdomain().validate(self).hasValue()",message="a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character."
202201
// +kubebuilder:validation:MinLength=1
203202
// +kubebuilder:validation:MaxLength=253
203+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$`
204204
// +required
205205
Name string `json:"name"`
206206
}
@@ -209,9 +209,9 @@ type ObjectReference struct {
209209
type MachineOSConfigReference struct {
210210
// name of the MachineOSConfig.
211211
// The name must contain only lowercase alphanumeric characters, '-' or '.' and start/end with an alphanumeric character.
212-
// +kubebuilder:validation:XValidation:rule="!format.dns1123Subdomain().validate(self).hasValue()",message="a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character."
213212
// +kubebuilder:validation:MinLength=1
214213
// +kubebuilder:validation:MaxLength=253
214+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$`
215215
// +required
216216
Name string `json:"name"`
217217
}

machineconfiguration/v1/types_machineosconfig.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ type MachineConfigPoolReference struct {
176176
// This value should be at most 253 characters, and must contain only lowercase
177177
// alphanumeric characters, hyphens and periods, and should start and end with an alphanumeric character.
178178
// +kubebuilder:validation:MaxLength:=253
179-
// +kubebuilder:validation:XValidation:rule="!format.dns1123Subdomain().validate(self).hasValue()",message="a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character."
179+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$`
180180
// +required
181181
Name string `json:"name"`
182182
}
@@ -187,7 +187,7 @@ type ImageSecretObjectReference struct {
187187
// Must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character.
188188
// This secret must be in the openshift-machine-config-operator namespace.
189189
// +kubebuilder:validation:MaxLength:=253
190-
// +kubebuilder:validation:XValidation:rule="!format.dns1123Subdomain().validate(self).hasValue()",message="a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character."
190+
// +kubebuilder:validation:Pattern=`^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$`
191191
// +required
192192
Name string `json:"name"`
193193
}

machineconfiguration/v1/zz_generated.crd-manifests/0000_80_machine-config_01_machineosbuilds-CustomNoUpgrade.crd.yaml

+10-46
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,8 @@ spec:
7878
alphanumeric characters, hyphens and periods, and should start and end with an alphanumeric character.
7979
maxLength: 253
8080
minLength: 10
81+
pattern: ^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$
8182
type: string
82-
x-kubernetes-validations:
83-
- message: a lowercase RFC 1123 subdomain must consist of lower
84-
case alphanumeric characters, '-' or '.', and must start and
85-
end with an alphanumeric character.
86-
rule: '!format.dns1123Subdomain().validate(self).hasValue()'
8783
required:
8884
- name
8985
type: object
@@ -97,12 +93,8 @@ spec:
9793
The name must contain only lowercase alphanumeric characters, '-' or '.' and start/end with an alphanumeric character.
9894
maxLength: 253
9995
minLength: 1
96+
pattern: ^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$
10097
type: string
101-
x-kubernetes-validations:
102-
- message: a lowercase RFC 1123 subdomain must consist of lower
103-
case alphanumeric characters, '-' or '.', and must start and
104-
end with an alphanumeric character.
105-
rule: '!format.dns1123Subdomain().validate(self).hasValue()'
10698
required:
10799
- name
108100
type: object
@@ -173,36 +165,25 @@ spec:
173165
The name must contain only lowercase alphanumeric characters, '-' or '.' and start/end with an alphanumeric character.
174166
Example: "", "apps", "build.openshift.io", etc.
175167
maxLength: 253
168+
pattern: ^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$
176169
type: string
177-
x-kubernetes-validations:
178-
- message: a lowercase RFC 1123 subdomain must consist of
179-
lower case alphanumeric characters, '-' or '.', and must
180-
start and end with an alphanumeric character.
181-
rule: '!format.dns1123Subdomain().validate(self).hasValue()'
182170
name:
183171
description: |-
184172
name of the referent.
185173
The name must contain only lowercase alphanumeric characters, '-' or '.' and start/end with an alphanumeric character.
186174
maxLength: 253
187175
minLength: 1
176+
pattern: ^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$
188177
type: string
189-
x-kubernetes-validations:
190-
- message: a lowercase RFC 1123 subdomain must consist of
191-
lower case alphanumeric characters, '-' or '.', and must
192-
start and end with an alphanumeric character.
193-
rule: '!format.dns1123Subdomain().validate(self).hasValue()'
194178
namespace:
195179
description: |-
196180
namespace of the referent.
197181
This value should consist of at most 63 characters, and of only lowercase alphanumeric characters and hyphens,
198182
and should start and end with an alphanumeric character.
199183
maxLength: 63
200184
minLength: 1
185+
pattern: ^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$
201186
type: string
202-
x-kubernetes-validations:
203-
- message: the value must consist of only lowercase alphanumeric
204-
characters and hyphens
205-
rule: '!format.dns1123Label().validate(self).hasValue()'
206187
resource:
207188
description: |-
208189
resource of the referent.
@@ -211,11 +192,8 @@ spec:
211192
Example: "deployments", "deploymentconfigs", "pods", etc.
212193
maxLength: 63
213194
minLength: 1
195+
pattern: ^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$
214196
type: string
215-
x-kubernetes-validations:
216-
- message: the value must consist of only lowercase alphanumeric
217-
characters and hyphens
218-
rule: '!format.dns1123Label().validate(self).hasValue()'
219197
required:
220198
- group
221199
- name
@@ -334,36 +312,25 @@ spec:
334312
The name must contain only lowercase alphanumeric characters, '-' or '.' and start/end with an alphanumeric character.
335313
Example: "", "apps", "build.openshift.io", etc.
336314
maxLength: 253
315+
pattern: ^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$
337316
type: string
338-
x-kubernetes-validations:
339-
- message: a lowercase RFC 1123 subdomain must consist of lower
340-
case alphanumeric characters, '-' or '.', and must start
341-
and end with an alphanumeric character.
342-
rule: '!format.dns1123Subdomain().validate(self).hasValue()'
343317
name:
344318
description: |-
345319
name of the referent.
346320
The name must contain only lowercase alphanumeric characters, '-' or '.' and start/end with an alphanumeric character.
347321
maxLength: 253
348322
minLength: 1
323+
pattern: ^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$
349324
type: string
350-
x-kubernetes-validations:
351-
- message: a lowercase RFC 1123 subdomain must consist of lower
352-
case alphanumeric characters, '-' or '.', and must start
353-
and end with an alphanumeric character.
354-
rule: '!format.dns1123Subdomain().validate(self).hasValue()'
355325
namespace:
356326
description: |-
357327
namespace of the referent.
358328
This value should consist of at most 63 characters, and of only lowercase alphanumeric characters and hyphens,
359329
and should start and end with an alphanumeric character.
360330
maxLength: 63
361331
minLength: 1
332+
pattern: ^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$
362333
type: string
363-
x-kubernetes-validations:
364-
- message: the value must consist of only lowercase alphanumeric
365-
characters and hyphens
366-
rule: '!format.dns1123Label().validate(self).hasValue()'
367334
resource:
368335
description: |-
369336
resource of the referent.
@@ -372,11 +339,8 @@ spec:
372339
Example: "deployments", "deploymentconfigs", "pods", etc.
373340
maxLength: 63
374341
minLength: 1
342+
pattern: ^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$
375343
type: string
376-
x-kubernetes-validations:
377-
- message: the value must consist of only lowercase alphanumeric
378-
characters and hyphens
379-
rule: '!format.dns1123Label().validate(self).hasValue()'
380344
required:
381345
- group
382346
- name

0 commit comments

Comments
 (0)