Skip to content

Commit 4dc330e

Browse files
committed
update validation logic for Data Cache to distinguish user and non-user errors when RAIDing fails
1 parent 58c8eaf commit 4dc330e

File tree

5 files changed

+42
-27
lines changed

5 files changed

+42
-27
lines changed

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

Lines changed: 12 additions & 3 deletions
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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func setupCaching(devicePath string, req *csi.NodeStageVolumeRequest, nodeId str
225225
return mainDevicePath, nil
226226
}
227227

228-
func ValidateDataCacheConfig(dataCacheMode string, dataCacheSize string, ctx context.Context, nodeName string) error {
228+
func ValidateDataCacheConfig(dataCacheMode string, dataCacheSize string, ctx context.Context) error {
229229
if dataCacheMode != "" && dataCacheSize != "" {
230230
isAlreadyRaided, err := IsRaided()
231231
if err != nil {
@@ -236,8 +236,7 @@ func ValidateDataCacheConfig(dataCacheMode string, dataCacheSize string, ctx con
236236
}
237237
return nil
238238
}
239-
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)
240-
return nil
239+
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)
241240
}
242241

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

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

Lines changed: 10 additions & 9 deletions
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

Lines changed: 15 additions & 9 deletions
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("Data Cache PVC is requested for an incompatible node pool: %v", configError.Error()))
351357
}
352358
devicePath, err = setupCaching(devFsPath, req, nodeId)
353359
if err != nil {

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

Lines changed: 3 additions & 3 deletions
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)