Skip to content

Commit 1eaa5d6

Browse files
authored
Merge pull request #33 from civo/feat/add-delete-snapshot
Add DeleteSnapshot handler for VolumeSnapshot support
2 parents 612dbe8 + f8e810a commit 1eaa5d6

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

pkg/driver/controller_server.go

+30-2
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ func (d *Driver) ControllerGetCapabilities(context.Context, *csi.ControllerGetCa
561561
csi.ControllerServiceCapability_RPC_LIST_VOLUMES,
562562
csi.ControllerServiceCapability_RPC_GET_CAPACITY,
563563
csi.ControllerServiceCapability_RPC_EXPAND_VOLUME,
564+
// csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT, TODO: Uncomment after client implementation is complete.
564565
}
565566

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

592-
// DeleteSnapshot is part of implementing Snapshot & Restore functionality, but we don't support that
593-
func (d *Driver) DeleteSnapshot(context.Context, *csi.DeleteSnapshotRequest) (*csi.DeleteSnapshotResponse, error) {
593+
// DeleteSnapshot is part of implementing Snapshot & Restore functionality, and it will be supported in the future.
594+
func (d *Driver) DeleteSnapshot(ctx context.Context, req *csi.DeleteSnapshotRequest) (*csi.DeleteSnapshotResponse, error) {
595+
log.Info().
596+
Str("snapshot_id", req.GetSnapshotId()).
597+
Msg("Request: DeleteSnapshot")
598+
599+
snapshotID := req.GetSnapshotId()
600+
if snapshotID == "" {
601+
return nil, status.Error(codes.InvalidArgument, "must provide SnapshotId to DeleteSnapshot")
602+
}
603+
604+
log.Debug().
605+
Str("snapshot_id", snapshotID).
606+
Msg("Deleting snapshot in Civo API")
607+
608+
// TODO: Uncomment after client implementation is complete.
609+
// _, err := d.CivoClient.DeleteVolumeSnapshot(snapshotID)
610+
// if err != nil {
611+
// if strings.Contains(err.Error(), "DatabaseVolumeSnapshotNotFoundError") {
612+
// log.Info().
613+
// Str("volume_id", snapshotID).
614+
// Msg("Snapshot already deleted from Civo API")
615+
// return &csi.DeleteSnapshotResponse{}, nil
616+
// } else if strings.Contains(err.Error(), "DatabaseSnapshotCannotDeleteInUseError") {
617+
// return nil, status.Errorf(codes.FailedPrecondition, "failed to delete snapshot %q, it is currently in use, err: %s", snapshotID, err)
618+
// }
619+
// return nil, status.Errorf(codes.Internal, "failed to delete snapshot %q, err: %s", snapshotID, err)
620+
// }
621+
// return &csi.DeleteSnapshotResponse{}, nil
594622
return nil, status.Error(codes.Unimplemented, "")
595623
}
596624

0 commit comments

Comments
 (0)