Skip to content

Commit 10b737f

Browse files
authored
Merge pull request #1960 from hungnguyen243/dataCacheValidationPatch
Update validation logic for Data Cache to distinguish user and non-us…
2 parents 11a1d38 + 508ebbd commit 10b737f

File tree

5 files changed

+42
-27
lines changed

5 files changed

+42
-27
lines changed

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

+12-3
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,10 @@ func handle() {
246246
klog.Fatalf("Failed to set up metadata service: %v", err.Error())
247247
}
248248
nsArgs := driver.NodeServerArgs{
249-
EnableDeviceInUseCheck: *enableDeviceInUseCheck,
250-
DeviceInUseTimeout: *deviceInUseTimeout,
251-
EnableDataCache: *enableDataCacheFlag,
249+
EnableDeviceInUseCheck: *enableDeviceInUseCheck,
250+
DeviceInUseTimeout: *deviceInUseTimeout,
251+
EnableDataCache: *enableDataCacheFlag,
252+
DataCacheEnabledNodePool: isDataCacheEnabledNodePool(ctx, *nodeName),
252253
}
253254
nodeServer = driver.NewNodeServer(gceDriver, mounter, deviceUtils, meta, statter, nsArgs)
254255
if *maxConcurrentFormatAndMount > 0 {
@@ -344,6 +345,14 @@ func urlFlag(target **url.URL, name string, usage string) {
344345
})
345346
}
346347

348+
func isDataCacheEnabledNodePool(ctx context.Context, nodeName string) bool {
349+
dataCacheLSSDCount, err := driver.GetDataCacheCountFromNodeLabel(ctx, nodeName)
350+
if err != nil || dataCacheLSSDCount == 0 {
351+
return false
352+
}
353+
return true
354+
}
355+
347356
func fetchLssdsForRaiding(lssdCount int) ([]string, error) {
348357
allLssds, err := driver.FetchAllLssds()
349358
if err != nil {

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func setupCaching(devicePath string, req *csi.NodeStageVolumeRequest, nodeId str
226226
return mainDevicePath, nil
227227
}
228228

229-
func ValidateDataCacheConfig(dataCacheMode string, dataCacheSize string, ctx context.Context, nodeName string) error {
229+
func ValidateDataCacheConfig(dataCacheMode string, dataCacheSize string, ctx context.Context) error {
230230
if dataCacheMode != "" && dataCacheSize != "" {
231231
isAlreadyRaided, err := IsRaided()
232232
if err != nil {
@@ -237,8 +237,7 @@ func ValidateDataCacheConfig(dataCacheMode string, dataCacheSize string, ctx con
237237
}
238238
return nil
239239
}
240-
klog.V(4).Infof("Data Cache is not enabled for PVC (data-cache-size: %v, data-cache-mode: %v). Please set both these parameters in StorageClass to enable caching", dataCacheSize, dataCacheMode)
241-
return nil
240+
return fmt.Errorf("Data Cache is not enabled for PVC (data-cache-size: %v, data-cache-mode: %v). Please set both parameters in StorageClass to enable caching", dataCacheSize, dataCacheMode)
242241
}
243242

244243
func GetDataCacheCountFromNodeLabel(ctx context.Context, nodeName string) (int, error) {

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

+10-9
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,16 @@ func NewIdentityServer(gceDriver *GCEDriver) *GCEIdentityServer {
147147

148148
func NewNodeServer(gceDriver *GCEDriver, mounter *mount.SafeFormatAndMount, deviceUtils deviceutils.DeviceUtils, meta metadataservice.MetadataService, statter mountmanager.Statter, args NodeServerArgs) *GCENodeServer {
149149
return &GCENodeServer{
150-
Driver: gceDriver,
151-
Mounter: mounter,
152-
DeviceUtils: deviceUtils,
153-
MetadataService: meta,
154-
volumeLocks: common.NewVolumeLocks(),
155-
VolumeStatter: statter,
156-
enableDeviceInUseCheck: args.EnableDeviceInUseCheck,
157-
deviceInUseErrors: newDeviceErrMap(args.DeviceInUseTimeout),
158-
EnableDataCache: args.EnableDataCache,
150+
Driver: gceDriver,
151+
Mounter: mounter,
152+
DeviceUtils: deviceUtils,
153+
MetadataService: meta,
154+
volumeLocks: common.NewVolumeLocks(),
155+
VolumeStatter: statter,
156+
enableDeviceInUseCheck: args.EnableDeviceInUseCheck,
157+
deviceInUseErrors: newDeviceErrMap(args.DeviceInUseTimeout),
158+
EnableDataCache: args.EnableDataCache,
159+
DataCacheEnabledNodePool: args.DataCacheEnabledNodePool,
159160
}
160161
}
161162

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

+15-9
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ import (
4141
)
4242

4343
type GCENodeServer struct {
44-
Driver *GCEDriver
45-
Mounter *mount.SafeFormatAndMount
46-
DeviceUtils deviceutils.DeviceUtils
47-
VolumeStatter mountmanager.Statter
48-
MetadataService metadataservice.MetadataService
49-
EnableDataCache bool
44+
Driver *GCEDriver
45+
Mounter *mount.SafeFormatAndMount
46+
DeviceUtils deviceutils.DeviceUtils
47+
VolumeStatter mountmanager.Statter
48+
MetadataService metadataservice.MetadataService
49+
EnableDataCache bool
50+
DataCacheEnabledNodePool bool
5051

5152
// A map storing all volumes with ongoing operations so that additional operations
5253
// for that same volume (as defined by VolumeID) return an Aborted error
@@ -81,6 +82,8 @@ type NodeServerArgs struct {
8182
DeviceInUseTimeout time.Duration
8283

8384
EnableDataCache bool
85+
86+
DataCacheEnabledNodePool bool
8487
}
8588

8689
var _ csi.NodeServer = &GCENodeServer{}
@@ -337,17 +340,20 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
337340

338341
klog.Infof("Successfully found attached GCE PD %q at device path %s.", volumeKey.Name, devicePath)
339342

340-
if ns.EnableDataCache && req.GetPublishContext()[common.ContextDataCacheSize] != "" {
343+
if ns.EnableDataCache && (req.GetPublishContext()[common.ContextDataCacheSize] != "" || req.GetPublishContext()[common.ContextDataCacheMode] != "") {
341344
if len(nodeId) == 0 {
342345
return nil, status.Error(codes.InvalidArgument, "NodeStageVolume Node ID must be provided")
343346
}
344347
devFsPath, err := filepath.EvalSymlinks(devicePath)
345348
if err != nil {
346349
klog.Errorf("filepath.EvalSymlinks(%q) failed when trying to create volume group: %v", devicePath, err)
347350
}
348-
configError := ValidateDataCacheConfig(req.GetPublishContext()[common.ContextDataCacheMode], req.GetPublishContext()[common.ContextDataCacheSize], ctx, nodeId)
351+
configError := ValidateDataCacheConfig(req.GetPublishContext()[common.ContextDataCacheMode], req.GetPublishContext()[common.ContextDataCacheSize], ctx)
349352
if configError != nil {
350-
return nil, status.Error(codes.Internal, fmt.Sprintf("Error validate configuration for Data Cache: %v", err.Error()))
353+
if ns.DataCacheEnabledNodePool {
354+
return nil, status.Error(codes.DataLoss, fmt.Sprintf("Error validate configuration for Data Cache: %v", configError.Error()))
355+
}
356+
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("The Data Cache PVC is scheduled on an incompatible node pool. Please select a node pool with data cache configured: %v", configError.Error()))
351357
}
352358
devicePath, err = setupCaching(devFsPath, req, nodeId)
353359
if err != nil {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func getTestGCEDriverWithCustomMounter(t *testing.T, mounter *mount.SafeFormatAn
5252
func getCustomTestGCEDriver(t *testing.T, mounter *mount.SafeFormatAndMount, deviceUtils deviceutils.DeviceUtils, metaService metadataservice.MetadataService) *GCEDriver {
5353
gceDriver := GetGCEDriver()
5454
enableDataCache := false
55-
nodeServer := NewNodeServer(gceDriver, mounter, deviceUtils, metaService, mountmanager.NewFakeStatter(mounter), NodeServerArgs{true, 0, enableDataCache})
55+
nodeServer := NewNodeServer(gceDriver, mounter, deviceUtils, metaService, mountmanager.NewFakeStatter(mounter), NodeServerArgs{true, 0, enableDataCache, false /*dataCacheEnableNodePool */})
5656
err := gceDriver.SetupGCEDriver(driver, "test-vendor", nil, nil, nil, nil, nodeServer)
5757
if err != nil {
5858
t.Fatalf("Failed to setup GCE Driver: %v", err)
@@ -63,7 +63,7 @@ func getCustomTestGCEDriver(t *testing.T, mounter *mount.SafeFormatAndMount, dev
6363
func getTestBlockingMountGCEDriver(t *testing.T, readyToExecute chan chan struct{}) *GCEDriver {
6464
gceDriver := GetGCEDriver()
6565
mounter := mountmanager.NewFakeSafeBlockingMounter(readyToExecute)
66-
nodeServer := NewNodeServer(gceDriver, mounter, deviceutils.NewFakeDeviceUtils(false), metadataservice.NewFakeService(), mountmanager.NewFakeStatter(mounter), NodeServerArgs{true, 0, true})
66+
nodeServer := NewNodeServer(gceDriver, mounter, deviceutils.NewFakeDeviceUtils(false), metadataservice.NewFakeService(), mountmanager.NewFakeStatter(mounter), NodeServerArgs{true, 0, true, false /*dataCacheEnableNodePool */})
6767
err := gceDriver.SetupGCEDriver(driver, "test-vendor", nil, nil, nil, nil, nodeServer)
6868
if err != nil {
6969
t.Fatalf("Failed to setup GCE Driver: %v", err)
@@ -75,7 +75,7 @@ func getTestBlockingFormatAndMountGCEDriver(t *testing.T, readyToExecute chan ch
7575
gceDriver := GetGCEDriver()
7676
enableDataCache := true
7777
mounter := mountmanager.NewFakeSafeBlockingMounter(readyToExecute)
78-
nodeServer := NewNodeServer(gceDriver, mounter, deviceutils.NewFakeDeviceUtils(false), metadataservice.NewFakeService(), mountmanager.NewFakeStatter(mounter), NodeServerArgs{true, 0, enableDataCache}).WithSerializedFormatAndMount(5*time.Second, 1)
78+
nodeServer := NewNodeServer(gceDriver, mounter, deviceutils.NewFakeDeviceUtils(false), metadataservice.NewFakeService(), mountmanager.NewFakeStatter(mounter), NodeServerArgs{true, 0, enableDataCache, false /*dataCacheEnableNodePool */}).WithSerializedFormatAndMount(5*time.Second, 1)
7979

8080
err := gceDriver.SetupGCEDriver(driver, "test-vendor", nil, nil, nil, nil, nodeServer)
8181
if err != nil {

0 commit comments

Comments
 (0)