Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Functionality to setup disk specific RAIDs #48

Merged
merged 6 commits into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 47 additions & 4 deletions packet/flatcar-linux/kubernetes/workers/cl/install.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,57 @@ storage:
mkfs.ext4 /dev/md/node-local-storage
}

function create_disk_specific_data_raid() {
surajssd marked this conversation as resolved.
Show resolved Hide resolved
# Ignore the disk on which Linux is installed when selecting disks for RAID.
local osdisk="$1"
local major_numbers="$2"
# for hdd value is 1 and for ssd value is 0
local disk_type="$3"
# RAID device path on disk
local device_path="$4"
local setup_fs_on_raid="$5"

# Select disks for RAID.
local disks=$(lsblk -lnpd -o name,rota -I "$${major_numbers}" \
| grep "$${disk_type}" \
pothos marked this conversation as resolved.
Show resolved Hide resolved
| sort -h -k 4,4 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sort can be deleted and has no effect anyway because the keys are wrong. If you want to sort by something, then use lsblk -lnpd - x size or lsblk -lnpd -x rota (and add | tac to reverse the ordering).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL: tac 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I think about it, is there really a need to sort here? Do we need sorted disk order to form RAID?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to have predictable RAID devices here, so sorting is a good idea. Otherwise for every server, you will have a different disk layout. It's easier to spot potential inconsistencies/issues when the setup is predictable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should change all that in a follow up PR, this PR has already been prolonged for so long on very minuscule issues.

Copy link
Contributor

@pothos pothos Aug 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to sort it I would say. The sorting was just done to find the smallest disk for installation - that works even if it's more complicated as it needs to be. Anyway, the sort invocation here is a no-op and should be deleted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record: lsblk -lnpd -o name,rota | sort -h -k 4,4 --debug complains that it cannot match the key (sorting by rota makes no sense anyway?).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it has to be sorted on the basis of size.

The diff would look something like this:

diff --git a/packet/flatcar-linux/kubernetes/workers/cl/install.yaml.tmpl b/packet/flatcar-linux/kubernetes/workers/cl/install.yaml.tmpl                                     
index f51c6df..39b63f2 100644                                                                                                                                                
--- a/packet/flatcar-linux/kubernetes/workers/cl/install.yaml.tmpl                                                                                                           
+++ b/packet/flatcar-linux/kubernetes/workers/cl/install.yaml.tmpl                                                                                                           
@@ -99,9 +99,8 @@ storage:                                                                                                                                                   
             local setup_fs_on_raid="$5"                                                                                                                                     
                                                                                                                                                                             
             # Select disks for RAID.                                                 
-            local disks=$(lsblk -lnpd -o name,rota -I "$${major_numbers}" \          
+            local disks=$(lsblk -lnpd -o name,rota,size -I "$${major_numbers}" -x size \                                                                                    
               | grep "$${disk_type}" \                                               
-              | sort -h -k 4,4 \                                                     
               | grep -vE "^$${osdisk} " \                                                                                                                                   
               | awk '{x=$1 " " x;} END{print x}'                                     
             ) 

| grep -vE "^$${osdisk} " \
| awk '{x=$1 " " x;} END{print x}'
surajssd marked this conversation as resolved.
Show resolved Hide resolved
)
local count=$(echo "$$disks" | wc -w)

# Exit if we don't have any disks to create an array
[ $$count -lt 1 ] && return 0

# Create, format and mount array.
local extra_opts=""
if [ $$count -lt 2 ]; then
# Force array creation even with one disk
extra_opts="--force"
fi

# if the device_path is "/dev/md/node-local-hdd-storage" then array
# name would be "node-local-hdd-storage"
array_name=$(basename "$${device_path}")
mdadm --create "$${device_path}" --homehost=any $$extra_opts --verbose --name="$${array_name}" --level=0 --raid-devices="$${count}" $${disks}
cat /proc/mdstat
if [ "$${setup_fs_on_raid}" = true ]; then
mkfs.ext4 "$${device_path}"
fi
}

os_disk="$(select_install_disk $${major_numbers})"

# Create a RAID 0 from extra disks to be used for persistent container storage.
# This will only be run if setup_raid variable is set to true.
setup_raid=${setup_raid}

if [ "$${setup_raid}" = true ]; then
if [ ${setup_raid} = true ]; then
create_data_raid "$${os_disk}" "$${major_numbers}"
else
if [ ${setup_raid_hdd} = true ]; then
create_disk_specific_data_raid "$${os_disk}" "$${major_numbers}" 1 /dev/md/node-local-hdd-storage true
fi
if [ ${setup_raid_ssd} = true ]; then
create_disk_specific_data_raid "$${os_disk}" "$${major_numbers}" 0 /dev/md/node-local-ssd-storage ${setup_raid_ssd_fs}
fi
fi

flatcar-install \
Expand Down
18 changes: 14 additions & 4 deletions packet/flatcar-linux/kubernetes/workers/cl/worker.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,20 @@ storage:
# Don't mount if no RAID is configured.
[ -z "$${raid_config}" ] && return 0

# Make mount persistent across reboots.
local devname=$(awk '{print $2}' /etc/mdadm.conf)
mount "$${devname}" /mnt/
echo "$${devname} /mnt ext4 defaults,nofail,discard 0 0" | tee -a /etc/fstab
cat /etc/mdadm.conf | while read line; do
# Make mount persistent across reboots.
local devname=$(echo "$${line}" | awk '{print $2}')

# Mount the RAID device only if there is a filesystem on the device
local fs=$(blkid "$${devname}")
surajssd marked this conversation as resolved.
Show resolved Hide resolved
[ -z "$${fs}" ] && continue

local mount_point=$(basename "$${devname}")
# Create the mount point before mounting
mkdir "/mnt/$${mount_point}"
mount "$${devname}" "/mnt/$${mount_point}"
echo "$${devname} /mnt ext4 defaults,nofail,discard 0 0" | tee -a /etc/fstab
pothos marked this conversation as resolved.
Show resolved Hide resolved
done
}

persist_data_raid
Expand Down
20 changes: 19 additions & 1 deletion packet/flatcar-linux/kubernetes/workers/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,29 @@ EOD
}

variable "setup_raid" {
description = "Attempt to create a RAID 0 from extra disks to be used for persistent container storage. Valid values: 'true', 'false'"
description = "Attempt to create a RAID 0 from extra disks to be used for persistent container storage. Valid values: \"true\", \"false\""
type = "string"
default = "false"
}

variable "setup_raid_hdd" {
description = "Attempt to create a RAID 0 from extra Hard Disk drives only, to be used for persistent container storage. Valid values: \"true\", \"false\""
type = "string"
default = "false"
}

variable "setup_raid_ssd" {
description = "Attempt to create a RAID 0 from extra Solid State Drives only, to be used for persistent container storage. Valid values: \"true\", \"false\""
type = "string"
default = "false"
}

variable "setup_raid_ssd_fs" {
description = "When set to \"true\" file system will be created on SSD RAID device and will be mounted on /mnt/node-local-ssd-storage. To use the raw device set it to \"false\". Valid values: \"true\", \"false\""
surajssd marked this conversation as resolved.
Show resolved Hide resolved
type = "string"
default = "true"
}

variable "reservation_ids" {
description = "Specify Packet hardware_reservation_id for instances. A map where the key format is 'worker-${index}' and the associated value is the reservation id string. Nodes not present in the map will use the value of reservation_ids_default var. Example: reservation_ids = { worker-0 = '<reservation_id>' }"
type = "map"
Expand Down
3 changes: 3 additions & 0 deletions packet/flatcar-linux/kubernetes/workers/workers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ data "template_file" "install" {
ssh_keys = "${jsonencode("${var.ssh_keys}")}"
postinstall_ignition = "${data.ct_config.ignitions.rendered}"
setup_raid = "${var.setup_raid}"
setup_raid_hdd = "${var.setup_raid_hdd}"
setup_raid_ssd = "${var.setup_raid_ssd}"
setup_raid_ssd_fs = "${var.setup_raid_ssd_fs}"
}
}

Expand Down