Skip to content

Commit 3b83da7

Browse files
leonardocenixpanic
authored andcommitted
Keep track of both the PV Handle IDs and Snapshot IDs
This avoids the CSI driver to fail with `group snapshot with the same name: ... but with different SourceVolumeIds already exist`.
1 parent 115b2ad commit 3b83da7

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

pkg/hostpath/groupcontrollerserver.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,16 @@ func (hp *hostPath) CreateVolumeGroupSnapshot(ctx context.Context, req *csi.Crea
102102
}
103103

104104
groupSnapshot := state.GroupSnapshot{
105-
Name: req.GetName(),
106-
Id: uuid.NewUUID().String(),
107-
CreationTime: ptypes.TimestampNow(),
108-
SnapshotIDs: make([]string, len(req.GetSourceVolumeIds())),
109-
ReadyToUse: true,
105+
Name: req.GetName(),
106+
Id: uuid.NewUUID().String(),
107+
CreationTime: ptypes.TimestampNow(),
108+
SnapshotIDs: make([]string, len(req.GetSourceVolumeIds())),
109+
SourceVolumeIDs: make([]string, len(req.GetSourceVolumeIds())),
110+
ReadyToUse: true,
110111
}
111112

113+
copy(groupSnapshot.SourceVolumeIDs, req.GetSourceVolumeIds())
114+
112115
snapshots := make([]*csi.Snapshot, len(req.GetSourceVolumeIds()))
113116

114117
// TODO: defer a cleanup function to remove snapshots in case of a failure

pkg/state/state.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@ type Snapshot struct {
7070
}
7171

7272
type GroupSnapshot struct {
73-
Name string
74-
Id string
75-
SnapshotIDs []string
76-
CreationTime *timestamp.Timestamp
77-
ReadyToUse bool
73+
Name string
74+
Id string
75+
SnapshotIDs []string
76+
SourceVolumeIDs []string
77+
CreationTime *timestamp.Timestamp
78+
ReadyToUse bool
7879
}
7980

8081
// State is the interface that the rest of the code has to use to
@@ -337,17 +338,17 @@ func (s *state) DeleteGroupSnapshot(groupSnapshotID string) error {
337338
}
338339

339340
func (gs *GroupSnapshot) MatchesSourceVolumeIDs(sourceVolumeIDs []string) bool {
340-
snapshotIDs := gs.SnapshotIDs
341+
stateSourceVolumeIDs := gs.SourceVolumeIDs
341342

342-
if len(snapshotIDs) != len(sourceVolumeIDs) {
343+
if len(stateSourceVolumeIDs) != len(sourceVolumeIDs) {
343344
return false
344345
}
345346

346347
// sort slices so that values are at the same location
347-
sort.Strings(snapshotIDs)
348+
sort.Strings(stateSourceVolumeIDs)
348349
sort.Strings(sourceVolumeIDs)
349350

350-
for i, v := range snapshotIDs {
351+
for i, v := range stateSourceVolumeIDs {
351352
if v != sourceVolumeIDs[i] {
352353
return false
353354
}

0 commit comments

Comments
 (0)