@@ -32,6 +32,8 @@ import (
32
32
"text/template"
33
33
)
34
34
35
+ // parseJSONSchemaProps populates the CRD field of each Group.Version.Resource,
36
+ // creating validations using the annotations on type fields.
35
37
func (b * APIs ) parseJSONSchemaProps () {
36
38
for _ , group := range b .APIs .Groups {
37
39
for _ , version := range group .Versions {
@@ -94,6 +96,8 @@ func (b *APIs) getMeta() string {
94
96
}`
95
97
}
96
98
99
+ // typeToJSONSchemaProps returns a JSONSchemaProps object and its serialization
100
+ // in Go that describe the JSONSchema validations for the given type.
97
101
func (b * APIs ) typeToJSONSchemaProps (t * types.Type , found sets.String , comments []string ) (v1beta1.JSONSchemaProps , string ) {
98
102
// Special cases
99
103
time := types.Name {Name : "Time" , Package : "k8s.io/apimachinery/pkg/apis/meta/v1" }
@@ -165,6 +169,9 @@ var primitiveTemplate = template.Must(template.New("map-template").Parse(
165
169
{{ end -}}
166
170
}` ))
167
171
172
+ // parsePrimitiveValidation returns a JSONSchemaProps object and its
173
+ // serialization in Go that describe the validations for the given primitive
174
+ // type.
168
175
func (b * APIs ) parsePrimitiveValidation (t * types.Type , found sets.String , comments []string ) (v1beta1.JSONSchemaProps , string ) {
169
176
props := v1beta1.JSONSchemaProps {Type : string (t .Name .Name )}
170
177
@@ -211,6 +218,8 @@ var mapTemplate = template.Must(template.New("map-template").Parse(
211
218
},
212
219
}` ))
213
220
221
+ // parseMapValidation returns a JSONSchemaProps object and its serialization in
222
+ // Go that describe the validations for the given map type.
214
223
func (b * APIs ) parseMapValidation (t * types.Type , found sets.String , comments []string ) (v1beta1.JSONSchemaProps , string ) {
215
224
additionalProps , _ := b .typeToJSONSchemaProps (t .Elem , found , comments )
216
225
props := v1beta1.JSONSchemaProps {
@@ -235,6 +244,8 @@ var arrayTemplate = template.Must(template.New("array-template").Parse(
235
244
},
236
245
}` ))
237
246
247
+ // parseArrayValidation returns a JSONSchemaProps object and its serialization in
248
+ // Go that describe the validations for the given array type.
238
249
func (b * APIs ) parseArrayValidation (t * types.Type , found sets.String , comments []string ) (v1beta1.JSONSchemaProps , string ) {
239
250
items , result := b .typeToJSONSchemaProps (t .Elem , found , comments )
240
251
props := v1beta1.JSONSchemaProps {
@@ -264,6 +275,8 @@ var objectTemplate = template.Must(template.New("object-template").Parse(
264
275
},
265
276
}` ))
266
277
278
+ // parseObjectValidation returns a JSONSchemaProps object and its serialization in
279
+ // Go that describe the validations for the given object type.
267
280
func (b * APIs ) parseObjectValidation (t * types.Type , found sets.String , comments []string ) (v1beta1.JSONSchemaProps , string ) {
268
281
buff := & bytes.Buffer {}
269
282
props := v1beta1.JSONSchemaProps {
@@ -290,6 +303,8 @@ func (b *APIs) parseObjectValidation(t *types.Type, found sets.String, comments
290
303
return props , buff .String ()
291
304
}
292
305
306
+ // getValidation parses the validation tags from the comment and sets the
307
+ // validation rules on the given JSONSchemaProps.
293
308
func getValidation (comment string , props * v1beta1.JSONSchemaProps ) {
294
309
comment = strings .TrimLeft (comment , " " )
295
310
if ! strings .HasPrefix (comment , "+kubebuilder:validation:" ) {
@@ -392,6 +407,8 @@ func getValidation(comment string, props *v1beta1.JSONSchemaProps) {
392
407
}
393
408
}
394
409
410
+ // getMembers builds maps by field name of the JSONSchemaProps and their Go
411
+ // serializations.
395
412
func (b * APIs ) getMembers (t * types.Type , found sets.String ) (map [string ]v1beta1.JSONSchemaProps , map [string ]string ) {
396
413
members := map [string ]v1beta1.JSONSchemaProps {}
397
414
result := map [string ]string {}
0 commit comments