Skip to content

Commit c941871

Browse files
committed
Add nil checks around the usage of the device cache
1 parent f7d78aa commit c941871

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
@@ -537,9 +537,11 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
537537
}
538538
}
539539

540-
err = ns.DeviceCache.AddVolume(volumeID)
541-
if err != nil {
542-
klog.Warningf("Error adding volume %s to cache: %v", volumeID, err)
540+
if ns.DeviceCache != nil {
541+
err = ns.DeviceCache.AddVolume(volumeID)
542+
if err != nil {
543+
klog.Warningf("Error adding volume %s to cache: %v", volumeID, err)
544+
}
543545
}
544546

545547
klog.V(4).Infof("NodeStageVolume succeeded on %v to %s", volumeID, stagingTargetPath)
@@ -661,7 +663,9 @@ func (ns *GCENodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUns
661663
}
662664
}
663665

664-
ns.DeviceCache.RemoveVolume(volumeID)
666+
if ns.DeviceCache != nil {
667+
ns.DeviceCache.RemoveVolume(volumeID)
668+
}
665669

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

0 commit comments

Comments
 (0)