Skip to content

Commit c435a87

Browse files
authored
Merge pull request kubernetes-sigs#1994 from k8s-infra-cherrypick-robot/cherry-pick-1993-to-release-1.17
[release-1.17] Fix logic bug while checking available LSSDs for RAIDing for Data Cache
2 parents 73f9ad6 + c3442f0 commit c435a87

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

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

+4-13
Original file line numberDiff line numberDiff line change
@@ -368,24 +368,14 @@ func fetchLssdsForRaiding(lssdCount int) ([]string, error) {
368368
return nil, fmt.Errorf("Error listing RAIDed LSSDs %v", err)
369369
}
370370

371-
unRaidedLssds := []string{}
372-
for _, l := range allLssds {
373-
if !slices.Contains(raidedLssds, l) {
374-
unRaidedLssds = append(unRaidedLssds, l)
375-
}
376-
if len(unRaidedLssds) == lssdCount {
377-
break
378-
}
379-
}
380-
381371
LSSDsWithEmptyMountPoint, err := driver.FetchLSSDsWihtEmptyMountPoint()
382372
if err != nil {
383373
return nil, fmt.Errorf("Error listing LSSDs with empty mountpoint: %v", err)
384374
}
385375

386376
// We need to ensure the disks to be used for Data Cache are both unRAIDed & not containing mountpoints for ephemeral storage already
387-
availableLssds := slices.Filter(nil, unRaidedLssds, func(e string) bool {
388-
return slices.Contains(LSSDsWithEmptyMountPoint, e)
377+
availableLssds := slices.Filter(nil, allLssds, func(e string) bool {
378+
return slices.Contains(LSSDsWithEmptyMountPoint, e) && !slices.Contains(raidedLssds, e)
389379
})
390380

391381
if len(availableLssds) == 0 {
@@ -395,7 +385,8 @@ func fetchLssdsForRaiding(lssdCount int) ([]string, error) {
395385
if len(availableLssds) < lssdCount {
396386
return nil, fmt.Errorf("Not enough LSSDs available to set up caching. Available LSSDs: %v, wanted LSSDs: %v", len(availableLssds), lssdCount)
397387
}
398-
return availableLssds, nil
388+
389+
return availableLssds[:lssdCount], nil
399390
}
400391

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

0 commit comments

Comments
 (0)