Refactor: code cleanup
This commit is contained in:
parent
89de295293
commit
1cd4ca3d1f
4
bd2fs.py
4
bd2fs.py
@ -17,7 +17,6 @@ from declarative import (
|
|||||||
be_absent,
|
be_absent,
|
||||||
be_formatted,
|
be_formatted,
|
||||||
be_fs_expanded,
|
be_fs_expanded,
|
||||||
current_fs,
|
|
||||||
)
|
)
|
||||||
from metrics import path_stats, mountpoint_to_dev
|
from metrics import path_stats, mountpoint_to_dev
|
||||||
from util import log_grpc_request
|
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
|
# > access_type from given volume_path for the volume and perform
|
||||||
# > node expansion.
|
# > node expansion.
|
||||||
# Apparently k8s 1.18 omits this field.
|
# Apparently k8s 1.18 omits this field.
|
||||||
fs_type = current_fs(bd_request.volume_path)
|
be_fs_expanded(bd_request.volume_path, volume_path)
|
||||||
be_fs_expanded(fs_type, bd_request.volume_path, volume_path)
|
|
||||||
|
|
||||||
size = request.capacity_range.required_bytes
|
size = request.capacity_range.required_bytes
|
||||||
return csi_pb2.NodeExpandVolumeResponse(capacity_bytes=size)
|
return csi_pb2.NodeExpandVolumeResponse(capacity_bytes=size)
|
||||||
|
@ -59,25 +59,26 @@ def current_fs(device):
|
|||||||
|
|
||||||
|
|
||||||
def be_formatted(dev, fs):
|
def be_formatted(dev, fs):
|
||||||
def init_fs(device, filesystem):
|
def init_fs(device):
|
||||||
if fs == "ext4":
|
if fs == "ext4":
|
||||||
run(f"mkfs.ext4 {device}")
|
run(f"mkfs.ext4 {device}")
|
||||||
elif fs == "btrfs":
|
elif fs == "btrfs":
|
||||||
run(f"mkfs.btrfs {device}")
|
run(f"mkfs.btrfs {device}")
|
||||||
else:
|
else:
|
||||||
raise Exception(f"Unsupported fs type: {filesystem}")
|
raise Exception(f"Unsupported fs type: {fs}")
|
||||||
|
|
||||||
dev = Path(dev).resolve()
|
dev = Path(dev).resolve()
|
||||||
current = current_fs(dev)
|
current = current_fs(dev)
|
||||||
if current is None:
|
if current is None:
|
||||||
init_fs(dev, fs)
|
init_fs(dev)
|
||||||
else:
|
else:
|
||||||
if current != fs:
|
if current != fs:
|
||||||
raise Exception(f"Existing filesystem does not match: {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()
|
dev = Path(dev).resolve()
|
||||||
|
fs = current_fs(dev)
|
||||||
path = Path(path).resolve()
|
path = Path(path).resolve()
|
||||||
if fs == "ext4":
|
if fs == "ext4":
|
||||||
run(f"resize2fs {dev}")
|
run(f"resize2fs {dev}")
|
||||||
|
Loading…
Reference in New Issue
Block a user