@@ -27,6 +27,7 @@ import (
27
27
"strings"
28
28
"time"
29
29
30
+ v1 "k8s.io/api/core/v1"
30
31
"k8s.io/klog/v2"
31
32
"k8s.io/utils/strings/slices"
32
33
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common"
@@ -245,15 +246,26 @@ func handle() {
245
246
if err != nil {
246
247
klog .Fatalf ("Failed to set up metadata service: %v" , err .Error ())
247
248
}
248
- isDataCacheEnabledNodePool , err := isDataCacheEnabledNodePool (ctx , * nodeName )
249
- if err != nil {
250
- klog .Fatalf ("Failed to get node info from API server: %v" , err .Error ())
249
+ var node * v1.Node
250
+ var isDataCacheEnabledNodePoolCheck bool
251
+ if * nodeName == common .TestNode {
252
+ isDataCacheEnabledNodePoolCheck = true
253
+ } else if len (* nodeName ) > 0 && * nodeName != common .TestNode {
254
+ node , err = driver .FetchNodeWithRetry (ctx , * nodeName )
255
+ if err != nil {
256
+ klog .Fatalf ("Failed to get node info from API server: %v" , err .Error ())
257
+ }
258
+ isDataCacheEnabledNodePoolCheck , err = isDataCacheEnabledNodePool (ctx , node )
259
+ if err != nil {
260
+ klog .Fatalf ("Unable to fetch node labels: %v" , err .Error ())
261
+ }
251
262
}
263
+ // isDataCacheEnabledNodePool := true
252
264
nsArgs := driver.NodeServerArgs {
253
265
EnableDeviceInUseCheck : * enableDeviceInUseCheck ,
254
266
DeviceInUseTimeout : * deviceInUseTimeout ,
255
267
EnableDataCache : * enableDataCacheFlag ,
256
- DataCacheEnabledNodePool : isDataCacheEnabledNodePool ,
268
+ DataCacheEnabledNodePool : isDataCacheEnabledNodePoolCheck ,
257
269
}
258
270
nodeServer = driver .NewNodeServer (gceDriver , mounter , deviceUtils , meta , statter , nsArgs )
259
271
if * maxConcurrentFormatAndMount > 0 {
@@ -264,7 +276,7 @@ func handle() {
264
276
klog .Errorf ("Data Cache enabled, but --node-name not passed" )
265
277
}
266
278
if nsArgs .DataCacheEnabledNodePool {
267
- if err := setupDataCache (ctx , * nodeName , nodeServer . MetadataService . GetName () ); err != nil {
279
+ if err := setupDataCache (ctx , node , * nodeName ); err != nil {
268
280
klog .Errorf ("Data Cache setup failed: %v" , err )
269
281
}
270
282
go driver .StartWatcher (* nodeName )
@@ -351,15 +363,16 @@ func urlFlag(target **url.URL, name string, usage string) {
351
363
})
352
364
}
353
365
354
- func isDataCacheEnabledNodePool (ctx context.Context , nodeName string ) (bool , error ) {
366
+ func isDataCacheEnabledNodePool (ctx context.Context , node * v1. Node ) (bool , error ) {
355
367
if ! * enableDataCacheFlag {
356
368
return false , nil
357
369
}
358
- if len (nodeName ) > 0 && nodeName != common .TestNode { // disregard logic below when E2E testing.
359
- dataCacheLSSDCount , err := driver .GetDataCacheCountFromNodeLabel (ctx , nodeName )
360
- return dataCacheLSSDCount != 0 , err
361
- }
362
- return true , nil
370
+ // nodeName := node.Name
371
+ // if len(nodeName) > 0 && nodeName != common.TestNode { // disregard logic below when E2E testing.
372
+ dataCacheLSSDCount , err := driver .GetDataCacheCountFromNodeLabel (ctx , node )
373
+ return dataCacheLSSDCount != 0 , err
374
+ // }
375
+ // return true, nil
363
376
}
364
377
365
378
func fetchLssdsForRaiding (lssdCount int ) ([]string , error ) {
@@ -394,7 +407,7 @@ func fetchLssdsForRaiding(lssdCount int) ([]string, error) {
394
407
return availableLssds [:lssdCount ], nil
395
408
}
396
409
397
- func setupDataCache (ctx context.Context , nodeName string , nodeId string ) error {
410
+ func setupDataCache (ctx context.Context , node * v1. Node , nodeName string ) error {
398
411
isAlreadyRaided , err := driver .IsRaided ()
399
412
if err != nil {
400
413
klog .V (4 ).Infof ("Errored while scanning for available LocalSSDs err:%v; continuing Raiding" , err )
@@ -404,9 +417,11 @@ func setupDataCache(ctx context.Context, nodeName string, nodeId string) error {
404
417
}
405
418
406
419
lssdCount := common .LocalSSDCountForDataCache
420
+ nodeUid := nodeName
407
421
if nodeName != common .TestNode {
408
- var err error
409
- lssdCount , err = driver .GetDataCacheCountFromNodeLabel (ctx , nodeName )
422
+ nodeUid = string (node .ObjectMeta .UID )
423
+ // lssdCount := 4
424
+ lssdCount , err = driver .GetDataCacheCountFromNodeLabel (ctx , node )
410
425
if err != nil {
411
426
return err
412
427
}
@@ -425,7 +440,7 @@ func setupDataCache(ctx context.Context, nodeName string, nodeId string) error {
425
440
}
426
441
427
442
// Initializing data cache node (VG checks w/ raided lssd)
428
- if err := driver .InitializeDataCacheNode (nodeId ); err != nil {
443
+ if err := driver .InitializeDataCacheNode (nodeUid ); err != nil {
429
444
return err
430
445
}
431
446
0 commit comments