Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Support nvme devices #54

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
25 changes: 21 additions & 4 deletions bin/create-ebs-volume
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,11 @@ function get_next_logical_device() {
for letter in ${alphabet[@]}; do
# use /dev/xvdb* device names to avoid contention for /dev/sd* and /dev/xvda names
# only supported by HVM instances
if [ ! -b "/dev/xvdb${letter}" ]; then
if [[ $created_volumes =~ .*/dev/xvdb${letter}.* ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the .* at the start of the pattern needed, and can the .* at the end of the pattern be scoped to a subset - e.g. [0-9]?

Copy link
Author

@tetron tetron Oct 31, 2022

Choose a reason for hiding this comment

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

The string in created_volumes comes from $(aws ec2 describe-volumes) which is JSON output, to avoid having to actually parse it (and pull in jq or python or something) it just does the simpler match to see if "/dev/xvdb${letter}" shows up anywhere in the describe-volumes output, which is good enough to guess that we probably shouldn't try to use it.

Copy link
Author

Choose a reason for hiding this comment

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

So the leading and trailing .* are there to consume all the other stuff we don't care about.

continue
fi
echo "/dev/xvdb${letter}"
break
fi
done
}

Expand Down Expand Up @@ -339,13 +340,25 @@ function create_and_attach_volume() {
--region $region \
--volume-id $volume_id \
> /dev/null

error "could not attach volume to instance"
fi
set -e

logthis "waiting for volume $volume_id on filesystem"
while true; do
# Check for nvme device
# AWS returns e.g. vol-00338247831716a7b4, the kernel changes that to vol00338247831716a7b
valid_volume_id=`echo $volume_id |sed -e 's/[^a-zA-Z0-9]//'`
# example lsblk output:
# nvme4n1 259:7 0 150G 0 disk vol00338247831716a7b
if LSBLK=`lsblk -o NAME,SERIAL |grep $valid_volume_id`; then
nvme_device=/dev/`echo $LSBLK|cut -f1 -d' '`
logthis "volume $volume_id on filesystem as $nvme_device (aws device $device)"
break
fi

# Check for xvdb device
if [ -e "$device" ]; then
logthis "volume $volume_id on filesystem as $device"
break
Expand All @@ -361,7 +374,11 @@ function create_and_attach_volume() {
> /dev/null
logthis "volume $volume_id DeleteOnTermination ENABLED"

echo $device
if [ -n "$nvme_device" ] ; then
echo "$nvme_device"
else
echo "$device"
fi
}

create_and_attach_volume
2 changes: 1 addition & 1 deletion bin/ebs-autoscale
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
# Copyright Amazon.com, Inc. or its affiliates.
#
# Redistribution and use in source and binary forms, with or without
Expand Down
1 change: 1 addition & 0 deletions config/ebs-autoscale.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"mountpoint": "%%MOUNTPOINT%%",
"filesystem": "%%FILESYSTEM%%",
"imdsv2": "%%IMDSV2%%",
"lvm": {
"volume_group": "autoscale_vg",
"logical_volume": "autoscale_lv"
Expand Down
31 changes: 16 additions & 15 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,21 @@ done

eval set -- "$PARAMS"

# install default config
cat ${BASEDIR}/config/ebs-autoscale.json | \
sed -e "s#%%MOUNTPOINT%%#${MOUNTPOINT}#" | \
sed -e "s#%%VOLUMETYPE%%#${VOLUMETYPE}#" | \
sed -e "s#%%VOLUMEIOPS%%#${VOLUMEIOPS}#" | \
sed -e "s#%%VOLUMETHOUGHPUT%%#${VOLUMETHOUGHPUT}#" | \
sed -e "s#%%FILESYSTEM%%#${FILE_SYSTEM}#" | \
sed -e "s#%%IMDSV2%%#${IMDSV2}#" | \
sed -e "s#%%MINEBSVOLUMESIZE%%#${MIN_EBS_VOLUME_SIZE}#" | \
sed -e "s#%%MAXEBSVOLUMESIZE%%#${MAX_EBS_VOLUME_SIZE}#" | \
sed -e "s#%%MAXLOGICALVOLUMESIZE%%#${MAX_LOGICAL_VOLUME_SIZE}#" | \
sed -e "s#%%MAXATTACHEDVOLUMES%%#${MAX_ATTACHED_VOLUMES}#" | \
sed -e "s#%%INITIALUTILIZATIONTHRESHOLD%%#${INITIAL_UTILIZATION_THRESHOLD}#" \
> /etc/ebs-autoscale.json

initialize

# for backwards compatibility evaluate positional parameters like previous 2.0.x and 2.1.x releases
Expand All @@ -201,7 +216,7 @@ fi
# make executables available on standard PATH
mkdir -p /usr/local/amazon-ebs-autoscale/{bin,shared}
cp ${BASEDIR}/bin/{create-ebs-volume,ebs-autoscale} /usr/local/amazon-ebs-autoscale/bin
chmod +x /usr/local/amazon-ebs-autoscale/bin/*
chmod 755 /usr/local/amazon-ebs-autoscale/bin/*
ln -sf /usr/local/amazon-ebs-autoscale/bin/* /usr/local/bin/
ln -sf /usr/local/amazon-ebs-autoscale/bin/* /usr/bin/

Expand All @@ -214,20 +229,6 @@ cp ${BASEDIR}/shared/utils.sh /usr/local/amazon-ebs-autoscale/shared
# install the logrotate config
cp ${BASEDIR}/config/ebs-autoscale.logrotate /etc/logrotate.d/ebs-autoscale

# install default config
cat ${BASEDIR}/config/ebs-autoscale.json | \
sed -e "s#%%MOUNTPOINT%%#${MOUNTPOINT}#" | \
sed -e "s#%%VOLUMETYPE%%#${VOLUMETYPE}#" | \
sed -e "s#%%VOLUMEIOPS%%#${VOLUMEIOPS}#" | \
sed -e "s#%%VOLUMETHOUGHPUT%%#${VOLUMETHOUGHPUT}#" | \
sed -e "s#%%FILESYSTEM%%#${FILE_SYSTEM}#" | \
sed -e "s#%%MINEBSVOLUMESIZE%%#${MIN_EBS_VOLUME_SIZE}#" | \
sed -e "s#%%MAXEBSVOLUMESIZE%%#${MAX_EBS_VOLUME_SIZE}#" | \
sed -e "s#%%MAXLOGICALVOLUMESIZE%%#${MAX_LOGICAL_VOLUME_SIZE}#" | \
sed -e "s#%%MAXATTACHEDVOLUMES%%#${MAX_ATTACHED_VOLUMES}#" | \
sed -e "s#%%INITIALUTILIZATIONTHRESHOLD%%#${INITIAL_UTILIZATION_THRESHOLD}#" \
> /etc/ebs-autoscale.json

## Create filesystem
if [ -e $MOUNTPOINT ] && ! [ -d $MOUNTPOINT ]; then
echo "ERROR: $MOUNTPOINT exists but is not a directory."
Expand Down
6 changes: 3 additions & 3 deletions shared/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ function get_metadata() {
local key=$1
local metadata_ip='169.254.169.254'

if [ ! -z "$IMDSV2" ]; then
if [ ! -z "$(get_config_value .imdsv2)" ]; then
local token=$(curl -s -X PUT "http://$metadata_ip/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 60")
local token_wrapper='-H "X-aws-ec2-metadata-token: $token"'
fi

echo `curl -s $token_wrapper http://$metadata_ip/latest/meta-data/$key`
eval "curl -s $token_wrapper http://$metadata_ip/latest/meta-data/$key"
}

function initialize() {
export EBS_AUTOSCALE_CONFIG_FILE=/etc/ebs-autoscale.json
export AWS_AZ=$(get_metadata placement/availability-zone)
export AWS_REGION=$(echo ${AWS_AZ} | sed -e 's/[a-z]$//')
export INSTANCE_ID=$(get_metadata instance-id)
export EBS_AUTOSCALE_CONFIG_FILE=/etc/ebs-autoscale.json
}

function detect_init_system() {
Expand Down