From c3442f0418008e9a7c2bff592fd62ca667a6e0ae Mon Sep 17 00:00:00 2001 From: Hung Nguyen Date: Fri, 14 Mar 2025 19:18:52 +0000 Subject: [PATCH] Fix logic bug while checking available LSSDs for RAIDing for Data Cache --- cmd/gce-pd-csi-driver/main.go | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/cmd/gce-pd-csi-driver/main.go b/cmd/gce-pd-csi-driver/main.go index 06c1ab7ca..460d134a7 100644 --- a/cmd/gce-pd-csi-driver/main.go +++ b/cmd/gce-pd-csi-driver/main.go @@ -368,24 +368,14 @@ func fetchLssdsForRaiding(lssdCount int) ([]string, error) { return nil, fmt.Errorf("Error listing RAIDed LSSDs %v", err) } - unRaidedLssds := []string{} - for _, l := range allLssds { - if !slices.Contains(raidedLssds, l) { - unRaidedLssds = append(unRaidedLssds, l) - } - if len(unRaidedLssds) == lssdCount { - break - } - } - LSSDsWithEmptyMountPoint, err := driver.FetchLSSDsWihtEmptyMountPoint() if err != nil { return nil, fmt.Errorf("Error listing LSSDs with empty mountpoint: %v", err) } // We need to ensure the disks to be used for Data Cache are both unRAIDed & not containing mountpoints for ephemeral storage already - availableLssds := slices.Filter(nil, unRaidedLssds, func(e string) bool { - return slices.Contains(LSSDsWithEmptyMountPoint, e) + availableLssds := slices.Filter(nil, allLssds, func(e string) bool { + return slices.Contains(LSSDsWithEmptyMountPoint, e) && !slices.Contains(raidedLssds, e) }) if len(availableLssds) == 0 { @@ -395,7 +385,8 @@ func fetchLssdsForRaiding(lssdCount int) ([]string, error) { if len(availableLssds) < lssdCount { return nil, fmt.Errorf("Not enough LSSDs available to set up caching. Available LSSDs: %v, wanted LSSDs: %v", len(availableLssds), lssdCount) } - return availableLssds, nil + + return availableLssds[:lssdCount], nil } func setupDataCache(ctx context.Context, nodeName string, nodeId string) error {