Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions cmd/gce-pd-csi-driver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func handle() {
if err != nil {
klog.Fatalf("Failed to set up metadata service: %v", err.Error())
}
isDataCacheEnabledNodePool, err := isDataCacheEnabledNodePool(ctx, *nodeName)
isDataCacheEnabledNodePool, err := driver.IsDataCacheEnabledNodePool(ctx, *nodeName, *enableDataCacheFlag)
if err != nil {
klog.Fatalf("Failed to get node info from API server: %v", err.Error())
}
Expand Down Expand Up @@ -351,17 +351,6 @@ func urlFlag(target **url.URL, name string, usage string) {
})
}

func isDataCacheEnabledNodePool(ctx context.Context, nodeName string) (bool, error) {
if !*enableDataCacheFlag {
return false, nil
}
if len(nodeName) > 0 && nodeName != common.TestNode { // disregard logic below when E2E testing.
dataCacheLSSDCount, err := driver.GetDataCacheCountFromNodeLabel(ctx, nodeName)
return dataCacheLSSDCount != 0, err
}
return true, nil
}

func fetchLssdsForRaiding(lssdCount int) ([]string, error) {
allLssds, err := driver.FetchAllLssds()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion deploy/kubernetes/images/stable-master/image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ metadata:
name: imagetag-csi-resizer
imageTag:
name: registry.k8s.io/sig-storage/csi-resizer
newTag: "v1.12.0"
newTag: "v1.13.2"
---

apiVersion: builtin
Expand Down
2 changes: 1 addition & 1 deletion pkg/gce-pd-csi-driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ func (ns *GCENodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUns

// The NodeUnstageVolume does not have any volume or publish context, we need to get the info from LVM locally
// Check if cache group cache-{volumeID} exist in LVM
if ns.EnableDataCache {
if ns.EnableDataCache && ns.DataCacheEnabledNodePool {
nodeId := ns.MetadataService.GetName()
err := cleanupCache(volumeID, nodeId)
if err != nil {
Expand Down
14 changes: 14 additions & 0 deletions pkg/gce-pd-csi-driver/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,17 @@ func containsZone(zones []string, zone string) bool {

return false
}

func IsDataCacheEnabledNodePool(ctx context.Context, nodeName string, enableDataCacheFlag bool) (bool, error) {
if !enableDataCacheFlag {
return false, nil
}
if nodeName == common.TestNode { // disregard logic below when E2E testing.
return true, nil
}
if len(nodeName) > 0 {
dataCacheLSSDCount, err := GetDataCacheCountFromNodeLabel(ctx, nodeName)
return dataCacheLSSDCount != 0, err
}
return false, nil
}
53 changes: 53 additions & 0 deletions pkg/gce-pd-csi-driver/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ limitations under the License.
package gceGCEDriver

import (
"context"
"fmt"
"testing"
"time"

csi "github.com/container-storage-interface/spec/lib/go/csi"
"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -857,3 +859,54 @@ func TestGetHyperdiskAccessModeFromCapabilities(t *testing.T) {
}
}
}

func TestIsDataCacheEnabledNodePool(t *testing.T) {
for _, tc := range []struct {
name string
nodeName string
wantDataCacheEnabled bool
dataCacheFlag bool
wantErr bool
}{
{
// Valid nod ename tries to fetch the data cache count from node labels resulting in an error
name: "node name is provided",
nodeName: "gke-node-some-name",
dataCacheFlag: true,
wantDataCacheEnabled: true,
wantErr: true,
},
{
name: "no node name provided",
nodeName: "",
dataCacheFlag: true,
wantDataCacheEnabled: false,
},
{
name: "test node",
nodeName: common.TestNode,
dataCacheFlag: true,
wantDataCacheEnabled: true,
},
{
name: "node name provided but data cache feature disabled",
nodeName: "",
dataCacheFlag: false,
wantDataCacheEnabled: false,
},
} {
t.Logf("Running test: %v", tc.name)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
gotDataCacheEnabled, err := IsDataCacheEnabledNodePool(ctx, tc.nodeName, tc.dataCacheFlag)
if err != nil {
if !tc.wantErr {
t.Errorf("unexpected error, got %v", err)
}
continue
}
if gotDataCacheEnabled != tc.wantDataCacheEnabled {
t.Errorf("want %t, got %t", tc.wantDataCacheEnabled, gotDataCacheEnabled)
}
}
}