Skip to content

Commit

Permalink
Merge pull request #33 from civo/feat/add-delete-snapshot
Browse files Browse the repository at this point in the history
Add DeleteSnapshot handler for VolumeSnapshot support
  • Loading branch information
hlts2 authored Nov 27, 2024
2 parents 612dbe8 + f8e810a commit 1eaa5d6
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions pkg/driver/controller_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ func (d *Driver) ControllerGetCapabilities(context.Context, *csi.ControllerGetCa
csi.ControllerServiceCapability_RPC_LIST_VOLUMES,
csi.ControllerServiceCapability_RPC_GET_CAPACITY,
csi.ControllerServiceCapability_RPC_EXPAND_VOLUME,
// csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT, TODO: Uncomment after client implementation is complete.
}

var csc []*csi.ControllerServiceCapability
Expand Down Expand Up @@ -589,8 +590,35 @@ func (d *Driver) CreateSnapshot(context.Context, *csi.CreateSnapshotRequest) (*c
return nil, status.Error(codes.Unimplemented, "")
}

// DeleteSnapshot is part of implementing Snapshot & Restore functionality, but we don't support that
func (d *Driver) DeleteSnapshot(context.Context, *csi.DeleteSnapshotRequest) (*csi.DeleteSnapshotResponse, error) {
// DeleteSnapshot is part of implementing Snapshot & Restore functionality, and it will be supported in the future.
func (d *Driver) DeleteSnapshot(ctx context.Context, req *csi.DeleteSnapshotRequest) (*csi.DeleteSnapshotResponse, error) {
log.Info().
Str("snapshot_id", req.GetSnapshotId()).
Msg("Request: DeleteSnapshot")

snapshotID := req.GetSnapshotId()
if snapshotID == "" {
return nil, status.Error(codes.InvalidArgument, "must provide SnapshotId to DeleteSnapshot")
}

log.Debug().
Str("snapshot_id", snapshotID).
Msg("Deleting snapshot in Civo API")

// TODO: Uncomment after client implementation is complete.
// _, err := d.CivoClient.DeleteVolumeSnapshot(snapshotID)
// if err != nil {
// if strings.Contains(err.Error(), "DatabaseVolumeSnapshotNotFoundError") {
// log.Info().
// Str("volume_id", snapshotID).
// Msg("Snapshot already deleted from Civo API")
// return &csi.DeleteSnapshotResponse{}, nil
// } else if strings.Contains(err.Error(), "DatabaseSnapshotCannotDeleteInUseError") {
// return nil, status.Errorf(codes.FailedPrecondition, "failed to delete snapshot %q, it is currently in use, err: %s", snapshotID, err)
// }
// return nil, status.Errorf(codes.Internal, "failed to delete snapshot %q, err: %s", snapshotID, err)
// }
// return &csi.DeleteSnapshotResponse{}, nil
return nil, status.Error(codes.Unimplemented, "")
}

Expand Down

0 comments on commit 1eaa5d6

Please sign in to comment.