Skip to content

Commit 0c33c22

Browse files
hungnguyen243cemakd
authored andcommitted
Fix logic bug while checking available LSSDs for RAIDing for Data Cache
1 parent f86f20d commit 0c33c22

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

cmd/gce-pd-csi-driver/main.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -349,24 +349,14 @@ func fetchLssdsForRaiding(lssdCount int) ([]string, error) {
349349
return nil, fmt.Errorf("Error listing RAIDed LSSDs %v", err)
350350
}
351351

352-
unRaidedLssds := []string{}
353-
for _, l := range allLssds {
354-
if !slices.Contains(raidedLssds, l) {
355-
unRaidedLssds = append(unRaidedLssds, l)
356-
}
357-
if len(unRaidedLssds) == lssdCount {
358-
break
359-
}
360-
}
361-
362352
LSSDsWithEmptyMountPoint, err := driver.FetchLSSDsWihtEmptyMountPoint()
363353
if err != nil {
364354
return nil, fmt.Errorf("Error listing LSSDs with empty mountpoint: %v", err)
365355
}
366356

367357
// We need to ensure the disks to be used for Data Cache are both unRAIDed & not containing mountpoints for ephemeral storage already
368-
availableLssds := slices.Filter(nil, unRaidedLssds, func(e string) bool {
369-
return slices.Contains(LSSDsWithEmptyMountPoint, e)
358+
availableLssds := slices.Filter(nil, allLssds, func(e string) bool {
359+
return slices.Contains(LSSDsWithEmptyMountPoint, e) && !slices.Contains(raidedLssds, e)
370360
})
371361

372362
if len(availableLssds) == 0 {
@@ -376,7 +366,8 @@ func fetchLssdsForRaiding(lssdCount int) ([]string, error) {
376366
if len(availableLssds) < lssdCount {
377367
return nil, fmt.Errorf("Not enough LSSDs available to set up caching. Available LSSDs: %v, wanted LSSDs: %v", len(availableLssds), lssdCount)
378368
}
379-
return availableLssds, nil
369+
370+
return availableLssds[:lssdCount], nil
380371
}
381372

382373
func setupDataCache(ctx context.Context, nodeName string) error {

0 commit comments

Comments
 (0)