mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-23 21:40:20 +00:00
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:
parent
bfef0279a7
commit
1fd5277b3c
@ -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())
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user