mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-12-18 11:00:25 +00:00
cephfs: implement purgeVolume with go-ceph
moved frm ceph fs CLI to go-ceph for purgeVolume. Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
parent
34d0ff0d70
commit
9a96370942
@ -22,10 +22,8 @@ import (
|
|||||||
|
|
||||||
// Error strings for comparison with CLI errors.
|
// Error strings for comparison with CLI errors.
|
||||||
const (
|
const (
|
||||||
// volumeNotFound is returned when a subvolume is not found in CephFS.
|
|
||||||
volumeNotFound = "Error ENOENT"
|
|
||||||
// volumeNotEmpty is returned when the volume is not empty.
|
// volumeNotEmpty is returned when the volume is not empty.
|
||||||
volumeNotEmpty = "Error ENOTEMPTY"
|
volumeNotEmpty = "Directory not empty"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -210,33 +210,26 @@ func (vo *volumeOptions) resizeVolume(ctx context.Context, volID volumeID, bytes
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (vo *volumeOptions) purgeVolume(ctx context.Context, volID volumeID, cr *util.Credentials, force bool) error {
|
func (vo *volumeOptions) purgeVolume(ctx context.Context, volID volumeID, cr *util.Credentials, force bool) error {
|
||||||
arg := []string{
|
fsa, err := vo.conn.GetFSAdmin()
|
||||||
"fs",
|
if err != nil {
|
||||||
"subvolume",
|
util.ErrorLog(ctx, "could not get FSAdmin %s:", err)
|
||||||
"rm",
|
return err
|
||||||
vo.FsName,
|
|
||||||
string(volID),
|
|
||||||
"--group_name",
|
|
||||||
vo.SubvolumeGroup,
|
|
||||||
"-m", vo.Monitors,
|
|
||||||
"-c", util.CephConfigPath,
|
|
||||||
"-n", cephEntityClientPrefix + cr.ID,
|
|
||||||
"--keyfile=" + cr.KeyFile,
|
|
||||||
}
|
|
||||||
if force {
|
|
||||||
arg = append(arg, "--force")
|
|
||||||
}
|
|
||||||
if checkSubvolumeHasFeature("snapshot-retention", vo.Features) {
|
|
||||||
arg = append(arg, "--retain-snapshots")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err := execCommandErr(ctx, "ceph", arg...)
|
opt := fsAdmin.SubVolRmFlags{}
|
||||||
|
opt.Force = force
|
||||||
|
|
||||||
|
if checkSubvolumeHasFeature("snapshot-retention", vo.Features) {
|
||||||
|
opt.RetainSnapshots = true
|
||||||
|
}
|
||||||
|
|
||||||
|
err = fsa.RemoveSubVolumeWithFlags(vo.FsName, vo.SubvolumeGroup, string(volID), opt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
util.ErrorLog(ctx, "failed to purge subvolume %s in fs %s: %s", string(volID), vo.FsName, err)
|
util.ErrorLog(ctx, "failed to purge subvolume %s in fs %s: %s", string(volID), vo.FsName, err)
|
||||||
if strings.Contains(err.Error(), volumeNotEmpty) {
|
if strings.Contains(err.Error(), volumeNotEmpty) {
|
||||||
return util.JoinErrors(ErrVolumeHasSnapshots, err)
|
return util.JoinErrors(ErrVolumeHasSnapshots, err)
|
||||||
}
|
}
|
||||||
if strings.Contains(err.Error(), volumeNotFound) {
|
if errors.Is(err, rados.ErrNotFound) {
|
||||||
return util.JoinErrors(ErrVolumeNotFound, err)
|
return util.JoinErrors(ErrVolumeNotFound, err)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user