Refactor: code cleanup

This commit is contained in:
Mehran Kholdi 2021-06-26 01:37:52 +04:30
parent 89de295293
commit 1cd4ca3d1f
2 changed files with 6 additions and 7 deletions

View File

@ -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)

View File

@ -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}")