Skip to content

Commit

Permalink
prevent deletion of single snapshot that is part of a snapshotgroup
Browse files Browse the repository at this point in the history
  • Loading branch information
nixpanic committed Mar 10, 2023
1 parent ccbe7d7 commit 21abfde
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/hostpath/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,11 @@ func (hp *hostPath) DeleteSnapshot(ctx context.Context, req *csi.DeleteSnapshotR
hp.mutex.Lock()
defer hp.mutex.Unlock()

// If the snapshot has a GroupSnapshotID, deletion is not allowed and should return InvalidArgument.
if snapshot, err := hp.state.GetSnapshotByID(snapshotID); err != nil && snapshot.GroupSnapshotID != "" {
return nil, status.Errorf(codes.InvalidArgument, "Snapshot with ID %s is part of snapshotgroup %s", snapshotID, snapshot.GroupSnapshotID)
}

glog.V(4).Infof("deleting snapshot %s", snapshotID)
path := hp.getSnapshotPath(snapshotID)
os.RemoveAll(path)
Expand Down

0 comments on commit 21abfde

Please sign in to comment.