mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-22 06:10:22 +00:00
rbd: implement deleteImage() with go-ceph
Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
parent
0ca07e4657
commit
43857a3b75
@ -30,6 +30,7 @@ import (
|
|||||||
|
|
||||||
"github.com/ceph/ceph-csi/internal/util"
|
"github.com/ceph/ceph-csi/internal/util"
|
||||||
|
|
||||||
|
"github.com/ceph/go-ceph/rados"
|
||||||
librbd "github.com/ceph/go-ceph/rbd"
|
librbd "github.com/ceph/go-ceph/rbd"
|
||||||
"github.com/container-storage-interface/spec/lib/go/csi"
|
"github.com/container-storage-interface/spec/lib/go/csi"
|
||||||
"github.com/golang/protobuf/ptypes"
|
"github.com/golang/protobuf/ptypes"
|
||||||
@ -266,8 +267,6 @@ func rbdManagerTaskDeleteImage(ctx context.Context, pOpts *rbdVolume, cr *util.C
|
|||||||
|
|
||||||
// deleteImage deletes a ceph image with provision and volume options.
|
// deleteImage deletes a ceph image with provision and volume options.
|
||||||
func deleteImage(ctx context.Context, pOpts *rbdVolume, cr *util.Credentials) error {
|
func deleteImage(ctx context.Context, pOpts *rbdVolume, cr *util.Credentials) error {
|
||||||
var output []byte
|
|
||||||
|
|
||||||
image := pOpts.RbdImageName
|
image := pOpts.RbdImageName
|
||||||
found, _, err := rbdStatus(ctx, pOpts, cr)
|
found, _, err := rbdStatus(ctx, pOpts, cr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -288,12 +287,17 @@ func deleteImage(ctx context.Context, pOpts *rbdVolume, cr *util.Credentials) er
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !rbdCephMgrSupported {
|
if !rbdCephMgrSupported {
|
||||||
// attempt older style deletion
|
var ioctx *rados.IOContext
|
||||||
args := []string{"rm", image, "--pool", pOpts.Pool, "--id", cr.ID, "-m", pOpts.Monitors,
|
ioctx, err = pOpts.conn.GetIoctx(pOpts.Pool)
|
||||||
"--keyfile=" + cr.KeyFile}
|
|
||||||
output, err = execCommand("rbd", args)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf(util.Log(ctx, "failed to delete rbd image: %s/%s, error: %v, command output: %s"), pOpts.Pool, image, err, string(output))
|
return err
|
||||||
|
}
|
||||||
|
defer ioctx.Destroy()
|
||||||
|
|
||||||
|
rbdImage := librbd.GetImage(ioctx, image)
|
||||||
|
err = rbdImage.Remove()
|
||||||
|
if err != nil {
|
||||||
|
klog.Errorf(util.Log(ctx, "failed to delete rbd image: %s/%s, error: %v"), pOpts.Pool, image, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user