Skip to content

Commit d6e553a

Browse files
committed
dafult data cache enabled to false
1 parent afcd757 commit d6e553a

File tree

4 files changed

+69
-13
lines changed

4 files changed

+69
-13
lines changed

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func handle() {
270270
if err != nil {
271271
klog.Fatalf("Failed to set up metadata service: %v", err.Error())
272272
}
273-
isDataCacheEnabledNodePool, err := isDataCacheEnabledNodePool(ctx, *nodeName)
273+
isDataCacheEnabledNodePool, err := driver.IsDataCacheEnabledNodePool(ctx, *nodeName, *enableDataCacheFlag)
274274
if err != nil {
275275
klog.Fatalf("Failed to get node info from API server: %v", err.Error())
276276
}
@@ -381,17 +381,6 @@ func urlFlag(target **url.URL, name string, usage string) {
381381
})
382382
}
383383

384-
func isDataCacheEnabledNodePool(ctx context.Context, nodeName string) (bool, error) {
385-
if !*enableDataCacheFlag {
386-
return false, nil
387-
}
388-
if len(nodeName) > 0 && nodeName != common.TestNode { // disregard logic below when E2E testing.
389-
dataCacheLSSDCount, err := driver.GetDataCacheCountFromNodeLabel(ctx, nodeName)
390-
return dataCacheLSSDCount != 0, err
391-
}
392-
return true, nil
393-
}
394-
395384
func fetchLssdsForRaiding(lssdCount int) ([]string, error) {
396385
allLssds, err := driver.FetchAllLssds()
397386
if err != nil {

pkg/gce-pd-csi-driver/node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ func (ns *GCENodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUns
613613

614614
// The NodeUnstageVolume does not have any volume or publish context, we need to get the info from LVM locally
615615
// Check if cache group cache-{volumeID} exist in LVM
616-
if ns.EnableDataCache {
616+
if ns.EnableDataCache && ns.DataCacheEnabledNodePool {
617617
nodeId := ns.MetadataService.GetName()
618618
err := cleanupCache(volumeID, nodeId)
619619
if err != nil {

pkg/gce-pd-csi-driver/utils.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,3 +339,17 @@ func containsZone(zones []string, zone string) bool {
339339

340340
return false
341341
}
342+
343+
func IsDataCacheEnabledNodePool(ctx context.Context, nodeName string, enableDataCacheFlag bool) (bool, error) {
344+
if !enableDataCacheFlag {
345+
return false, nil
346+
}
347+
if nodeName == common.TestNode { // disregard logic below when E2E testing.
348+
return true, nil
349+
}
350+
if len(nodeName) > 0 {
351+
dataCacheLSSDCount, err := GetDataCacheCountFromNodeLabel(ctx, nodeName)
352+
return dataCacheLSSDCount != 0, err
353+
}
354+
return false, nil
355+
}

pkg/gce-pd-csi-driver/utils_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ limitations under the License.
1818
package gceGCEDriver
1919

2020
import (
21+
"context"
2122
"fmt"
2223
"testing"
24+
"time"
2325

2426
csi "github.com/container-storage-interface/spec/lib/go/csi"
2527
"github.com/google/go-cmp/cmp"
@@ -857,3 +859,54 @@ func TestGetHyperdiskAccessModeFromCapabilities(t *testing.T) {
857859
}
858860
}
859861
}
862+
863+
func TestIsDataCacheEnabledNodePool(t *testing.T) {
864+
for _, tc := range []struct {
865+
name string
866+
nodeName string
867+
wantDataCacheEnabled bool
868+
dataCacheFlag bool
869+
wantErr bool
870+
}{
871+
{
872+
// Valid nod ename tries to fetch the data cache count from node labels resulting in an error
873+
name: "node name is provided",
874+
nodeName: "gke-node-some-name",
875+
dataCacheFlag: true,
876+
wantDataCacheEnabled: true,
877+
wantErr: true,
878+
},
879+
{
880+
name: "no node name provided",
881+
nodeName: "",
882+
dataCacheFlag: true,
883+
wantDataCacheEnabled: false,
884+
},
885+
{
886+
name: "test node",
887+
nodeName: common.TestNode,
888+
dataCacheFlag: true,
889+
wantDataCacheEnabled: true,
890+
},
891+
{
892+
name: "node name provided but data cache feature disabled",
893+
nodeName: "",
894+
dataCacheFlag: false,
895+
wantDataCacheEnabled: false,
896+
},
897+
} {
898+
t.Logf("Running test: %v", tc.name)
899+
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
900+
defer cancel()
901+
gotDataCacheEnabled, err := IsDataCacheEnabledNodePool(ctx, tc.nodeName, tc.dataCacheFlag)
902+
if err != nil {
903+
if !tc.wantErr {
904+
t.Errorf("unexpected error, got %v", err)
905+
}
906+
continue
907+
}
908+
if gotDataCacheEnabled != tc.wantDataCacheEnabled {
909+
t.Errorf("want %t, got %t", tc.wantDataCacheEnabled, gotDataCacheEnabled)
910+
}
911+
}
912+
}

0 commit comments

Comments
 (0)