@@ -924,8 +924,75 @@ func TestControllerSyncPool(t *testing.T) {
924924 },
925925 expectedError : `create ResourceSlice: pool "pool", slice #0: some fields were dropped by the apiserver, probably because these features are disabled: DRAPartitionableDevices` ,
926926 },
927+ "create-device-with-binding-condition" : {
928+ nodeUID : nodeUID ,
929+ inputDriverResources : & DriverResources {
930+ Pools : map [string ]Pool {
931+ poolName : {
932+ Generation : 1 ,
933+ Slices : []Slice {{
934+ Devices : func () []resourceapi.Device {
935+ d := newDevice (deviceName )
936+ d .BindingConditions = []string {"condition1" , "condition2" }
937+ d .BindingFailureConditions = []string {"failure-condition1" }
938+ d .BindsToNode = ptr .To (true )
939+ return []resourceapi.Device {d }
940+ }(),
941+ }},
942+ },
943+ },
944+ },
945+ expectedStats : Stats {
946+ NumCreates : 1 ,
947+ },
948+ expectedResourceSlices : []resourceapi.ResourceSlice {
949+ * MakeResourceSlice ().Name (generatedName1 ).GenerateName (generateName ).
950+ NodeOwnerReferences (ownerName , string (nodeUID )).NodeName (ownerName ).
951+ Driver (driverName ).
952+ Devices (func () []resourceapi.Device {
953+ d := newDevice (deviceName )
954+ d .BindingConditions = []string {"condition1" , "condition2" }
955+ d .BindingFailureConditions = []string {"failure-condition1" }
956+ d .BindsToNode = ptr .To (true )
957+ return []resourceapi.Device {d }
958+ }()).
959+ Pool (resourceapi.ResourcePool {Name : poolName , Generation : 1 , ResourceSliceCount : 1 }).
960+ Obj (),
961+ },
962+ },
963+ "drop-device-with-binding-condition" : {
964+ features : features {disableBindingConditions : true },
965+ nodeUID : nodeUID ,
966+ inputDriverResources : & DriverResources {
967+ Pools : map [string ]Pool {
968+ poolName : {
969+ Generation : 1 ,
970+ Slices : []Slice {{
971+ Devices : func () []resourceapi.Device {
972+ d := newDevice (deviceName )
973+ d .BindingConditions = []string {"condition1" , "condition2" }
974+ d .BindingFailureConditions = []string {"failure-condition1" }
975+ d .BindsToNode = ptr .To (true )
976+ return []resourceapi.Device {d }
977+ }(),
978+ }},
979+ },
980+ },
981+ },
982+ expectedStats : Stats {
983+ NumCreates : 1 ,
984+ },
985+ expectedResourceSlices : []resourceapi.ResourceSlice {
986+ * MakeResourceSlice ().Name (generatedName1 ).GenerateName (generateName ).
987+ NodeOwnerReferences (ownerName , string (nodeUID )).NodeName (ownerName ).
988+ Driver (driverName ).
989+ Devices ([]resourceapi.Device {newDevice (deviceName )}).
990+ Pool (resourceapi.ResourcePool {Name : poolName , Generation : 1 , ResourceSliceCount : 1 }).
991+ Obj (),
992+ },
993+ expectedError : `create ResourceSlice: pool "pool", slice #0: some fields were dropped by the apiserver, probably because these features are disabled: DRADeviceBindingConditions` ,
994+ },
927995 }
928-
929996 for name , test := range testCases {
930997 t .Run (name , func (t * testing.T ) {
931998 _ , ctx := ktesting .NewTestContext (t )
@@ -1050,6 +1117,7 @@ func sortResourceSlices(slices []resourceapi.ResourceSlice) {
10501117}
10511118
10521119type features struct {
1120+ disableBindingConditions bool
10531121 disableDeviceTaints bool
10541122 disablePartitionableDevices bool
10551123}
@@ -1116,6 +1184,13 @@ func dropDisabledFields(features features, resourceslice *resourceapi.ResourceSl
11161184 resourceslice .Spec .Devices [i ].ConsumesCounters = nil
11171185 }
11181186 }
1187+ if features .disableBindingConditions {
1188+ for i := range resourceslice .Spec .Devices {
1189+ resourceslice .Spec .Devices [i ].BindingConditions = nil
1190+ resourceslice .Spec .Devices [i ].BindingFailureConditions = nil
1191+ resourceslice .Spec .Devices [i ].BindsToNode = nil
1192+ }
1193+ }
11191194}
11201195
11211196func addTimeAdded (timeAdded metav1.Time , resourceslice * resourceapi.ResourceSlice ) {
0 commit comments