Skip to content

Commit f472f93

Browse files
committed
Add nil checks around the usage of the device cache
1 parent e8056a5 commit f472f93

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
@@ -519,9 +519,11 @@ func (ns *GCENodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStage
519519
}
520520
}
521521

522-
err = ns.DeviceCache.AddVolume(volumeID)
523-
if err != nil {
524-
klog.Warningf("Error adding volume %s to cache: %v", volumeID, err)
522+
if ns.DeviceCache != nil {
523+
err = ns.DeviceCache.AddVolume(volumeID)
524+
if err != nil {
525+
klog.Warningf("Error adding volume %s to cache: %v", volumeID, err)
526+
}
525527
}
526528

527529
klog.V(4).Infof("NodeStageVolume succeeded on %v to %s", volumeID, stagingTargetPath)
@@ -639,7 +641,9 @@ func (ns *GCENodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUns
639641
}
640642
}
641643

642-
ns.DeviceCache.RemoveVolume(volumeID)
644+
if ns.DeviceCache != nil {
645+
ns.DeviceCache.RemoveVolume(volumeID)
646+
}
643647

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

0 commit comments

Comments
 (0)