@@ -924,8 +924,75 @@ func TestControllerSyncPool(t *testing.T) {
924
924
},
925
925
expectedError : `create ResourceSlice: pool "pool", slice #0: some fields were dropped by the apiserver, probably because these features are disabled: DRAPartitionableDevices` ,
926
926
},
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
+ },
927
995
}
928
-
929
996
for name , test := range testCases {
930
997
t .Run (name , func (t * testing.T ) {
931
998
_ , ctx := ktesting .NewTestContext (t )
@@ -1050,6 +1117,7 @@ func sortResourceSlices(slices []resourceapi.ResourceSlice) {
1050
1117
}
1051
1118
1052
1119
type features struct {
1120
+ disableBindingConditions bool
1053
1121
disableDeviceTaints bool
1054
1122
disablePartitionableDevices bool
1055
1123
}
@@ -1116,6 +1184,13 @@ func dropDisabledFields(features features, resourceslice *resourceapi.ResourceSl
1116
1184
resourceslice .Spec .Devices [i ].ConsumesCounters = nil
1117
1185
}
1118
1186
}
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
+ }
1119
1194
}
1120
1195
1121
1196
func addTimeAdded (timeAdded metav1.Time , resourceslice * resourceapi.ResourceSlice ) {
0 commit comments