From e1cbd0242691273c3ffaecca566d1b1ce43e15c0 Mon Sep 17 00:00:00 2001 From: halimsam Date: Fri, 28 Feb 2025 18:57:53 +0000 Subject: [PATCH] Only run data cache watcher if a data cache nodepool exist & adding check for VG cleanup --- cmd/gce-pd-csi-driver/main.go | 16 ++++++++++------ pkg/gce-pd-csi-driver/cache.go | 4 ++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cmd/gce-pd-csi-driver/main.go b/cmd/gce-pd-csi-driver/main.go index ae554360f..06c1ab7ca 100644 --- a/cmd/gce-pd-csi-driver/main.go +++ b/cmd/gce-pd-csi-driver/main.go @@ -259,10 +259,12 @@ func handle() { if nodeName == nil || *nodeName == "" { klog.Errorf("Data Cache enabled, but --node-name not passed") } - if err := setupDataCache(ctx, *nodeName, nodeServer.MetadataService.GetName()); err != nil { - klog.Errorf("DataCache setup failed: %v", err) + if nsArgs.DataCacheEnabledNodePool { + if err := setupDataCache(ctx, *nodeName, nodeServer.MetadataService.GetName()); err != nil { + klog.Errorf("Data Cache setup failed: %v", err) + } + go driver.StartWatcher(*nodeName) } - go driver.StartWatcher(*nodeName) } } @@ -346,9 +348,11 @@ func urlFlag(target **url.URL, name string, usage string) { } func isDataCacheEnabledNodePool(ctx context.Context, nodeName string) bool { - dataCacheLSSDCount, err := driver.GetDataCacheCountFromNodeLabel(ctx, nodeName) - if err != nil || dataCacheLSSDCount == 0 { - return false + if nodeName != common.TestNode { // disregard logic below when E2E testing. + dataCacheLSSDCount, err := driver.GetDataCacheCountFromNodeLabel(ctx, nodeName) + if err != nil || dataCacheLSSDCount == 0 { + return false + } } return true } diff --git a/pkg/gce-pd-csi-driver/cache.go b/pkg/gce-pd-csi-driver/cache.go index 197ce5e05..691eb4f07 100644 --- a/pkg/gce-pd-csi-driver/cache.go +++ b/pkg/gce-pd-csi-driver/cache.go @@ -453,6 +453,10 @@ func createVg(volumeGroupName string, raidedLocalSsds string) error { } func reduceVolumeGroup(volumeGroupName string, force bool) { + if !checkVgExists(volumeGroupName) { + klog.V(2).Infof("Volume group %v not found, no further action needed", volumeGroupName) + return + } args := []string{ "--removemissing", volumeGroupName,