Skip to content

Commit 0668037

Browse files
authored
Merge pull request #2115 from tkatila/gpu-fix-empty-allowdeny-list
gpu: fix breakage with allow/deny list being empty
2 parents 0f33db2 + 45479b7 commit 0668037

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

cmd/gpu_plugin/gpu_plugin.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ func packedPolicy(req *pluginapi.ContainerPreferredAllocationRequest) []string {
207207
}
208208

209209
func validatePCIDeviceIDs(pciIDList string) error {
210+
if pciIDList == "" {
211+
return nil
212+
}
213+
210214
r := regexp.MustCompile(`^0x[0-9a-f]{4}$`)
211215

212216
for id := range strings.SplitSeq(pciIDList, ",") {

cmd/gpu_plugin/gpu_plugin_test.go

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ func TestParsePCIDeviceIDs(t *testing.T) {
11601160
{
11611161
name: "empty string",
11621162
input: "",
1163-
wantError: true,
1163+
wantError: false,
11641164
},
11651165
{
11661166
name: "invalid ID format",
@@ -1193,3 +1193,51 @@ func TestParsePCIDeviceIDs(t *testing.T) {
11931193
})
11941194
}
11951195
}
1196+
1197+
func TestCheckAllowDenyOptions(t *testing.T) {
1198+
tcases := []struct {
1199+
name string
1200+
options cliOptions
1201+
expectReturn bool
1202+
}{
1203+
{
1204+
name: "valid allow IDs",
1205+
options: cliOptions{allowIDs: "0x1234,0x5678"},
1206+
expectReturn: true,
1207+
},
1208+
{
1209+
name: "valid deny IDs",
1210+
options: cliOptions{denyIDs: "0x1234,0x5678"},
1211+
expectReturn: true,
1212+
},
1213+
{
1214+
name: "both allow and deny IDs",
1215+
options: cliOptions{allowIDs: "0x1234", denyIDs: "0x5678"},
1216+
expectReturn: false,
1217+
},
1218+
{
1219+
name: "invalid allow ID format",
1220+
options: cliOptions{allowIDs: "0x1234,abcd"},
1221+
expectReturn: false,
1222+
},
1223+
{
1224+
name: "invalid deny ID format",
1225+
options: cliOptions{denyIDs: "0x1234,abcd"},
1226+
expectReturn: false,
1227+
},
1228+
{
1229+
name: "both empty",
1230+
options: cliOptions{allowIDs: "", denyIDs: ""},
1231+
expectReturn: true,
1232+
},
1233+
}
1234+
1235+
for _, tc := range tcases {
1236+
t.Run(tc.name, func(t *testing.T) {
1237+
ret := checkAllowDenyOptions(tc.options)
1238+
if ret != tc.expectReturn {
1239+
t.Errorf("checkAllowDenyOptions() return = %v, expected %v", ret, tc.expectReturn)
1240+
}
1241+
})
1242+
}
1243+
}

0 commit comments

Comments
 (0)