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 <prasanna.kalever@redhat.com>
This commit is contained in:
Prasanna Kumar Kalever 2022-04-28 12:03:30 +05:30 committed by mergify[bot]
parent bfef0279a7
commit 1fd5277b3c
3 changed files with 12 additions and 22 deletions

View File

@ -331,7 +331,8 @@ func (cs *ControllerServer) CreateVolume(
} }
// Set Metadata on PV Create // Set Metadata on PV Create
err = rbdVol.setVolumeMetadata(req.GetParameters()) metadata := k8s.GetVolumeMetadata(req.GetParameters())
err = rbdVol.setAllMetadata(metadata)
if err != nil { if err != nil {
return nil, err 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 // 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 { if err != nil {
return nil, err return nil, err
} }
@ -1074,7 +1076,8 @@ func (cs *ControllerServer) CreateSnapshot(
// Set snapshot-name/snapshot-namespace/snapshotcontent-name details // Set snapshot-name/snapshot-namespace/snapshotcontent-name details
// on RBD backend image as metadata on create // 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 { if err != nil {
return nil, status.Error(codes.Internal, err.Error()) return nil, status.Error(codes.Internal, err.Error())
} }
@ -1131,7 +1134,8 @@ func cloneFromSnapshot(
// Update snapshot-name/snapshot-namespace/snapshotcontent-name details on // Update snapshot-name/snapshot-namespace/snapshotcontent-name details on
// RBD backend image as metadata on restart of provisioner pod when image exist // RBD backend image as metadata on restart of provisioner pod when image exist
if len(parameters) != 0 { if len(parameters) != 0 {
err = rbdVol.setSnapshotMetadata(parameters) metadata := k8s.GetSnapshotMetadata(parameters)
err = rbdVol.setAllMetadata(metadata)
if err != nil { if err != nil {
return nil, status.Error(codes.Internal, err.Error()) return nil, status.Error(codes.Internal, err.Error())
} }

View File

@ -617,7 +617,7 @@ func RegenerateJournal(
} }
// Update Metadata on reattach of the same old PV // Update Metadata on reattach of the same old PV
parameters := k8s.PrepareVolumeMetadata(claimName, rbdVol.Owner, "") parameters := k8s.PrepareVolumeMetadata(claimName, rbdVol.Owner, "")
err = rbdVol.setVolumeMetadata(parameters) err = rbdVol.setAllMetadata(parameters)
if err != nil { if err != nil {
return "", fmt.Errorf("failed to set volume metadata: %w", err) return "", fmt.Errorf("failed to set volume metadata: %w", err)
} }

View File

@ -28,7 +28,6 @@ import (
"time" "time"
"github.com/ceph/ceph-csi/internal/util" "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/ceph-csi/internal/util/log"
"github.com/ceph/go-ceph/rados" "github.com/ceph/go-ceph/rados"
@ -1913,22 +1912,9 @@ func genVolFromVolIDWithMigration(
return rv, err return rv, err
} }
// setVolumeMetadata set PV/PVC/PVCNamespace metadata on RBD image. // setAllMetadata set all the metadata from arg parameters on RBD image.
func (rv *rbdVolume) setVolumeMetadata(parameters map[string]string) error { func (rv *rbdVolume) setAllMetadata(parameters map[string]string) error {
for k, v := range k8s.GetVolumeMetadata(parameters) { 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)
}
}
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) {
err := rv.SetMetadata(k, v) err := rv.SetMetadata(k, v)
if err != nil { if err != nil {
return fmt.Errorf("failed to set metadata key %q, value %q on image: %w", k, v, err) return fmt.Errorf("failed to set metadata key %q, value %q on image: %w", k, v, err)