cephfs: update subvolume snapshot metadata if snapshot already exists.

Make sure to set metadata when subvolume snapshot exist, i.e. if the
provisioner pod is restarted while createSnapShot is in progress, say it
created the subvolume snapshot but didn't yet set the metadata.

Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
This commit is contained in:
Prasanna Kumar Kalever 2022-06-08 19:52:55 +05:30 committed by mergify[bot]
parent 7c9259a45e
commit 5f36f7e8bd

View File

@ -699,7 +699,7 @@ func (cs *ControllerServer) ControllerExpandVolume(
// CreateSnapshot creates the snapshot in backend and stores metadata // CreateSnapshot creates the snapshot in backend and stores metadata
// in store // in store
// nolint:gocyclo,cyclop // golangci-lint did not catch this earlier, needs to get fixed late // nolint:gocognit,gocyclo,cyclop // golangci-lint did not catch this earlier, needs to get fixed late
func (cs *ControllerServer) CreateSnapshot( func (cs *ControllerServer) CreateSnapshot(
ctx context.Context, ctx context.Context,
req *csi.CreateSnapshotRequest, req *csi.CreateSnapshotRequest,
@ -815,12 +815,12 @@ func (cs *ControllerServer) CreateSnapshot(
return nil, status.Error(codes.Internal, err.Error()) return nil, status.Error(codes.Internal, err.Error())
} }
metadata := k8s.GetSnapshotMetadata(req.GetParameters())
if sid != nil { if sid != nil {
// check snapshot is protected // check snapshot is protected
protected := true protected := true
snapClient := core.NewSnapshot(parentVolOptions.GetConnection(), sid.FsSnapshotName, &parentVolOptions.SubVolume)
if !(snapInfo.Protected == core.SnapshotIsProtected) { if !(snapInfo.Protected == core.SnapshotIsProtected) {
snapClient := core.NewSnapshot(parentVolOptions.GetConnection(),
sid.FsSnapshotName, &parentVolOptions.SubVolume)
err = snapClient.ProtectSnapshot(ctx) err = snapClient.ProtectSnapshot(ctx)
if err != nil { if err != nil {
protected = false protected = false
@ -829,6 +829,15 @@ func (cs *ControllerServer) CreateSnapshot(
} }
} }
// Update snapshot-name/snapshot-namespace/snapshotcontent-name details on
// subvolume snapshot as metadata in case snapshot already exist
if len(metadata) != 0 {
err = snapClient.SetAllSnapshotMetadata(metadata)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
}
return &csi.CreateSnapshotResponse{ return &csi.CreateSnapshotResponse{
Snapshot: &csi.Snapshot{ Snapshot: &csi.Snapshot{
SizeBytes: info.BytesQuota, SizeBytes: info.BytesQuota,
@ -854,7 +863,6 @@ func (cs *ControllerServer) CreateSnapshot(
} }
} }
}() }()
metadata := k8s.GetSnapshotMetadata(req.GetParameters())
snap, err := doSnapshot(ctx, parentVolOptions, sID.FsSnapshotName, metadata) snap, err := doSnapshot(ctx, parentVolOptions, sID.FsSnapshotName, metadata)
if err != nil { if err != nil {
return nil, status.Error(codes.Internal, err.Error()) return nil, status.Error(codes.Internal, err.Error())