Skip to content

Commit 3824cbb

Browse files
committed
Add nil checks around the usage of the device cache
1 parent 3437efd commit 3824cbb

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -512,9 +512,11 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
512512
}
513513
}
514514

515-
err = ns.DeviceCache.AddVolume(volumeID)
516-
if err != nil {
517-
klog.Warningf("Error adding volume %s to cache: %v", volumeID, err)
515+
if ns.DeviceCache != nil {
516+
err = ns.DeviceCache.AddVolume(volumeID)
517+
if err != nil {
518+
klog.Warningf("Error adding volume %s to cache: %v", volumeID, err)
519+
}
518520
}
519521

520522
klog.V(4).Infof("NodeStageVolume succeeded on %v to %s", volumeID, stagingTargetPath)
@@ -631,7 +633,9 @@ func (ns *GCENodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUns
631633
}
632634
}
633635

634-
ns.DeviceCache.RemoveVolume(volumeID)
636+
if ns.DeviceCache != nil {
637+
ns.DeviceCache.RemoveVolume(volumeID)
638+
}
635639

636640
klog.V(4).Infof("NodeUnstageVolume succeeded on %v from %s", volumeID, stagingTargetPath)
637641
return &csi.NodeUnstageVolumeResponse{}, nil

0 commit comments

Comments
 (0)