rbd: add unset volume/snapshot metadata utility functions

Added
GetVolumeMetadataKeys()
GetSnaoshotMetadataKeys()
unsetVolumeMetadata() and
unsetSnapshotMetadata()

functions.

Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
This commit is contained in:
Prasanna Kumar Kalever 2022-04-04 17:13:39 +05:30 committed by mergify[bot]
parent 1fd5277b3c
commit bac33262ae
2 changed files with 31 additions and 0 deletions

View File

@ -1923,3 +1923,16 @@ func (rv *rbdVolume) setAllMetadata(parameters map[string]string) error {
return nil
}
// unsetAllMetadata unset all the metadata from arg keys on RBD image.
func (rv *rbdVolume) unsetAllMetadata(keys []string) error {
for _, key := range keys {
err := rv.RemoveMetadata(key)
// TODO: replace string comparison with errno.
if err != nil && !strings.Contains(err.Error(), "No such file or directory") {
return fmt.Errorf("failed to unset metadata key %q on %q: %w", key, rv, err)
}
}
return nil
}

View File

@ -69,6 +69,15 @@ func GetVolumeMetadata(parameters map[string]string) map[string]string {
return newParam
}
// GetVolumeMetadataKeys return volume metadata keys.
func GetVolumeMetadataKeys() []string {
return []string{
pvcNameKey,
pvcNamespaceKey,
pvNameKey,
}
}
// PrepareVolumeMetadata return PV/PVC/PVCNamespace metadata based on inputs.
func PrepareVolumeMetadata(pvcName, pvcNamespace, pvName string) map[string]string {
newParam := map[string]string{}
@ -100,3 +109,12 @@ func GetSnapshotMetadata(parameters map[string]string) map[string]string {
return newParam
}
// GetSnapshotMetadataKeys return snapshot metadata keys.
func GetSnapshotMetadataKeys() []string {
return []string{
volSnapNameKey,
volSnapNamespaceKey,
volSnapContentNameKey,
}
}