local-path-provisioner
local-path-provisioner copied to clipboard
[Question] Using loopback device to manage space
Hi folks, I'm looking for help/advice on adapting the setup/teardown scripts to create loopback devices as disks, to put a hard limit on the space allocated for each volume.
My current rough idea looks like the scripts below (which have only had very light testing so far).
Mostly, I'm looking for someone to tell me what obvious thing I'm missing that means this hasn't been done already.
Thanks.
setup:
NAME=$( basename $absolutePath )
# Store images in the folder above $absolutePath
IMAGE="$absolutePath/../$NAME.img"
# Create a backing file of the right size
dd if=/dev/zero of=$IMAGE count=$sizeInBytes iflag=count_bytes status=progress
# Give it a filesystem
# TOOD: Check if we've been asked for a filesystem!
mkfs.ext4 $IMAGE
# Add the new filesystem to host/node fstab
echo "$IMAGE $absolutePath ext4 loop 0 0" >> /etc/fstab
# Mount the device
mount $absolutePath
teardown:
IMAGE=$( grep $absolutePath /etc/fstab | awk '{print $1}' )
umount $absolutePath
sed -i "/$absolutePath/d' /etc/fstab
rm $IMAGE
To think about
- Rather than giving the caller the root (with /lost+found), create a folder in the mount and give them that
- Permissions?
- Chose your own filesystem
- A better way of naming/storing/identifying images
Looks good. Is there any hindrance in the setup/teardown scripts?