Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
DMajrekar committed May 30, 2024
1 parent c044b0b commit 739bd82
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions pkg/driver/controller_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,20 @@ func (d *Driver) ControllerPublishVolume(ctx context.Context, req *csi.Controlle
log.Info().Str("volume_id", volume.ID).Str("instance_id", req.NodeId).Msg("Volume successfully requested to be attached in Civo API")

log.Debug().Str("volume_id", volume.ID).Msg("Waiting for volume to become attached in Civo API")
_, err = d.waitForVolumeStatus(volume, "attached", CivoVolumeAvailableRetries)
//slep for 5 secons
time.Sleep(5 * time.Second)
// refetch the volume
volume, err = d.CivoClient.GetVolume(req.VolumeId)
if err != nil {
log.Error().Err(err).Msg("Volume attaching never completed successfully in Civo API")
log.Error().Err(err).Msg("Unable to find volume for publishing in Civo API")
return nil, err
}

if volume.InstanceID != req.NodeId {
log.Error().Str("volume_id", volume.ID).Str("instance_id", req.NodeId).Msg("Volume is not attached to the requested instance")
return nil, status.Errorf(codes.Unavailable, "Volume is not attached to the requested instance")
}

log.Debug().Str("volume_id", volume.ID).Msg("Volume successfully attached in Civo API")
return &csi.ControllerPublishVolumeResponse{}, nil
}
Expand Down Expand Up @@ -315,12 +323,14 @@ func (d *Driver) ControllerUnpublishVolume(ctx context.Context, req *csi.Control
}
log.Info().Str("volume_id", volume.ID).Msg("Volume sucessfully requested to be detached in Civo API")

log.Debug().Str("volume_id", volume.ID).Msg("Waiting for volume status to return to available")
available, err := d.waitForVolumeStatus(volume, "available", CivoVolumeAvailableRetries)
// Fetch new state after 5 seconds
time.Sleep(5 * time.Second)
volume, err = d.CivoClient.GetVolume(req.VolumeId)
if err != nil {
log.Error().Err(err).Msg("Volume becoming available again never completed successfully in Civo API")
log.Error().Err(err).Msg("Unable to find volume for unpublishing in Civo API")
return nil, err
}
available := volume.Status == "available"

if available {
log.Debug().Str("volume_id", volume.ID).Msg("Volume is now available again")
Expand Down

0 comments on commit 739bd82

Please sign in to comment.