Skip to content

Commit e1d8632

Browse files
hungnguyen243cemakd
authored andcommitted
update validation logic for Data Cache to distinguish user and non-user errors when RAIDing fails
1 parent 723acf5 commit e1d8632

File tree

5 files changed

+38
-23
lines changed

5 files changed

+38
-23
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ func handle() {
229229
klog.Fatalf("Failed to set up metadata service: %v", err.Error())
230230
}
231231
nsArgs := driver.NodeServerArgs{
232-
EnableDataCache: *enableDataCacheFlag,
232+
EnableDataCache: *enableDataCacheFlag,
233+
DataCacheEnabledNodePool: isDataCacheEnabledNodePool(ctx, *nodeName),
233234
}
234235
nodeServer = driver.NewNodeServer(gceDriver, mounter, deviceUtils, meta, statter, nsArgs)
235236
if *maxConcurrentFormatAndMount > 0 {
@@ -325,6 +326,14 @@ func urlFlag(target **url.URL, name string, usage string) {
325326
})
326327
}
327328

329+
func isDataCacheEnabledNodePool(ctx context.Context, nodeName string) bool {
330+
dataCacheLSSDCount, err := driver.GetDataCacheCountFromNodeLabel(ctx, nodeName)
331+
if err != nil || dataCacheLSSDCount == 0 {
332+
return false
333+
}
334+
return true
335+
}
336+
328337
func fetchLssdsForRaiding(lssdCount int) ([]string, error) {
329338
allLssds, err := driver.FetchAllLssds()
330339
if err != nil {

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

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

210-
func ValidateDataCacheConfig(dataCacheMode string, dataCacheSize string, ctx context.Context, nodeName string) error {
210+
func ValidateDataCacheConfig(dataCacheMode string, dataCacheSize string, ctx context.Context) error {
211211
if dataCacheMode != "" && dataCacheSize != "" {
212212
isAlreadyRaided, err := IsRaided()
213213
if err != nil {
@@ -218,8 +218,7 @@ func ValidateDataCacheConfig(dataCacheMode string, dataCacheSize string, ctx con
218218
}
219219
return nil
220220
}
221-
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)
222-
return nil
221+
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)
223222
}
224223

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

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,14 @@ func NewIdentityServer(gceDriver *GCEDriver) *GCEIdentityServer {
145145

146146
func NewNodeServer(gceDriver *GCEDriver, mounter *mount.SafeFormatAndMount, deviceUtils deviceutils.DeviceUtils, meta metadataservice.MetadataService, statter mountmanager.Statter, args NodeServerArgs) *GCENodeServer {
147147
return &GCENodeServer{
148-
Driver: gceDriver,
149-
Mounter: mounter,
150-
DeviceUtils: deviceUtils,
151-
MetadataService: meta,
152-
volumeLocks: common.NewVolumeLocks(),
153-
VolumeStatter: statter,
154-
EnableDataCache: args.EnableDataCache,
148+
Driver: gceDriver,
149+
Mounter: mounter,
150+
DeviceUtils: deviceUtils,
151+
MetadataService: meta,
152+
volumeLocks: common.NewVolumeLocks(),
153+
VolumeStatter: statter,
154+
EnableDataCache: args.EnableDataCache,
155+
DataCacheEnabledNodePool: args.DataCacheEnabledNodePool,
155156
}
156157
}
157158

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ import (
4242
)
4343

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

5253
// A map storing all volumes with ongoing operations so that additional operations
5354
// for that same volume (as defined by VolumeID) return an Aborted error
@@ -69,6 +70,8 @@ type GCENodeServer struct {
6970

7071
type NodeServerArgs struct {
7172
EnableDataCache bool
73+
74+
DataCacheEnabledNodePool bool
7275
}
7376

7477
var _ csi.NodeServer = &GCENodeServer{}
@@ -328,17 +331,20 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
328331

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

331-
if ns.EnableDataCache && req.GetPublishContext()[common.ContextDataCacheSize] != "" {
334+
if ns.EnableDataCache && (req.GetPublishContext()[common.ContextDataCacheSize] != "" || req.GetPublishContext()[common.ContextDataCacheMode] != "") {
332335
if len(nodeId) == 0 {
333336
return nil, status.Error(codes.InvalidArgument, "NodeStageVolume Node ID must be provided")
334337
}
335338
devFsPath, err := filepath.EvalSymlinks(devicePath)
336339
if err != nil {
337340
klog.Errorf("filepath.EvalSymlinks(%q) failed when trying to create volume group: %v", devicePath, err)
338341
}
339-
configError := ValidateDataCacheConfig(req.GetPublishContext()[common.ContextDataCacheMode], req.GetPublishContext()[common.ContextDataCacheSize], ctx, nodeId)
342+
configError := ValidateDataCacheConfig(req.GetPublishContext()[common.ContextDataCacheMode], req.GetPublishContext()[common.ContextDataCacheSize], ctx)
340343
if configError != nil {
341-
return nil, status.Error(codes.Internal, fmt.Sprintf("Error validate configuration for Data Cache: %v", err.Error()))
344+
if ns.DataCacheEnabledNodePool {
345+
return nil, status.Error(codes.DataLoss, fmt.Sprintf("Error validate configuration for Data Cache: %v", configError.Error()))
346+
}
347+
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("Data Cache PVC is requested for an incompatible node pool: %v", configError.Error()))
342348
}
343349
devicePath, err = setupCaching(devFsPath, req, nodeId)
344350
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{enableDataCache})
55+
nodeServer := NewNodeServer(gceDriver, mounter, deviceUtils, metaService, mountmanager.NewFakeStatter(mounter), NodeServerArgs{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})
66+
nodeServer := NewNodeServer(gceDriver, mounter, deviceutils.NewFakeDeviceUtils(false), metadataservice.NewFakeService(), mountmanager.NewFakeStatter(mounter), NodeServerArgs{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{enableDataCache}).WithSerializedFormatAndMount(5*time.Second, 1)
78+
nodeServer := NewNodeServer(gceDriver, mounter, deviceutils.NewFakeDeviceUtils(false), metadataservice.NewFakeService(), mountmanager.NewFakeStatter(mounter), NodeServerArgs{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)