@@ -32,14 +32,14 @@ import (
32
32
33
33
csi "github.com/container-storage-interface/spec/lib/go/csi"
34
34
35
- "k8s.io/client-go/kubernetes"
36
- "k8s.io/client-go/rest"
37
35
"k8s.io/klog/v2"
38
36
"k8s.io/mount-utils"
39
37
40
38
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/common"
41
39
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/deviceutils"
42
40
metadataservice "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider/metadata"
41
+ "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/k8sclient"
42
+ "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/linkcache"
43
43
mountmanager "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/mount-manager"
44
44
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/resizefs"
45
45
)
@@ -77,6 +77,9 @@ type GCENodeServer struct {
77
77
// Embed UnimplementedNodeServer to ensure the driver returns Unimplemented for any
78
78
// new RPC methods that might be introduced in future versions of the spec.
79
79
csi.UnimplementedNodeServer
80
+
81
+ // A cache of the device paths for the volumes that are attached to the node.
82
+ DeviceCache * linkcache.DeviceCache
80
83
}
81
84
82
85
type NodeServerArgs struct {
@@ -92,6 +95,8 @@ type NodeServerArgs struct {
92
95
93
96
// SysfsPath defaults to "/sys", except if it's a unit test.
94
97
SysfsPath string
98
+
99
+ DeviceCache * linkcache.DeviceCache
95
100
}
96
101
97
102
var _ csi.NodeServer = & GCENodeServer {}
@@ -501,6 +506,11 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
501
506
}
502
507
}
503
508
509
+ err = ns .DeviceCache .AddVolume (volumeID )
510
+ if err != nil {
511
+ klog .Warningf ("Error adding volume %s to cache: %v" , volumeID , err )
512
+ }
513
+
504
514
klog .V (4 ).Infof ("NodeStageVolume succeeded on %v to %s" , volumeID , stagingTargetPath )
505
515
return & csi.NodeStageVolumeResponse {}, nil
506
516
}
@@ -614,6 +624,9 @@ func (ns *GCENodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUns
614
624
return nil , status .Errorf (codes .DataLoss , "Failed to cleanup cache for volume %s: %v" , volumeID , err )
615
625
}
616
626
}
627
+
628
+ ns .DeviceCache .RemoveVolume (volumeID )
629
+
617
630
klog .V (4 ).Infof ("NodeUnstageVolume succeeded on %v from %s" , volumeID , stagingTargetPath )
618
631
return & csi.NodeUnstageVolumeResponse {}, nil
619
632
}
@@ -869,15 +882,7 @@ func (ns *GCENodeServer) GetVolumeLimits(ctx context.Context) (int64, error) {
869
882
}
870
883
871
884
func GetAttachLimitsOverrideFromNodeLabel (ctx context.Context , nodeName string ) (int64 , error ) {
872
- cfg , err := rest .InClusterConfig ()
873
- if err != nil {
874
- return 0 , err
875
- }
876
- kubeClient , err := kubernetes .NewForConfig (cfg )
877
- if err != nil {
878
- return 0 , err
879
- }
880
- node , err := getNodeWithRetry (ctx , kubeClient , nodeName )
885
+ node , err := k8sclient .GetNodeWithRetry (ctx , nodeName )
881
886
if err != nil {
882
887
return 0 , err
883
888
}
0 commit comments