Skip to content

Commit 68e3bad

Browse files
authored
Merge pull request #2162 from Sneha-at/automated-cherry-pick-of-#2112-upstream-release-1.17
Automated cherry pick of #2112: dafult data cache enabled to false
2 parents 3db8137 + e18e794 commit 68e3bad

File tree

5 files changed

+70
-14
lines changed

5 files changed

+70
-14
lines changed

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func handle() {
245245
if err != nil {
246246
klog.Fatalf("Failed to set up metadata service: %v", err.Error())
247247
}
248-
isDataCacheEnabledNodePool, err := isDataCacheEnabledNodePool(ctx, *nodeName)
248+
isDataCacheEnabledNodePool, err := driver.IsDataCacheEnabledNodePool(ctx, *nodeName, *enableDataCacheFlag)
249249
if err != nil {
250250
klog.Fatalf("Failed to get node info from API server: %v", err.Error())
251251
}
@@ -351,17 +351,6 @@ func urlFlag(target **url.URL, name string, usage string) {
351351
})
352352
}
353353

354-
func isDataCacheEnabledNodePool(ctx context.Context, nodeName string) (bool, error) {
355-
if !*enableDataCacheFlag {
356-
return false, nil
357-
}
358-
if len(nodeName) > 0 && nodeName != common.TestNode { // disregard logic below when E2E testing.
359-
dataCacheLSSDCount, err := driver.GetDataCacheCountFromNodeLabel(ctx, nodeName)
360-
return dataCacheLSSDCount != 0, err
361-
}
362-
return true, nil
363-
}
364-
365354
func fetchLssdsForRaiding(lssdCount int) ([]string, error) {
366355
allLssds, err := driver.FetchAllLssds()
367356
if err != nil {

deploy/kubernetes/images/stable-master/image.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ metadata:
2222
name: imagetag-csi-resizer
2323
imageTag:
2424
name: registry.k8s.io/sig-storage/csi-resizer
25-
newTag: "v1.12.0"
25+
newTag: "v1.13.2"
2626
---
2727

2828
apiVersion: builtin

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

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

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

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

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

332332
return false
333333
}
334+
335+
func IsDataCacheEnabledNodePool(ctx context.Context, nodeName string, enableDataCacheFlag bool) (bool, error) {
336+
if !enableDataCacheFlag {
337+
return false, nil
338+
}
339+
if nodeName == common.TestNode { // disregard logic below when E2E testing.
340+
return true, nil
341+
}
342+
if len(nodeName) > 0 {
343+
dataCacheLSSDCount, err := GetDataCacheCountFromNodeLabel(ctx, nodeName)
344+
return dataCacheLSSDCount != 0, err
345+
}
346+
return false, nil
347+
}

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)