-
Notifications
You must be signed in to change notification settings - Fork 6
Added initial creator for loopback based files #18
base: master
Are you sure you want to change the base?
Conversation
Added creator for generating XFS formatted files to use as loopback mounted PVs. Signed-off-by: ShyamsundarR <[email protected]>
Tested using local setup and scripts (which need to get in as a separate commit later). - Init fail/pass tests - Invalid unmount - Valid unmount - Valid mount - Multiple mounts - Single unmount post multiple unmounts Signed-off-by: ShyamsundarR <[email protected]>
Signed-off-by: ShyamsundarR <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Couldn't yet get to run the scripts, just a glance on the code looks fine.
Untested! Also 1 shellcheck warning remains. Signed-off-by: ShyamsundarR <[email protected]>
blockstore/creator/creator.sh
Outdated
fi | ||
# Create a sparse file of required volume size | ||
# 2097152 = 1024 * 1024 * 1024 (GB to bytes) / 512 (obs in dd) | ||
seek_end=$((volsize_gb*2097152)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion by @JohnStrunk to use 1 byte and normal 1GB math, than this 512 byte conversion, still to process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dd bs=1 count=1 if=/dev/zero of="${blockfqpath}" seek="$((volsize_gb * 1024 * 1024 *1024))"
Don't need bs=512
since it's not actually a block device.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack, will update in the next commit.
name: "{{ install_loc }}" | ||
state: directory | ||
|
||
# TODO: Check package installation for which, jq and util-linux |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intention is to check and add util-linux package as part of the ansible play, than check for jq presence, as this avoids copying jq and such.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
echo "Failed parsing PV $pv (unable to get backing file capacity)" | ||
return | ||
fi | ||
capacity=$(echo "$capacity_str" | sed -r "s/Gi//") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assumption is that the capacity is always in "Gi" units, no backing document found to understand possible range of values yet!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure other suffixes are allowed... Mi, Ti. Not sure about others, and a quick search has turned up nothing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marked TODO for tackling later when we move to larger PV sizes (or find enough documentation to write this cleanly)
local scrub="${vol_root}/${subdir}/${blockfile}" | ||
echo "= $(date) = Working on ${pv}" | ||
echo " Scrubbing $scrub" | ||
test -e "$scrub" && rm -f "$scrub" && test -z "$(ls -A "${vol_root}/${subdir}")" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shellcheck warning exists here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can just if ! rm -f "$scrub"; then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we start with lock files per device, then we may need to ensure rm -rf, than rm -f. But can change this for now. Corrected in the next commit.
Signed-off-by: ShyamsundarR <[email protected]>
@@ -0,0 +1 @@ | |||
oc adm policy add-scc-to-user anyuid system:serviceaccount:glusterfs:volrecycler-sa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JohnStrunk I think this is incorrect, the name in the end "volrecycler-sa" may need a different specialization for block devices?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to use the same exact service account across all subvol types. It just grants the recycler pod(s) permissions to modify the PVs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...And even a test script 💯
blockstore/creator/creator.sh
Outdated
echo "Unable to create $dir" | ||
exit 2 | ||
fi | ||
if ! chmod 777 "$dir"; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we need to open up the perms here. It exists on subvol because this last level directory needs to be writable by the random uid assigned to the pod where this acts as the PV. In this case, nothing but uid=0 touches this directory and the blockfile... creator is root, recycler is root, and so is kubelet when it calls the plugin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack, will update in the next commit.
blockstore/creator/creator.sh
Outdated
echo "Unable to create file ${blockfile}" | ||
exit 2 | ||
fi | ||
if ! chmod 777 "$blockfqpath"; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
permissions here too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack, will update in the next commit.
blockstore/creator/creator.sh
Outdated
fi | ||
# Create a sparse file of required volume size | ||
# 2097152 = 1024 * 1024 * 1024 (GB to bytes) / 512 (obs in dd) | ||
seek_end=$((volsize_gb*2097152)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dd bs=1 count=1 if=/dev/zero of="${blockfqpath}" seek="$((volsize_gb * 1024 * 1024 *1024))"
Don't need bs=512
since it's not actually a block device.
metadata: | ||
name: gluster-block-subvol | ||
annotations: | ||
storageclass.kubernetes.io/is-default-class: "true" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably don't want this. If a user wants this as the default storageclass, they can patch it once it's been added. Having it automatically set itself as cluster default raises the possibility of accidentally having 2 that are set as default. In that case, neither acts as default and default provisioning breaks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This yml is a helper/reminder for anyone who wants to add this as the default, right? Normally we do not need to add this as a storage class, as we use the Flexvol scheme. Isn't that right?
Assuming so, I would assume we leave this as is, for interested users to set this as a default. If my assumptions are wrong, then I would need to change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes good point. Since we use static provisioning, there is no need for the StorageClass object unless one wants it to become the default class. (not related to flex)
DEBUG=1 | ||
# if DEBUG is 2 output all commands (verbose debug mode) | ||
elif [ "${DEBUG}" == 2 ]; then | ||
set -x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may break the flex interface as it interacts w/ the script via stdout. (not actually sure if -x goes to stderr or whether flex monitors stderr)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was more for my debugging, will remove it in the next commit.
name: "{{ install_loc }}" | ||
state: directory | ||
|
||
# TODO: Check package installation for which, jq and util-linux |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
echo "Unable to create file ${blockfile}" | ||
return 2 | ||
fi | ||
if ! chmod 777 "$blockfqpath"; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
permissions like above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack, corrected in the next commit.
# Create a sparse file of required volume size | ||
# 2097152 = 1024 * 1024 * 1024 (GB to bytes) / 512 (obs in dd) | ||
local seek_end | ||
seek_end=$((volsize_gb*2097152)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
math like above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack, corrected in the next commit.
local scrub="${vol_root}/${subdir}/${blockfile}" | ||
echo "= $(date) = Working on ${pv}" | ||
echo " Scrubbing $scrub" | ||
test -e "$scrub" && rm -f "$scrub" && test -z "$(ls -A "${vol_root}/${subdir}")" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can just if ! rm -f "$scrub"; then
echo "Failed parsing PV $pv (unable to get backing file capacity)" | ||
return | ||
fi | ||
capacity=$(echo "$capacity_str" | sed -r "s/Gi//") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure other suffixes are allowed... Mi, Ti. Not sure about others, and a quick search has turned up nothing.
Addressed provided review comments. - Couple of instances added TODO to the code - Added SELinux capability as a task list item to ensure it is tested before enabling the same During testing in a k8s cluster, on CentOS7 found and fixed a couple of script errors and assumptions. - losetup does not have -n option in CentOS - PV yml needs to be quoted whereever possible Signed-off-by: ShyamsundarR <[email protected]>
This completes creator and the flex volume provider. Signed-off-by: ShyamsundarR <[email protected]>
Further, - Updated existing recycler ansible to handle block as well - Added ansible plays to test recycler - This should ideally be useful to test the non-block case as well. - Fixed bugs found during testing Signed-off-by: ShyamsundarR <[email protected]>
dest: "{{ install_loc }}/jq" | ||
mode: 0755 | ||
- name: Install required dependencies | ||
yum: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of yum:
, consider package:
so it auto-chooses which package manager to use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I had a vague remembrance of this, but could not find it when writing this up. Will do in the next patch.
Added creator for generating XFS formatted files to use as
loopback mounted PVs.
Updates #14
Signed-off-by: ShyamsundarR [email protected]