You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// TODO: this is actually a field.Invalid error, but we cannot do JSON serialization of metadata here to get a proper message
142
+
allErrs=append(allErrs, field.Forbidden(fldPath.Child("properties").Key("metadata"), "must not specify anything other than name and generateName, but metadata is implicitly specified"))
allErrs=append(allErrs, field.Required(fldPath.Child("properties"), "must not be empty if x-kubernetes-embedded-resource is true without x-kubernetes-preserve-unknown-fields"))
Copy file name to clipboardExpand all lines: staging/src/k8s.io/apiextensions-apiserver/test/integration/validation_test.go
+108Lines changed: 108 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1222,6 +1222,114 @@ not:
1222
1222
"spec.version[v1].schema.openAPIV3Schema.properties[d]: Required value: because it is defined in spec.version[v1].schema.openAPIV3Schema.not.properties[d]",
1223
1223
},
1224
1224
},
1225
+
{
1226
+
desc: "metadata with non-properties",
1227
+
globalSchema: `
1228
+
type: object
1229
+
properties:
1230
+
metadata:
1231
+
minimum: 42.0
1232
+
`,
1233
+
expectedViolations: []string{
1234
+
"spec.validation.openAPIV3Schema.properties[metadata]: Forbidden: must not specify anything other than name and generateName, but metadata is implicitly specified",
1235
+
"spec.validation.openAPIV3Schema.properties[metadata].type: Required value: must not be empty for specified object fields",
1236
+
},
1237
+
},
1238
+
{
1239
+
desc: "metadata with other properties",
1240
+
globalSchema: `
1241
+
type: object
1242
+
properties:
1243
+
metadata:
1244
+
properties:
1245
+
name:
1246
+
pattern: "^[a-z]+$"
1247
+
labels:
1248
+
type: object
1249
+
maxLength: 4
1250
+
`,
1251
+
expectedViolations: []string{
1252
+
"spec.validation.openAPIV3Schema.properties[metadata]: Forbidden: must not specify anything other than name and generateName, but metadata is implicitly specified",
1253
+
"spec.validation.openAPIV3Schema.properties[metadata].type: Required value: must not be empty for specified object fields",
1254
+
"spec.validation.openAPIV3Schema.properties[metadata].properties[name].type: Required value: must not be empty for specified object fields",
1255
+
},
1256
+
},
1257
+
{
1258
+
desc: "metadata with name property",
1259
+
globalSchema: `
1260
+
type: object
1261
+
properties:
1262
+
metadata:
1263
+
type: object
1264
+
properties:
1265
+
name:
1266
+
type: string
1267
+
pattern: "^[a-z]+$"
1268
+
`,
1269
+
expectedViolations: []string{},
1270
+
},
1271
+
{
1272
+
desc: "metadata with generateName property",
1273
+
globalSchema: `
1274
+
type: object
1275
+
properties:
1276
+
metadata:
1277
+
type: object
1278
+
properties:
1279
+
generateName:
1280
+
type: string
1281
+
pattern: "^[a-z]+$"
1282
+
`,
1283
+
expectedViolations: []string{},
1284
+
},
1285
+
{
1286
+
desc: "metadata with name and generateName property",
1287
+
globalSchema: `
1288
+
type: object
1289
+
properties:
1290
+
metadata:
1291
+
type: object
1292
+
properties:
1293
+
name:
1294
+
type: string
1295
+
pattern: "^[a-z]+$"
1296
+
generateName:
1297
+
type: string
1298
+
pattern: "^[a-z]+$"
1299
+
`,
1300
+
expectedViolations: []string{},
1301
+
},
1302
+
{
1303
+
desc: "metadata under junctors",
1304
+
globalSchema: `
1305
+
type: object
1306
+
properties:
1307
+
metadata:
1308
+
type: object
1309
+
properties:
1310
+
name:
1311
+
type: string
1312
+
pattern: "^[a-z]+$"
1313
+
allOf:
1314
+
- properties:
1315
+
metadata: {}
1316
+
anyOf:
1317
+
- properties:
1318
+
metadata: {}
1319
+
oneOf:
1320
+
- properties:
1321
+
metadata: {}
1322
+
not:
1323
+
properties:
1324
+
metadata: {}
1325
+
`,
1326
+
expectedViolations: []string{
1327
+
"spec.validation.openAPIV3Schema.anyOf[0].properties[metadata]: Forbidden: must not be specified in a nested context",
1328
+
"spec.validation.openAPIV3Schema.allOf[0].properties[metadata]: Forbidden: must not be specified in a nested context",
1329
+
"spec.validation.openAPIV3Schema.oneOf[0].properties[metadata]: Forbidden: must not be specified in a nested context",
1330
+
"spec.validation.openAPIV3Schema.not.properties[metadata]: Forbidden: must not be specified in a nested context",
0 commit comments