@@ -25,20 +25,18 @@ import (
25
25
26
26
apiequality "k8s.io/apimachinery/pkg/api/equality"
27
27
apimachineryvalidation "k8s.io/apimachinery/pkg/api/validation"
28
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
28
+ metav1validation "k8s.io/apimachinery/pkg/apis/meta/v1/validation "
29
29
"k8s.io/apimachinery/pkg/runtime"
30
30
"k8s.io/apimachinery/pkg/types"
31
31
"k8s.io/apimachinery/pkg/util/sets"
32
32
"k8s.io/apimachinery/pkg/util/validation"
33
33
"k8s.io/apimachinery/pkg/util/validation/field"
34
34
"k8s.io/apiserver/pkg/cel"
35
35
"k8s.io/apiserver/pkg/cel/environment"
36
- utilfeature "k8s.io/apiserver/pkg/util/feature"
37
36
dracel "k8s.io/dynamic-resource-allocation/cel"
38
37
"k8s.io/dynamic-resource-allocation/structured"
39
38
corevalidation "k8s.io/kubernetes/pkg/apis/core/validation"
40
39
"k8s.io/kubernetes/pkg/apis/resource"
41
- "k8s.io/kubernetes/pkg/features"
42
40
)
43
41
44
42
var (
@@ -268,20 +266,18 @@ func validateResourceClaimStatusUpdate(status, oldStatus *resource.ResourceClaim
268
266
func (consumer resource.ResourceClaimConsumerReference ) (types.UID , string ) { return consumer .UID , "uid" },
269
267
fldPath .Child ("reservedFor" ))... )
270
268
271
- if utilfeature .DefaultFeatureGate .Enabled (features .DRAResourceClaimDeviceStatus ) {
272
- var allocatedDevices sets.Set [structured.DeviceID ]
273
- if status .Allocation != nil {
274
- allocatedDevices = gatherAllocatedDevices (& status .Allocation .Devices )
275
- }
276
- allErrs = append (allErrs , validateSet (status .Devices , - 1 ,
277
- func (device resource.AllocatedDeviceStatus , fldPath * field.Path ) field.ErrorList {
278
- return validateDeviceStatus (device , fldPath , allocatedDevices )
279
- },
280
- func (device resource.AllocatedDeviceStatus ) (structured.DeviceID , string ) {
281
- return structured.DeviceID {Driver : device .Driver , Pool : device .Pool , Device : device .Device }, "deviceID"
282
- },
283
- fldPath .Child ("devices" ))... )
269
+ var allocatedDevices sets.Set [structured.DeviceID ]
270
+ if status .Allocation != nil {
271
+ allocatedDevices = gatherAllocatedDevices (& status .Allocation .Devices )
284
272
}
273
+ allErrs = append (allErrs , validateSet (status .Devices , - 1 ,
274
+ func (device resource.AllocatedDeviceStatus , fldPath * field.Path ) field.ErrorList {
275
+ return validateDeviceStatus (device , fldPath , allocatedDevices )
276
+ },
277
+ func (device resource.AllocatedDeviceStatus ) (structured.DeviceID , string ) {
278
+ return structured.DeviceID {Driver : device .Driver , Pool : device .Pool , Device : device .Device }, "deviceID"
279
+ },
280
+ fldPath .Child ("devices" ))... )
285
281
286
282
// Now check for invariants that must be valid for a ResourceClaim.
287
283
if len (status .ReservedFor ) > 0 {
@@ -748,21 +744,17 @@ func validateDeviceStatus(device resource.AllocatedDeviceStatus, fldPath *field.
748
744
if ! allocatedDevices .Has (deviceID ) {
749
745
allErrs = append (allErrs , field .Invalid (fldPath , deviceID , "must be an allocated device in the claim" ))
750
746
}
751
- allErrs = append (allErrs , validateSlice (device .Conditions , - 1 ,
752
- func (condition metav1.Condition , fldPath * field.Path ) field.ErrorList {
753
- var allErrs field.ErrorList
754
- return allErrs
755
- }, fldPath .Child ("conditions" ))... )
747
+ allErrs = append (allErrs , metav1validation .ValidateConditions (device .Conditions , fldPath .Child ("conditions" ))... )
756
748
if len (device .Data .Raw ) > 0 { // Data is an optional field.
757
749
allErrs = append (allErrs , validateRawExtension (device .Data , fldPath .Child ("data" ))... )
758
750
}
759
751
allErrs = append (allErrs , validateNetworkDeviceData (device .NetworkData , fldPath .Child ("networkData" ))... )
760
752
return allErrs
761
753
}
762
754
755
+ // validateRawExtension validates RawExtension as in https://github.com/kubernetes/kubernetes/pull/125549/
763
756
func validateRawExtension (rawExtension runtime.RawExtension , fldPath * field.Path ) field.ErrorList {
764
757
var allErrs field.ErrorList
765
- // Validation of RawExtension as in https://github.com/kubernetes/kubernetes/pull/125549/
766
758
var v any
767
759
if len (rawExtension .Raw ) == 0 {
768
760
allErrs = append (allErrs , field .Required (fldPath , "" ))
0 commit comments