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 <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2020-07-23 10:01:21 +02:00 committed by mergify[bot]
parent 36469b87e2
commit be9e7cf956
2 changed files with 7 additions and 7 deletions

View File

@ -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) util.DebugLog(ctx, "rbd volume %s size is %v,resizing to %v", rbdVol, rbdVol.VolSize, volSize)
rbdVol.VolSize = volSize rbdVol.VolSize = volSize
nodeExpansion = true nodeExpansion = true
err = resizeRBDImage(rbdVol, cr) err = rbdVol.resize(ctx, cr)
if err != nil { if err != nil {
klog.Errorf(util.Log(ctx, "failed to resize rbd image: %s with error: %v"), rbdVol, err) klog.Errorf(util.Log(ctx, "failed to resize rbd image: %s with error: %v"), rbdVol, err)
return nil, status.Error(codes.Internal, err.Error()) return nil, status.Error(codes.Internal, err.Error())

View File

@ -1042,13 +1042,13 @@ func cleanupRBDImageMetadataStash(path string) error {
return nil return nil
} }
// resizeRBDImage resizes the given volume to new size. // resize the given volume to new size.
func resizeRBDImage(rbdVol *rbdVolume, cr *util.Credentials) error { func (rv *rbdVolume) resize(ctx context.Context, cr *util.Credentials) error {
mon := rbdVol.Monitors mon := rv.Monitors
volSzMiB := fmt.Sprintf("%dM", util.RoundOffVolSize(rbdVol.VolSize)) volSzMiB := fmt.Sprintf("%dM", util.RoundOffVolSize(rv.VolSize))
args := []string{"resize", rbdVol.String(), "--size", volSzMiB, "--id", cr.ID, "-m", mon, "--keyfile=" + cr.KeyFile} args := []string{"resize", rv.String(), "--size", volSzMiB, "--id", cr.ID, "-m", mon, "--keyfile=" + cr.KeyFile}
_, stderr, err := util.ExecCommand(context.TODO(), "rbd", args...) _, stderr, err := util.ExecCommand(ctx, "rbd", args...)
if err != nil { if err != nil {
return fmt.Errorf("failed to resize rbd image (%w), command output: %s", err, stderr) return fmt.Errorf("failed to resize rbd image (%w), command output: %s", err, stderr)