Compare commits

..

7 Commits

Author SHA1 Message Date
Lauri Võsandi 6648d0070c PV grow workaround
continuous-integration/drone Build is passing Details
2022-11-28 22:40:20 +02:00
Lauri Võsandi 439954e3ed Add Drone config 2022-11-28 19:07:45 +02:00
Mehran Kholdi 4e0a4fe698 Release 0.8.0 2022-03-30 13:20:57 +04:30
Mehran Kholdi 0a130f42ff Support creating snapshots from btrfs volumes 2022-03-30 13:15:46 +04:30
Mehran Kholdi c978b3290b Update base python version 2022-03-30 12:47:15 +04:30
Mehran Kholdi 22f2fb1628 Neat: code cleanup 2022-03-30 12:47:14 +04:30
Mehran Kholdi 2d1fa49b2a Delete task pods even upon failure
To prevent cluttering the namespace with lots of failing task pods.
2022-01-22 00:19:00 +03:30
4 changed files with 34 additions and 5 deletions

View File

@ -4,4 +4,5 @@ PROVISIONER_NAME = os.getenv("PROVISIONER_NAME", "rawfile.csi.openebs.io")
PROVISIONER_VERSION = "0.8.0"
DATA_DIR = "/data"
CONFIG = {}
RESOURCE_EXHAUSTED_EXIT_CODE = 101
VOLUME_IN_USE_EXIT_CODE = 102

View File

@ -8,6 +8,7 @@ import rawfile_util
from consts import (
PROVISIONER_VERSION,
PROVISIONER_NAME,
RESOURCE_EXHAUSTED_EXIT_CODE,
VOLUME_IN_USE_EXIT_CODE,
)
from csi import csi_pb2, csi_pb2_grpc
@ -191,7 +192,15 @@ class RawFileControllerServicer(csi_pb2_grpc.ControllerServicer):
grpc.StatusCode.INVALID_ARGUMENT, "Topology key not found... why?"
)
init_rawfile(volume_id=request.name, size=size),
try:
init_rawfile(volume_id=request.name, size=size),
except CalledProcessError as exc:
if exc.returncode == RESOURCE_EXHAUSTED_EXIT_CODE:
context.abort(
grpc.StatusCode.RESOURCE_EXHAUSTED, "Not enough disk space"
)
else:
raise exc
return csi_pb2.CreateVolumeResponse(
volume=csi_pb2.Volume(
@ -225,9 +234,17 @@ class RawFileControllerServicer(csi_pb2_grpc.ControllerServicer):
node_name = volume_to_node(volume_id)
size = request.capacity_range.required_bytes
run_on_node(
expand_rawfile.as_cmd(volume_id=volume_id, size=size), node=node_name
)
try:
run_on_node(
expand_rawfile.as_cmd(volume_id=volume_id, size=size), node=node_name
)
except CalledProcessError as exc:
if exc.returncode == RESOURCE_EXHAUSTED_EXIT_CODE:
context.abort(
grpc.StatusCode.RESOURCE_EXHAUSTED, "Not enough disk space"
)
else:
raise exc
return csi_pb2.ControllerExpandVolumeResponse(
capacity_bytes=size,

View File

@ -129,4 +129,8 @@ def get_volumes_stats() -> [dict]:
def get_capacity():
return path_stats(DATA_DIR)["fs_avail"]
disk_free_size = path_stats(DATA_DIR)["fs_avail"]
capacity = disk_free_size
for volume_stat in get_volumes_stats().values():
capacity -= volume_stat["total"] - volume_stat["used"]
return capacity

View File

@ -34,6 +34,10 @@ def init_rawfile(volume_id, size):
import rawfile_util
from volume_schema import LATEST_SCHEMA_VERSION
from util import run
from consts import RESOURCE_EXHAUSTED_EXIT_CODE
if rawfile_util.get_capacity() < size:
raise CalledProcessError(returncode=RESOURCE_EXHAUSTED_EXIT_CODE, cmd="")
img_dir = rawfile_util.img_dir(volume_id)
img_dir.mkdir(exist_ok=True)
@ -65,11 +69,14 @@ def expand_rawfile(volume_id, size):
import rawfile_util
from util import run
from consts import RESOURCE_EXHAUSTED_EXIT_CODE
img_file = rawfile_util.img_file(volume_id)
size_inc = size - rawfile_util.metadata(volume_id)["size"]
if size_inc <= 0:
return
if rawfile_util.get_capacity() < size_inc:
exit(RESOURCE_EXHAUSTED_EXIT_CODE)
rawfile_util.patch_metadata(
volume_id,