@@ -110,7 +110,7 @@ func validateDeviceClaim(deviceClaim *resource.DeviceClaim, fldPath *field.Path,
110
110
}, fldPath .Child ("constraints" ))... )
111
111
allErrs = append (allErrs , validateSlice (deviceClaim .Config , resource .DeviceConfigMaxSize ,
112
112
func (config resource.DeviceClaimConfiguration , fldPath * field.Path ) field.ErrorList {
113
- return validateDeviceClaimConfiguration (config , fldPath , requestNames )
113
+ return validateDeviceClaimConfiguration (config , fldPath , requestNames , stored )
114
114
}, fldPath .Child ("config" ))... )
115
115
return allErrs
116
116
}
@@ -212,13 +212,13 @@ func validateDeviceConstraint(constraint resource.DeviceConstraint, fldPath *fie
212
212
return allErrs
213
213
}
214
214
215
- func validateDeviceClaimConfiguration (config resource.DeviceClaimConfiguration , fldPath * field.Path , requestNames sets.Set [string ]) field.ErrorList {
215
+ func validateDeviceClaimConfiguration (config resource.DeviceClaimConfiguration , fldPath * field.Path , requestNames sets.Set [string ], stored bool ) field.ErrorList {
216
216
var allErrs field.ErrorList
217
217
allErrs = append (allErrs , validateSet (config .Requests , resource .DeviceRequestsMaxSize ,
218
218
func (name string , fldPath * field.Path ) field.ErrorList {
219
219
return validateRequestNameRef (name , fldPath , requestNames )
220
220
}, stringKey , fldPath .Child ("requests" ))... )
221
- allErrs = append (allErrs , validateDeviceConfiguration (config .DeviceConfiguration , fldPath )... )
221
+ allErrs = append (allErrs , validateDeviceConfiguration (config .DeviceConfiguration , fldPath , stored )... )
222
222
return allErrs
223
223
}
224
224
@@ -230,23 +230,29 @@ func validateRequestNameRef(name string, fldPath *field.Path, requestNames sets.
230
230
return allErrs
231
231
}
232
232
233
- func validateDeviceConfiguration (config resource.DeviceConfiguration , fldPath * field.Path ) field.ErrorList {
233
+ func validateDeviceConfiguration (config resource.DeviceConfiguration , fldPath * field.Path , stored bool ) field.ErrorList {
234
234
var allErrs field.ErrorList
235
235
if config .Opaque == nil {
236
236
allErrs = append (allErrs , field .Required (fldPath .Child ("opaque" ), "" ))
237
237
} else {
238
- allErrs = append (allErrs , validateOpaqueConfiguration (* config .Opaque , fldPath .Child ("opaque" ))... )
238
+ allErrs = append (allErrs , validateOpaqueConfiguration (* config .Opaque , fldPath .Child ("opaque" ), stored )... )
239
239
}
240
240
return allErrs
241
241
}
242
242
243
- func validateOpaqueConfiguration (config resource.OpaqueDeviceConfiguration , fldPath * field.Path ) field.ErrorList {
243
+ func validateOpaqueConfiguration (config resource.OpaqueDeviceConfiguration , fldPath * field.Path , stored bool ) field.ErrorList {
244
244
var allErrs field.ErrorList
245
245
allErrs = append (allErrs , validateDriverName (config .Driver , fldPath .Child ("driver" ))... )
246
246
// Validation of RawExtension as in https://github.com/kubernetes/kubernetes/pull/125549/
247
247
var v any
248
248
if len (config .Parameters .Raw ) == 0 {
249
249
allErrs = append (allErrs , field .Required (fldPath .Child ("parameters" ), "" ))
250
+ } else if ! stored && len (config .Parameters .Raw ) > resource .OpaqueParametersMaxLength {
251
+ // Don't even bother with parsing when too large.
252
+ // Only applies on create. Existing parameters are grand-fathered in
253
+ // because the limit was introduced in 1.32. This also means that it
254
+ // can be changed in the future.
255
+ allErrs = append (allErrs , field .TooLong (fldPath .Child ("parameters" ), "" /* unused */ , resource .OpaqueParametersMaxLength ))
250
256
} else if err := json .Unmarshal (config .Parameters .Raw , & v ); err != nil {
251
257
allErrs = append (allErrs , field .Invalid (fldPath .Child ("parameters" ), "<value omitted>" , fmt .Sprintf ("error parsing data as JSON: %v" , err .Error ())))
252
258
} else if v == nil {
@@ -290,7 +296,7 @@ func validateResourceClaimStatusUpdate(status, oldStatus *resource.ResourceClaim
290
296
if oldStatus .Allocation != nil && status .Allocation != nil {
291
297
allErrs = append (allErrs , apimachineryvalidation .ValidateImmutableField (status .Allocation , oldStatus .Allocation , fldPath .Child ("allocation" ))... )
292
298
} else if status .Allocation != nil {
293
- allErrs = append (allErrs , validateAllocationResult (status .Allocation , fldPath .Child ("allocation" ), requestNames )... )
299
+ allErrs = append (allErrs , validateAllocationResult (status .Allocation , fldPath .Child ("allocation" ), requestNames , false )... )
294
300
}
295
301
296
302
return allErrs
@@ -313,24 +319,24 @@ func validateResourceClaimUserReference(ref resource.ResourceClaimConsumerRefere
313
319
// validateAllocationResult enforces constraints for *new* results, which in at
314
320
// least one case (admin access) are more strict than before. Therefore it
315
321
// may not be called to re-validate results which were stored earlier.
316
- func validateAllocationResult (allocation * resource.AllocationResult , fldPath * field.Path , requestNames sets.Set [string ]) field.ErrorList {
322
+ func validateAllocationResult (allocation * resource.AllocationResult , fldPath * field.Path , requestNames sets.Set [string ], stored bool ) field.ErrorList {
317
323
var allErrs field.ErrorList
318
- allErrs = append (allErrs , validateDeviceAllocationResult (allocation .Devices , fldPath .Child ("devices" ), requestNames )... )
324
+ allErrs = append (allErrs , validateDeviceAllocationResult (allocation .Devices , fldPath .Child ("devices" ), requestNames , stored )... )
319
325
if allocation .NodeSelector != nil {
320
326
allErrs = append (allErrs , corevalidation .ValidateNodeSelector (allocation .NodeSelector , fldPath .Child ("nodeSelector" ))... )
321
327
}
322
328
return allErrs
323
329
}
324
330
325
- func validateDeviceAllocationResult (allocation resource.DeviceAllocationResult , fldPath * field.Path , requestNames sets.Set [string ]) field.ErrorList {
331
+ func validateDeviceAllocationResult (allocation resource.DeviceAllocationResult , fldPath * field.Path , requestNames sets.Set [string ], stored bool ) field.ErrorList {
326
332
var allErrs field.ErrorList
327
333
allErrs = append (allErrs , validateSlice (allocation .Results , resource .AllocationResultsMaxSize ,
328
334
func (result resource.DeviceRequestAllocationResult , fldPath * field.Path ) field.ErrorList {
329
335
return validateDeviceRequestAllocationResult (result , fldPath , requestNames )
330
336
}, fldPath .Child ("results" ))... )
331
337
allErrs = append (allErrs , validateSlice (allocation .Config , 2 * resource .DeviceConfigMaxSize , /* class + claim */
332
338
func (config resource.DeviceAllocationConfiguration , fldPath * field.Path ) field.ErrorList {
333
- return validateDeviceAllocationConfiguration (config , fldPath , requestNames )
339
+ return validateDeviceAllocationConfiguration (config , fldPath , requestNames , stored )
334
340
}, fldPath .Child ("config" ))... )
335
341
336
342
return allErrs
@@ -345,14 +351,14 @@ func validateDeviceRequestAllocationResult(result resource.DeviceRequestAllocati
345
351
return allErrs
346
352
}
347
353
348
- func validateDeviceAllocationConfiguration (config resource.DeviceAllocationConfiguration , fldPath * field.Path , requestNames sets.Set [string ]) field.ErrorList {
354
+ func validateDeviceAllocationConfiguration (config resource.DeviceAllocationConfiguration , fldPath * field.Path , requestNames sets.Set [string ], stored bool ) field.ErrorList {
349
355
var allErrs field.ErrorList
350
356
allErrs = append (allErrs , validateAllocationConfigSource (config .Source , fldPath .Child ("source" ))... )
351
357
allErrs = append (allErrs , validateSet (config .Requests , resource .DeviceRequestsMaxSize ,
352
358
func (name string , fldPath * field.Path ) field.ErrorList {
353
359
return validateRequestNameRef (name , fldPath , requestNames )
354
360
}, stringKey , fldPath .Child ("requests" ))... )
355
- allErrs = append (allErrs , validateDeviceConfiguration (config .DeviceConfiguration , fldPath )... )
361
+ allErrs = append (allErrs , validateDeviceConfiguration (config .DeviceConfiguration , fldPath , stored )... )
356
362
return allErrs
357
363
}
358
364
@@ -396,12 +402,20 @@ func validateDeviceClassSpec(spec, oldSpec *resource.DeviceClassSpec, fldPath *f
396
402
return validateSelector (selector , fldPath , stored )
397
403
},
398
404
fldPath .Child ("selectors" ))... )
399
- allErrs = append (allErrs , validateSlice (spec .Config , resource .DeviceConfigMaxSize , validateDeviceClassConfiguration , fldPath .Child ("config" ))... )
405
+ // Same logic as above for configs.
406
+ if oldSpec != nil {
407
+ stored = apiequality .Semantic .DeepEqual (spec .Config , oldSpec .Config )
408
+ }
409
+ allErrs = append (allErrs , validateSlice (spec .Config , resource .DeviceConfigMaxSize ,
410
+ func (config resource.DeviceClassConfiguration , fldPath * field.Path ) field.ErrorList {
411
+ return validateDeviceClassConfiguration (config , fldPath , stored )
412
+ },
413
+ fldPath .Child ("config" ))... )
400
414
return allErrs
401
415
}
402
416
403
- func validateDeviceClassConfiguration (config resource.DeviceClassConfiguration , fldPath * field.Path ) field.ErrorList {
404
- return validateDeviceConfiguration (config .DeviceConfiguration , fldPath )
417
+ func validateDeviceClassConfiguration (config resource.DeviceClassConfiguration , fldPath * field.Path , stored bool ) field.ErrorList {
418
+ return validateDeviceConfiguration (config .DeviceConfiguration , fldPath , stored )
405
419
}
406
420
407
421
// ValidateResourceClaimTemplate validates a ResourceClaimTemplate.
0 commit comments