From 1cd4ca3d1f4f2ab55d4f6054c64f0177eff15e45 Mon Sep 17 00:00:00 2001 From: Mehran Kholdi Date: Sat, 26 Jun 2021 01:37:52 +0430 Subject: [PATCH] Refactor: code cleanup --- bd2fs.py | 4 +--- declarative.py | 9 +++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/bd2fs.py b/bd2fs.py index 93038cc..3ac1e45 100644 --- a/bd2fs.py +++ b/bd2fs.py @@ -17,7 +17,6 @@ from declarative import ( be_absent, be_formatted, be_fs_expanded, - current_fs, ) from metrics import path_stats, mountpoint_to_dev from util import log_grpc_request @@ -161,8 +160,7 @@ class Bd2FsNodeServicer(csi_pb2_grpc.NodeServicer): # > access_type from given volume_path for the volume and perform # > node expansion. # Apparently k8s 1.18 omits this field. - fs_type = current_fs(bd_request.volume_path) - be_fs_expanded(fs_type, bd_request.volume_path, volume_path) + be_fs_expanded(bd_request.volume_path, volume_path) size = request.capacity_range.required_bytes return csi_pb2.NodeExpandVolumeResponse(capacity_bytes=size) diff --git a/declarative.py b/declarative.py index 258e9a3..1425417 100644 --- a/declarative.py +++ b/declarative.py @@ -59,25 +59,26 @@ def current_fs(device): def be_formatted(dev, fs): - def init_fs(device, filesystem): + def init_fs(device): if fs == "ext4": run(f"mkfs.ext4 {device}") elif fs == "btrfs": run(f"mkfs.btrfs {device}") else: - raise Exception(f"Unsupported fs type: {filesystem}") + raise Exception(f"Unsupported fs type: {fs}") dev = Path(dev).resolve() current = current_fs(dev) if current is None: - init_fs(dev, fs) + init_fs(dev) else: if current != fs: raise Exception(f"Existing filesystem does not match: {current}/{fs}") -def be_fs_expanded(fs, dev, path): +def be_fs_expanded(dev, path): dev = Path(dev).resolve() + fs = current_fs(dev) path = Path(path).resolve() if fs == "ext4": run(f"resize2fs {dev}")