Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve logging for node driver functions #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/driver/hotplug_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ func (p *RealDiskHotPlugger) Unmount(mountpoint string) error {
output, err := exec.Command("umount", mountpoint).CombinedOutput()
log.Debug().Str("output", string(output)).Msg("Unmounting command output")
if err != nil {
log.Error().Err(err).Str("mountpoint", mountpoint).Msg("Failed to unmount")
return fmt.Errorf("unmounting with 'umount %s' failed: %v output: %s", mountpoint, err, string(output))
}

Expand Down
29 changes: 29 additions & 0 deletions pkg/driver/node_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
log.Info().Str("volume_id", req.VolumeId).Str("staging_target_path", req.StagingTargetPath).Msg("Request: NodeStageVolume")

if req.VolumeId == "" {
log.Error().Msg("must provide a VolumeId to NodeStageVolume")
return nil, status.Error(codes.InvalidArgument, "must provide a VolumeId to NodeStageVolume")
}
if req.StagingTargetPath == "" {
log.Error().Msg("must provide a StagingTargetPath to NodeStageVolume")
return nil, status.Error(codes.InvalidArgument, "must provide a StagingTargetPath to NodeStageVolume")
}
if req.VolumeCapability == nil {
log.Error().Msg("must provide a VolumeCapability to NodeStageVolume")
return nil, status.Error(codes.InvalidArgument, "must provide a VolumeCapability to NodeStageVolume")
}

Expand All @@ -43,6 +46,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
// Format the volume if not already formatted
formatted, err := d.DiskHotPlugger.IsFormatted(attachedDiskPath)
if err != nil {
log.Error().Str("path", attachedDiskPath).Err(err).Msg("Formatted check errored")
return nil, err
}
log.Debug().Str("volume_id", req.VolumeId).Bool("formatted", formatted).Msg("Is currently formatted?")
Expand All @@ -54,6 +58,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
// Mount the volume if not already mounted
mounted, err := d.DiskHotPlugger.IsMounted(d.DiskHotPlugger.PathForVolume(req.VolumeId))
if err != nil {
log.Error().Str("path", attachedDiskPath).Err(err).Msg("Mounted check errored")
return nil, err
}
log.Debug().Str("volume_id", req.VolumeId).Bool("mounted", formatted).Msg("Is currently mounted?")
Expand All @@ -75,16 +80,19 @@ func (d *Driver) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstageVolu
log.Info().Str("volume_id", req.VolumeId).Str("staging_target_path", req.StagingTargetPath).Msg("Request: NodeUnstageVolume")

if req.VolumeId == "" {
log.Error().Msg("must provide a VolumeId to NodeUnstageVolume")
return nil, status.Error(codes.InvalidArgument, "must provide a VolumeId to NodeUnstageVolume")
}
if req.StagingTargetPath == "" {
log.Error().Msg("must provide a StagingTargetPath to NodeUnstageVolume")
return nil, status.Error(codes.InvalidArgument, "must provide a StagingTargetPath to NodeUnstageVolume")
}

log.Debug().Str("volume_id", req.VolumeId).Str("path", req.StagingTargetPath).Msg("Unmounting volume (unstaging)")
path := d.DiskHotPlugger.PathForVolume(req.VolumeId)

if path == "" && !d.TestMode {
log.Error().Str("volume_id", req.VolumeId).Msg("path to volume (/dev/disk/by-id/VOLUME_ID) not found")
return &csi.NodeUnstageVolumeResponse{}, nil
}

Expand All @@ -108,29 +116,35 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
log.Info().Str("volume_id", req.VolumeId).Str("staging_target_path", req.StagingTargetPath).Str("target_path", req.TargetPath).Msg("Request: NodePublishVolume")

if req.VolumeId == "" {
log.Error().Msg("must provide a VolumeId to NodePublishVolume")
return nil, status.Error(codes.InvalidArgument, "must provide a VolumeId to NodePublishVolume")
}
if req.StagingTargetPath == "" {
log.Error().Msg("must provide a StagingTargetPath to NodePublishVolume")
return nil, status.Error(codes.InvalidArgument, "must provide a StagingTargetPath to NodePublishVolume")
}
if req.TargetPath == "" {
log.Error().Msg("must provide a TargetPath to NodePublishVolume")
return nil, status.Error(codes.InvalidArgument, "must provide a TargetPath to NodePublishVolume")
}
if req.VolumeCapability == nil {
log.Error().Msg("must provide a VolumeCapability to NodePublishVolume")
return nil, status.Error(codes.InvalidArgument, "must provide a VolumeCapability to NodePublishVolume")
}

log.Debug().Str("volume_id", req.VolumeId).Str("from_path", req.StagingTargetPath).Str("to_path", req.TargetPath).Msg("Bind-mounting volume (publishing)")

err := os.MkdirAll(req.TargetPath, 0o750)
if err != nil {
log.Error().Str("volume_id", req.VolumeId).Str("targetPath", req.TargetPath).Err(err).Msg("Failed to create target path")
return nil, err
}

log.Debug().Str("volume_id", req.VolumeId).Str("targetPath", req.TargetPath).Msg("Ensuring target path exists")
// Mount the volume if not already mounted
mounted, err := d.DiskHotPlugger.IsMounted(req.TargetPath)
if err != nil {
log.Error().Str("path", req.TargetPath).Err(err).Msg("Mounted check errored")
return nil, err
}
log.Debug().Str("volume_id", req.VolumeId).Bool("mounted", mounted).Msg("Checking if currently mounting")
Expand All @@ -153,9 +167,11 @@ func (d *Driver) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublish
log.Info().Str("volume_id", req.VolumeId).Str("target_path", req.TargetPath).Msg("Request: NodeUnpublishVolume")

if req.VolumeId == "" {
log.Error().Msg("must provide a VolumeId to NodeUnpublishVolume")
return nil, status.Error(codes.InvalidArgument, "must provide a VolumeId to NodeUnpublishVolume")
}
if req.TargetPath == "" {
log.Error().Msg("must provide a TargetPath to NodeUnpublishVolume")
return nil, status.Error(codes.InvalidArgument, "must provide a TargetPath to NodeUnpublishVolume")
}

Expand All @@ -179,6 +195,7 @@ func (d *Driver) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublish

if !mounted {
if err = os.RemoveAll(targetPath); err != nil {
log.Error().Str("targetPath", targetPath).Err(err).Msg("Failed to remove target path")
return nil, status.Error(codes.Internal, err.Error())
}

Expand All @@ -187,12 +204,14 @@ func (d *Driver) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublish

err = d.DiskHotPlugger.Unmount(targetPath)
if err != nil {
log.Error().Str("targetPath", targetPath).Err(err).Msg("Failed to unmount target path")
return nil, err
}

log.Info().Str("volume_id", req.VolumeId).Str("target_path", targetPath).Msg("Removing target path")
err = os.Remove(targetPath)
if err != nil && !os.IsNotExist(err) {
log.Error().Str("targetPath", targetPath).Err(err).Msg("Failed to remove target path")
return nil, status.Error(codes.Internal, err.Error())
}

Expand All @@ -205,6 +224,7 @@ func (d *Driver) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRequest) (

nodeInstanceID, region, err := d.currentNodeDetails()
if err != nil {
log.Error().Err(err).Msg("Failed to get current node details")
return nil, status.Error(codes.Internal, err.Error())
}

Expand All @@ -228,25 +248,30 @@ func (d *Driver) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolumeS
log.Info().Str("volume_id", req.VolumeId).Msg("Request: NodeGetVolumeStats")

if req.VolumeId == "" {
log.Error().Msg("must provide a VolumeId to NodeGetVolumeStats")
return nil, status.Error(codes.InvalidArgument, "must provide a VolumeId to NodeGetVolumeStats")
}

volumePath := req.VolumePath
if volumePath == "" {
log.Error().Msg("must provide a VolumePath to NodeGetVolumeStats")
return nil, status.Error(codes.InvalidArgument, "must provide a VolumePath to NodeGetVolumeStats")
}

mounted, err := d.DiskHotPlugger.IsMounted(volumePath)
if err != nil {
log.Error().Str("volume_id", req.VolumeId).Str("path", volumePath).Err(err).Msg("Failed to check if volume path is mounted")
return nil, status.Errorf(codes.Internal, "failed to check if volume path %q is mounted: %s", volumePath, err)
}

if !mounted {
log.Error().Str("volume_id", req.VolumeId).Str("path", volumePath).Msg("Volume path is not mounted")
return nil, status.Errorf(codes.NotFound, "volume path %q is not mounted", volumePath)
}

stats, err := d.DiskHotPlugger.GetStatistics(volumePath)
if err != nil {
log.Error().Str("volume_id", req.VolumeId).Str("path", volumePath).Err(err).Msg("Failed to retrieve capacity statistics")
return nil, status.Errorf(codes.Internal, "failed to retrieve capacity statistics for volume path %q: %s", volumePath, err)
}

Expand Down Expand Up @@ -276,14 +301,17 @@ func (d *Driver) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolumeS
func (d *Driver) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandVolumeRequest) (*csi.NodeExpandVolumeResponse, error) {
log.Info().Str("volume_id", req.VolumeId).Str("target_path", req.VolumePath).Msg("Request: NodeExpandVolume")
if req.VolumeId == "" {
log.Error().Msg("must provide a VolumeId to NodeExpandVolume")
return nil, status.Error(codes.InvalidArgument, "must provide a VolumeId to NodeExpandVolume")
}
if req.VolumePath == "" {
log.Error().Msg("must provide a VolumePath to NodeExpandVolume")
return nil, status.Error(codes.InvalidArgument, "must provide a VolumePath to NodeExpandVolume")
}

_, err := d.CivoClient.GetVolume(req.VolumeId)
if err != nil {
log.Error().Str("volume_id", req.VolumeId).Err(err).Msg("Failed to find VolumeID to NodeExpandVolume")
return nil, status.Error(codes.NotFound, "unable to fund VolumeID to NodeExpandVolume")

}
Expand All @@ -298,6 +326,7 @@ func (d *Driver) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandVolume
log.Info().Str("volume_id", req.VolumeId).Str("path", attachedDiskPath).Msg("Expanding Volume")
err = d.DiskHotPlugger.ExpandFilesystem(d.DiskHotPlugger.PathForVolume(req.VolumeId))
if err != nil {
log.Error().Str("volume_id", req.VolumeId).Err(err).Msg("Failed to expand filesystem")
return nil, status.Error(codes.Internal, fmt.Sprintf("failed to expand file system: %s", err.Error()))
}

Expand Down
Loading