From 1fd5277b3c02b2400d7491143542964d742f678c Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Thu, 28 Apr 2022 12:03:30 +0530 Subject: [PATCH] cleanup: simplify setVolumeMetadata and rename it Move k8s.GetVolumeMetadata() out of setVolumeMetadata() and rename it to setAllMetadata() so that the same can be used for setting volume and snapshot metadata. Signed-off-by: Prasanna Kumar Kalever --- internal/rbd/controllerserver.go | 12 ++++++++---- internal/rbd/rbd_journal.go | 2 +- internal/rbd/rbd_util.go | 20 +++----------------- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/internal/rbd/controllerserver.go b/internal/rbd/controllerserver.go index bbfde3f64..4a8b3dfa6 100644 --- a/internal/rbd/controllerserver.go +++ b/internal/rbd/controllerserver.go @@ -331,7 +331,8 @@ func (cs *ControllerServer) CreateVolume( } // Set Metadata on PV Create - err = rbdVol.setVolumeMetadata(req.GetParameters()) + metadata := k8s.GetVolumeMetadata(req.GetParameters()) + err = rbdVol.setAllMetadata(metadata) if err != nil { return nil, err } @@ -454,7 +455,8 @@ func (cs *ControllerServer) repairExistingVolume(ctx context.Context, req *csi.C } // Set metadata on restart of provisioner pod when image exist - err := rbdVol.setVolumeMetadata(req.GetParameters()) + metadata := k8s.GetVolumeMetadata(req.GetParameters()) + err := rbdVol.setAllMetadata(metadata) if err != nil { return nil, err } @@ -1074,7 +1076,8 @@ func (cs *ControllerServer) CreateSnapshot( // Set snapshot-name/snapshot-namespace/snapshotcontent-name details // on RBD backend image as metadata on create - err = rbdVol.setSnapshotMetadata(req.GetParameters()) + metadata := k8s.GetSnapshotMetadata(req.GetParameters()) + err = rbdVol.setAllMetadata(metadata) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } @@ -1131,7 +1134,8 @@ func cloneFromSnapshot( // Update snapshot-name/snapshot-namespace/snapshotcontent-name details on // RBD backend image as metadata on restart of provisioner pod when image exist if len(parameters) != 0 { - err = rbdVol.setSnapshotMetadata(parameters) + metadata := k8s.GetSnapshotMetadata(parameters) + err = rbdVol.setAllMetadata(metadata) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } diff --git a/internal/rbd/rbd_journal.go b/internal/rbd/rbd_journal.go index dc3c0b920..57121c65b 100644 --- a/internal/rbd/rbd_journal.go +++ b/internal/rbd/rbd_journal.go @@ -617,7 +617,7 @@ func RegenerateJournal( } // Update Metadata on reattach of the same old PV parameters := k8s.PrepareVolumeMetadata(claimName, rbdVol.Owner, "") - err = rbdVol.setVolumeMetadata(parameters) + err = rbdVol.setAllMetadata(parameters) if err != nil { return "", fmt.Errorf("failed to set volume metadata: %w", err) } diff --git a/internal/rbd/rbd_util.go b/internal/rbd/rbd_util.go index e6e4e08c1..8b02de787 100644 --- a/internal/rbd/rbd_util.go +++ b/internal/rbd/rbd_util.go @@ -28,7 +28,6 @@ import ( "time" "github.com/ceph/ceph-csi/internal/util" - "github.com/ceph/ceph-csi/internal/util/k8s" "github.com/ceph/ceph-csi/internal/util/log" "github.com/ceph/go-ceph/rados" @@ -1913,22 +1912,9 @@ func genVolFromVolIDWithMigration( return rv, err } -// setVolumeMetadata set PV/PVC/PVCNamespace metadata on RBD image. -func (rv *rbdVolume) setVolumeMetadata(parameters map[string]string) error { - for k, v := range k8s.GetVolumeMetadata(parameters) { - err := rv.SetMetadata(k, v) - if err != nil { - return fmt.Errorf("failed to set metadata key %q, value %q on image: %w", k, v, err) - } - } - - return nil -} - -// setSnapshotMetadata Set snapshot-name/snapshot-namespace/snapshotcontent-name metadata -// on RBD image. -func (rv *rbdVolume) setSnapshotMetadata(parameters map[string]string) error { - for k, v := range k8s.GetSnapshotMetadata(parameters) { +// setAllMetadata set all the metadata from arg parameters on RBD image. +func (rv *rbdVolume) setAllMetadata(parameters map[string]string) error { + for k, v := range parameters { err := rv.SetMetadata(k, v) if err != nil { return fmt.Errorf("failed to set metadata key %q, value %q on image: %w", k, v, err)