@@ -16,11 +16,10 @@ import (
16
16
)
17
17
18
18
const (
19
- cacheSuffix = "csi-fast"
20
- mainLvSuffix = "csi-main"
21
- raidedLocalSsdName = "csi-driver-data-cache"
22
- raidMode = "0"
23
- initialRaidedLocalSsdPath = "/dev/md0"
19
+ cacheSuffix = "csi-fast"
20
+ mainLvSuffix = "csi-main"
21
+ raidedLocalSsdName = "csi-driver-data-cache"
22
+ raidMode = "0"
24
23
)
25
24
26
25
func fetchRAIDedLocalSsdPath () (string , error ) {
@@ -30,12 +29,13 @@ func fetchRAIDedLocalSsdPath() (string, error) {
30
29
}
31
30
info , err := common .RunCommand ("grep" , []string {raidedLocalSsdName }, "mdadm" , args ... )
32
31
if err != nil || len (info ) == 0 {
33
- return "" , fmt .Errorf ("Error getting RAIDed device path for Datacache %v, output:%v =============== " , err , string (info ))
32
+ return "" , fmt .Errorf ("Error getting RAIDed device path for Data Cache %v, output:%v" , err , string (info ))
34
33
}
35
34
infoString := strings .TrimSpace (string (info ))
36
35
infoSlice := strings .Split (infoString , " " )
37
36
38
- // We want to get the second element in the array, which is the path to the RAIDed device
37
+ // We want to get the second element in the array (sample: ARRAY /dev/md126 metadata=1.2 name=csi-driver-data-cache UUID=*),
38
+ // which is the path to the RAIDed device
39
39
return infoSlice [1 ], nil
40
40
}
41
41
@@ -51,7 +51,7 @@ func setupCaching(devicePath string, req *csi.NodeStageVolumeRequest, nodeId str
51
51
volumeGroupName := getVolumeGroupName (nodeId )
52
52
mainDevicePath := "/dev/" + volumeGroupName + "/" + getLvName (mainLvSuffix , volumeId )
53
53
mainLvName := getLvName (mainLvSuffix , volumeId )
54
- klog .V (2 ).Infof ("Volume group available on node %v " , volumeGroupName )
54
+ klog .V (4 ).Infof ("Volume group available on node %v " , volumeGroupName )
55
55
vgExists := checkVgExists (volumeGroupName )
56
56
if vgExists {
57
57
// Clean up Volume Group before adding the PD
@@ -82,9 +82,9 @@ func setupCaching(devicePath string, req *csi.NodeStageVolumeRequest, nodeId str
82
82
infoString = strings .ReplaceAll (infoString , "\" " , "" )
83
83
infoSlice := strings .Split (strings .TrimSpace (infoString ), " " )
84
84
vgNameForPv := strings .TrimSpace (infoSlice [(len (infoSlice ) - 1 )])
85
- klog .V (2 ).Infof ("============================== Physical volume is part of Volume group: %v ============================== " , vgNameForPv )
85
+ klog .V (4 ).Infof ("Physical volume is part of Volume group: %v" , vgNameForPv )
86
86
if vgNameForPv == volumeGroupName {
87
- klog .V (2 ).Infof ("============================== Physical Volume(PV) already exists in the Volume Group ============================== " )
87
+ klog .V (4 ).Infof ("Physical Volume(PV) already exists in the Volume Group" )
88
88
} else if vgNameForPv != "VG" && vgNameForPv != "" {
89
89
90
90
info , err = common .RunCommand ("" /* pipedCmd */ , nil /* pipedCmdArg */ , "vgchange" , []string {"-an" , vgNameForPv }... )
@@ -157,7 +157,7 @@ func setupCaching(devicePath string, req *csi.NodeStageVolumeRequest, nodeId str
157
157
cacheLvName := getLvName (cacheSuffix , volumeId )
158
158
if isCached {
159
159
// Validate that cache is setup for required size
160
- klog .V (2 ).Infof ("Assuming valid data cache size and mode, resizing cache is not supported" )
160
+ klog .V (4 ).Infof ("Assuming valid data cache size and mode, resizing cache is not supported" )
161
161
} else {
162
162
fastCacheSize := req .GetPublishContext ()[common .ContextDataCacheSize ]
163
163
chunkSize := "960" // Cannot use default chunk size(64KiB) as it errors on maxChunksAllowed. Unit - KiB
@@ -207,8 +207,8 @@ func setupCaching(devicePath string, req *csi.NodeStageVolumeRequest, nodeId str
207
207
return mainDevicePath , nil
208
208
}
209
209
210
- func ValidateDataCacheConfig (dataCacheMode string , datacacheSize string , ctx context.Context , nodeName string ) error {
211
- if dataCacheMode != "" && datacacheSize != "" {
210
+ func ValidateDataCacheConfig (dataCacheMode string , dataCacheSize string , ctx context.Context , nodeName string ) error {
211
+ if dataCacheMode != "" && dataCacheSize != "" {
212
212
isAlreadyRaided , err := IsRaided ()
213
213
if err != nil {
214
214
return fmt .Errorf ("Local SSDs are not setup for caching; got error: %v" , err )
@@ -218,48 +218,50 @@ func ValidateDataCacheConfig(dataCacheMode string, datacacheSize string, ctx con
218
218
}
219
219
return nil
220
220
}
221
- klog .Infof ("Data cache is not enabled for PVC" )
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
222
return nil
223
223
}
224
224
225
225
func GetDataCacheCountFromNodeLabel (ctx context.Context , nodeName string ) (int , error ) {
226
- if nodeName == common .TestNode {
227
- return common .LocalSSDCountForDataCache , nil
228
- }
229
226
cfg , err := rest .InClusterConfig ()
230
227
// We want to capture API errors with node label fetching, so return -1
231
228
// in those cases instead of 0.
232
229
if err != nil {
233
- return - 1 , err
230
+ return 0 , err
234
231
}
235
232
kubeClient , err := kubernetes .NewForConfig (cfg )
236
233
if err != nil {
237
- return - 1 , err
234
+ return 0 , err
238
235
}
239
236
node , err := kubeClient .CoreV1 ().Nodes ().Get (ctx , nodeName , metav1.GetOptions {})
240
237
if err != nil {
241
238
// We could retry, but this error will also crashloop the driver which may be as good a way to retry as any.
242
- return - 1 , err
239
+ return 0 , err
243
240
}
244
241
if val , found := node .GetLabels ()[fmt .Sprintf (common .NodeLabelPrefix , common .DataCacheLssdCountLabel )]; found {
245
242
dataCacheCount , err := strconv .Atoi (val )
246
243
if err != nil {
247
- return - 1 , fmt .Errorf ("Error getting Datacache 's LSSD count from node label: %v" , err )
244
+ return 0 , fmt .Errorf ("Error getting Data Cache 's LSSD count from node label: %v" , err )
248
245
}
249
- klog .Infof ("Number of local SSDs requested for Datacache : %v" , dataCacheCount )
246
+ klog .V ( 4 ). Infof ("Number of local SSDs requested for Data Cache : %v" , dataCacheCount )
250
247
return dataCacheCount , nil
251
248
}
252
- return 0 , fmt .Errorf ("Cannot get Datacache's LSSD count from node label" )
249
+ // This will be returned for a non-Data-Cache node pool
250
+ return 0 , nil
253
251
}
254
252
255
253
func FetchRaidedLssdCountForDatacache () (int , error ) {
254
+ raidedPath , err := fetchRAIDedLocalSsdPath ()
255
+ if err != nil {
256
+ return 0 , err
257
+ }
256
258
args := []string {
257
259
"--detail" ,
258
- initialRaidedLocalSsdPath ,
260
+ raidedPath ,
259
261
}
260
262
info , err := common .RunCommand ("grep" , []string {"Raid Devices" }, "mdadm" , args ... )
261
263
if err != nil {
262
- return 0 , fmt .Errorf ("Error getting RAIDed devices for Datacache " )
264
+ return 0 , fmt .Errorf ("Error getting RAIDed devices for Data Cache " )
263
265
}
264
266
if len (info ) != 0 {
265
267
raidedDeviceInfo := strings .Split (strings .TrimSpace (string (info )), ":" )
@@ -294,7 +296,7 @@ func FetchRaidedLssds() ([]string, error) {
294
296
}
295
297
}
296
298
297
- klog .V (2 ).Infof ("Raided NVME list %v" , raidedLssdList )
299
+ klog .V (4 ).Infof ("Raided NVME list %v" , raidedLssdList )
298
300
299
301
return raidedLssdList , nil
300
302
}
@@ -309,7 +311,7 @@ func FetchAllLssds() ([]string, error) {
309
311
infoList := strings .Split (strings .TrimSpace (string (info )), "\n " )
310
312
re , err := regexp .Compile ("nvme_card([0-9]+)?$" )
311
313
if err != nil {
312
- klog .V (2 ).ErrorS (err , "Errored while compiling to check PD or LSSD" )
314
+ klog .V (4 ).ErrorS (err , "Errored while compiling to check PD or LSSD" )
313
315
}
314
316
for _ , ssd := range infoList {
315
317
ssd = strings .TrimSpace (ssd )
@@ -322,7 +324,7 @@ func FetchAllLssds() ([]string, error) {
322
324
}
323
325
}
324
326
325
- klog .V (2 ).Infof ("NVME list %v" , diskList )
327
+ klog .V (4 ).Infof ("NVME list %v" , diskList )
326
328
327
329
return diskList , nil
328
330
}
@@ -358,6 +360,7 @@ func cleanupCache(volumeId string, nodeId string) error {
358
360
// If volume group doesn't exist then there's nothing to uncache
359
361
return nil
360
362
}
363
+ reduceVolumeGroup (volumeGroupName , true )
361
364
mainLvName := getLvName (mainLvSuffix , volumeId )
362
365
args := []string {
363
366
"-an" ,
@@ -404,7 +407,7 @@ func createVg(volumeGroupName string, raidedLocalSsds string) error {
404
407
if err != nil {
405
408
return fmt .Errorf ("Volume group creation failed %w: %s" , err , info )
406
409
}
407
- klog .Infof ("Volume group creation succeeded for %v" , volumeGroupName )
410
+ klog .V ( 4 ). Infof ("Volume group creation succeeded for %v" , volumeGroupName )
408
411
409
412
args = []string {}
410
413
info , err = common .RunCommand ("" /* pipedCmd */ , nil /* pipedCmdArg */ , "vgscan" , args ... )
@@ -431,8 +434,6 @@ func reduceVolumeGroup(volumeGroupName string, force bool) {
431
434
func RaidLocalSsds (availableLssds []string ) error {
432
435
args := []string {
433
436
"--create" ,
434
- initialRaidedLocalSsdPath ,
435
- "--name" ,
436
437
raidedLocalSsdName ,
437
438
"-l" + raidMode ,
438
439
// Force RAIDing as sometime it might fail for caution if there is just 1 LSSD present as 1 LSSD need not be RAIDed
@@ -448,7 +449,7 @@ func RaidLocalSsds(availableLssds []string) error {
448
449
// Validate if Raided successfully
449
450
isAlreadyRaided , err := IsRaided ()
450
451
if err != nil {
451
- klog .V (2 ).Infof ("Errored while scanning for available raided LocalSSDs err:%v=" , err )
452
+ klog .V (4 ).Infof ("Errored while scanning for available raided LocalSSDs err:%v=" , err )
452
453
}
453
454
if ! isAlreadyRaided {
454
455
return fmt .Errorf ("failed raiding, raided device not found on scanning" )
0 commit comments