From 5f36f7e8bda75245c5f3563da4c41a92d3fbba0f Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Wed, 8 Jun 2022 19:52:55 +0530 Subject: [PATCH] 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 --- internal/cephfs/controllerserver.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/internal/cephfs/controllerserver.go b/internal/cephfs/controllerserver.go index dce5e7593..6a2867c52 100644 --- a/internal/cephfs/controllerserver.go +++ b/internal/cephfs/controllerserver.go @@ -699,7 +699,7 @@ func (cs *ControllerServer) ControllerExpandVolume( // CreateSnapshot creates the snapshot in backend and stores metadata // 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( ctx context.Context, req *csi.CreateSnapshotRequest, @@ -815,12 +815,12 @@ func (cs *ControllerServer) CreateSnapshot( return nil, status.Error(codes.Internal, err.Error()) } + metadata := k8s.GetSnapshotMetadata(req.GetParameters()) if sid != nil { // check snapshot is protected protected := true + snapClient := core.NewSnapshot(parentVolOptions.GetConnection(), sid.FsSnapshotName, &parentVolOptions.SubVolume) if !(snapInfo.Protected == core.SnapshotIsProtected) { - snapClient := core.NewSnapshot(parentVolOptions.GetConnection(), - sid.FsSnapshotName, &parentVolOptions.SubVolume) err = snapClient.ProtectSnapshot(ctx) if err != nil { 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{ Snapshot: &csi.Snapshot{ SizeBytes: info.BytesQuota, @@ -854,7 +863,6 @@ func (cs *ControllerServer) CreateSnapshot( } } }() - metadata := k8s.GetSnapshotMetadata(req.GetParameters()) snap, err := doSnapshot(ctx, parentVolOptions, sID.FsSnapshotName, metadata) if err != nil { return nil, status.Error(codes.Internal, err.Error())