From be9e7cf956c378227ff43e0194410468919766b7 Mon Sep 17 00:00:00 2001 From: Niels de Vos Date: Thu, 23 Jul 2020 10:01:21 +0200 Subject: [PATCH] rbd: pass context.Context to rbdVolume.resize() While adding the context.Context to the resizeRBDimage() function, it became a little ugly. So renaming the function to resize() and making it a method of the rbdVolume type. Signed-off-by: Niels de Vos --- internal/rbd/controllerserver.go | 2 +- internal/rbd/rbd_util.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/rbd/controllerserver.go b/internal/rbd/controllerserver.go index 5de3d1b0b..47adfe285 100644 --- a/internal/rbd/controllerserver.go +++ b/internal/rbd/controllerserver.go @@ -1092,7 +1092,7 @@ func (cs *ControllerServer) ControllerExpandVolume(ctx context.Context, req *csi util.DebugLog(ctx, "rbd volume %s size is %v,resizing to %v", rbdVol, rbdVol.VolSize, volSize) rbdVol.VolSize = volSize nodeExpansion = true - err = resizeRBDImage(rbdVol, cr) + err = rbdVol.resize(ctx, cr) if err != nil { klog.Errorf(util.Log(ctx, "failed to resize rbd image: %s with error: %v"), rbdVol, err) return nil, status.Error(codes.Internal, err.Error()) diff --git a/internal/rbd/rbd_util.go b/internal/rbd/rbd_util.go index 55eb70ce9..432c50b6a 100644 --- a/internal/rbd/rbd_util.go +++ b/internal/rbd/rbd_util.go @@ -1042,13 +1042,13 @@ func cleanupRBDImageMetadataStash(path string) error { return nil } -// resizeRBDImage resizes the given volume to new size. -func resizeRBDImage(rbdVol *rbdVolume, cr *util.Credentials) error { - mon := rbdVol.Monitors - volSzMiB := fmt.Sprintf("%dM", util.RoundOffVolSize(rbdVol.VolSize)) +// resize the given volume to new size. +func (rv *rbdVolume) resize(ctx context.Context, cr *util.Credentials) error { + mon := rv.Monitors + volSzMiB := fmt.Sprintf("%dM", util.RoundOffVolSize(rv.VolSize)) - args := []string{"resize", rbdVol.String(), "--size", volSzMiB, "--id", cr.ID, "-m", mon, "--keyfile=" + cr.KeyFile} - _, stderr, err := util.ExecCommand(context.TODO(), "rbd", args...) + args := []string{"resize", rv.String(), "--size", volSzMiB, "--id", cr.ID, "-m", mon, "--keyfile=" + cr.KeyFile} + _, stderr, err := util.ExecCommand(ctx, "rbd", args...) if err != nil { return fmt.Errorf("failed to resize rbd image (%w), command output: %s", err, stderr)