util: implement RemoveObject() with go-ceph

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2020-06-02 10:02:02 +02:00 committed by mergify[bot]
parent 926f1e813c
commit 6e24b10364

View File

@ -249,27 +249,31 @@ func CreateObject(ctx context.Context, monitors string, cr *Credentials, poolNam
// RemoveObject removes the entire omap name passed in and returns ErrObjectNotFound is provided omap
// is not found in rados
func RemoveObject(ctx context.Context, monitors string, cr *Credentials, poolName, namespace, oMapName string) error {
// Command: "rados <options> rm oMapName"
args := []string{
"-m", monitors,
"--id", cr.ID,
"--keyfile=" + cr.KeyFile,
"-c", CephConfigPath,
"-p", poolName,
"rm", oMapName,
conn := ClusterConnection{}
err := conn.Connect(monitors, cr)
if err != nil {
return err
}
defer conn.Destroy()
ioctx, err := conn.GetIoctx(poolName)
if err != nil {
if _, ok := err.(ErrPoolNotFound); ok {
err = ErrObjectNotFound{poolName, err}
}
return err
}
defer ioctx.Destroy()
if namespace != "" {
args = append(args, "--namespace="+namespace)
ioctx.SetNamespace(namespace)
}
_, stderr, err := ExecCommand("rados", args[:]...)
if err != nil {
err = ioctx.Delete(oMapName)
if err == rados.ErrNotFound {
return ErrObjectNotFound{oMapName, err}
} else if err != nil {
klog.Errorf(Log(ctx, "failed removing omap (%s) in pool (%s): (%v)"), oMapName, poolName, err)
if strings.Contains(string(stderr), "error removing "+poolName+">"+oMapName+
": (2) No such file or directory") {
return ErrObjectNotFound{oMapName, err}
}
return err
}