Skip to content

Commit

Permalink
fix: fix snapshot object creation for apiv2 integration
Browse files Browse the repository at this point in the history
When creating csi.Snapshot object from API response, earlier versions
used objectType == 'snapshots'. Now use objectName == 'snapshot' instead.
Also use the timestamp object returned by the api lib directly instead
of generating it from a string.
  • Loading branch information
David-T-White committed Sep 27, 2023
1 parent 2359f1b commit d3acd84
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions pkg/controller/snapshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (controller *Controller) CreateSnapshot(ctx context.Context, req *csi.Creat

var snapshot *csi.Snapshot
for _, ss := range snapshots {
if ss.ObjectName != "snapshots" {
if ss.ObjectName != "snapshot" {
continue
}

Expand Down Expand Up @@ -157,19 +157,17 @@ func (controller *Controller) ListSnapshots(ctx context.Context, req *csi.ListSn
}

func newSnapshotFromResponse(snapshot *storageapitypes.SnapshotObject) (*csi.Snapshot, error) {
if snapshot.ObjectName != "snapshots" {
return nil, fmt.Errorf("not a snapshot object, type is %v", snapshot.ObjectName)
if snapshot.ObjectName != "snapshot" {
return nil, fmt.Errorf("not a snapshot object, type is %v", snapshot.ObjectName)
}

creationTime, _ := creationTimeFromString(snapshot.CreationDateTime)

klog.Info("csi snapshot info", "snapshot", snapshot.Name, "volume", snapshot.MasterVolumeName)
klog.InfoS("csi snapshot info", "snapshot", snapshot.Name, "volume", snapshot.MasterVolumeName, "creationTime", snapshot.CreationTime)

return &csi.Snapshot{
SizeBytes: snapshot.TotalSizeNumeric,
SnapshotId: snapshot.Name,
SourceVolumeId: snapshot.MasterVolumeName,
CreationTime: creationTime,
CreationTime: snapshot.CreationTime,
ReadyToUse: true,
}, nil
}
Expand Down

0 comments on commit d3acd84

Please sign in to comment.