Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add auto install for nvme-cli #510

Merged
merged 4 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
93 changes: 89 additions & 4 deletions config/samples/raid-disks/eks-daemonset-raid-disks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,97 @@ spec:
set -o errexit
set -o nounset
set -o pipefail
declare -A supported_oss
kevinliu24 marked this conversation as resolved.
Show resolved Hide resolved
supported_oss["amzn"]="2,2023"
supported_oss["centos"]="7+"
supported_oss["debian"]="10+"
supported_oss["rhel"]="7+"
supported_oss["ubuntu"]="20+"

function install_nvme() {
id=$(cat /etc/*release* | grep -e ^ID= | grep -v \" || true)
if [[ -z $id ]]; then
#for all oss except debian
id=$(cat /etc/*release* | grep -e ^ID=)
fi

os=$(echo "$id" | cut -d = -f 2 | tr -d \")
version=$(cat /etc/*release* | grep "VERSION_ID" | cut -d = -f 2 | tr -d \")
supported_versions=${supported_oss[$os]}

#check if os is supported
if [[ -z $supported_versions ]]; then
echo "Unable to install nvem-cli. Unsupported OS $os. Supported OSs: ${!supported_oss[*]}"
return 1
fi

#check if version is supported
readarray -t supported_versions_arr < <(echo "$supported_versions" | tr ',' '\n')
supported=0
for supported_ver in "${supported_versions_arr[@]}"; do
if [[ $supported_ver == *"+" ]]; then
ver_num=$(echo "$supported_ver" | tr -d +)
if awk "BEGIN {exit !($version >= $ver_num)}"; then
supported=1
break
fi
elif [[ $supported_ver =~ ^[0-9]+(\.[0-9]+)?$ ]]; then
if awk "BEGIN {exit !($version == $supported_ver)}"; then
supported=1
break
fi
else
echo "Invalid supported version/syntax $supported_ver found. Ignoring"
fi
done

if [[ $supported = 0 ]]; then
echo "Unsupported version $version for OS $os. Supported versions ${supported_versions_arr[*]}"
return 2
fi

case $os in
"amzn")
echo "$os $version detected. Installing with yum"
sudo yum install -y nvme-cli
;;
"centos"|"rhel")
if awk "BEGIN {exit !($version < 8)}"; then
echo "$os $version detected. Installing with yum"
sudo yum install -y nvme-cli
else
echo "$os $version detected. Installing with dnf"
sudo dnf install -y nvme-cli
fi
;;
"debian"|"ubuntu")
echo "$os $version detected. Installing with apt-get"
sudo apt-get update
sudo apt-get install -y nvme-cli
;;
esac
}

#main script
if ! sudo which nvme; then
echo "no nvme-cli detected. Installing nvme-cli"
install_nvme
echo "nvme-cli installed successfully"
else
echo "nvme-cli is already installed. Skipping installation"
fi

nvme_drives=$(nvme list | grep "Amazon EC2 NVMe Instance Storage" | cut -d " " -f 1 | tr -d " " || true)

if [ -n "$nvme_drives" ]; then
readarray -t nvme_drives <<< "$nvme_drives"
else
nvme_drives=()
fi

nvme_drives=$(nvme list | grep "Amazon EC2 NVMe Instance Storage" | cut -d " " -f 1 || true)
readarray -t nvme_drives <<< "$nvme_drives"
num_drives=${#nvme_drives[@]}

if [ "${#nvme_drives[@]}" -eq 0 ]; then
if [ "$num_drives" -eq 0 ]; then
echo "No NVMe instance storage found."
exit 0
fi
Expand All @@ -44,7 +129,7 @@ spec:
echo "Setting RAID array with Local SSDs on device ${device}"
if [ ! -e "$device" ]; then
device="/dev/md/0"
echo "y" | mdadm --create "${device}" --level=0 --force --raid-devices=${#nvme_drives[@]} "${nvme_drives[@]}"
echo "y" | mdadm --create "${device}" --level=0 --force --raid-devices=$num_drives "${nvme_drives[@]}"
fi

if ! tune2fs -l "${device}" ; then
Expand Down
80 changes: 80 additions & 0 deletions config/samples/raid-disks/gke-daemonset-raid-disks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,93 @@ spec:
set -o errexit
set -o nounset
set -o pipefail
declare -A supported_oss
supported_oss["amzn"]="2,2023"
supported_oss["centos"]="7+"
supported_oss["debian"]="10+"
supported_oss["rhel"]="7+"
supported_oss["ubuntu"]="20+"

function install_nvme() {
id=$(cat /etc/*release* | grep -e ^ID= | grep -v \" || true)
if [[ -z $id ]]; then
#for all oss except debian
id=$(cat /etc/*release* | grep -e ^ID=)
fi

os=$(echo "$id" | cut -d = -f 2 | tr -d \")
version=$(cat /etc/*release* | grep "VERSION_ID" | cut -d = -f 2 | tr -d \")
supported_versions=${supported_oss[$os]}

#check if os is supported
if [[ -z $supported_versions ]]; then
echo "Unable to install nvem-cli. Unsupported OS $os. Supported OSs: ${!supported_oss[*]}"
return 1
fi

#check if version is supported
readarray -t supported_versions_arr < <(echo "$supported_versions" | tr ',' '\n')
supported=0
for supported_ver in "${supported_versions_arr[@]}"; do
if [[ $supported_ver == *"+" ]]; then
ver_num=$(echo "$supported_ver" | tr -d +)
if awk "BEGIN {exit !($version >= $ver_num)}"; then
supported=1
break
fi
elif [[ $supported_ver =~ ^[0-9]+(\.[0-9]+)?$ ]]; then
if awk "BEGIN {exit !($version == $supported_ver)}"; then
supported=1
break
fi
else
echo "Invalid supported version/syntax $supported_ver found. Ignoring"
fi
done

if [[ $supported = 0 ]]; then
echo "Unsupported version $version for OS $os. Supported versions ${supported_versions_arr[*]}"
return 2
fi

case $os in
"amzn")
echo "$os $version detected. Installing with yum"
sudo yum install -y nvme-cli
;;
"centos"|"rhel")
if awk "BEGIN {exit !($version < 8)}"; then
echo "$os $version detected. Installing with yum"
sudo yum install -y nvme-cli
else
echo "$os $version detected. Installing with dnf"
sudo dnf install -y nvme-cli
fi
;;
"debian"|"ubuntu")
echo "$os $version detected. Installing with apt-get"
sudo apt-get update
sudo apt-get install -y nvme-cli
;;
esac
}

#main script
if ! sudo which nvme; then
echo "no nvme-cli detected. Installing nvme-cli"
install_nvme
echo "nvme-cli installed successfully"
else
echo "nvme-cli is already installed. Skipping installation"
fi

devices=()
for ssd in /dev/disk/by-id/google-local-nvme-ssd*; do
if [ -e "${ssd}" ]; then
devices+=("${ssd}")
fi
done

if [ "${#devices[@]}" -eq 0 ]; then
echo "No Local NVMe SSD disks found."
exit 0
Expand Down