From a4e92160688710654ccc1baa85ec4060c3a82c2e Mon Sep 17 00:00:00 2001 From: kevinliu24 Date: Wed, 26 Jun 2024 08:07:36 +0800 Subject: [PATCH 1/4] add auto install for nvme-cli --- .../raid-disks/eks-daemonset-raid-disks.yaml | 95 ++++++++++++++++++- .../raid-disks/gke-daemonset-raid-disks.yaml | 80 ++++++++++++++++ 2 files changed, 170 insertions(+), 5 deletions(-) diff --git a/config/samples/raid-disks/eks-daemonset-raid-disks.yaml b/config/samples/raid-disks/eks-daemonset-raid-disks.yaml index 1bb685cc..732836ae 100644 --- a/config/samples/raid-disks/eks-daemonset-raid-disks.yaml +++ b/config/samples/raid-disks/eks-daemonset-raid-disks.yaml @@ -29,12 +29,97 @@ 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 + + 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 @@ -43,8 +128,8 @@ spec: device=${seen_arrays[0]} 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[@]}" + device="/dev/md0" + echo "y" | mdadm --create "${device}" --level=0 --force --raid-devices=$num_drives "${nvme_drives[@]}" fi if ! tune2fs -l "${device}" ; then diff --git a/config/samples/raid-disks/gke-daemonset-raid-disks.yaml b/config/samples/raid-disks/gke-daemonset-raid-disks.yaml index 0c430110..2a3ca880 100644 --- a/config/samples/raid-disks/gke-daemonset-raid-disks.yaml +++ b/config/samples/raid-disks/gke-daemonset-raid-disks.yaml @@ -28,6 +28,85 @@ 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 @@ -35,6 +114,7 @@ spec: devices+=("${ssd}") fi done + if [ "${#devices[@]}" -eq 0 ]; then echo "No Local NVMe SSD disks found." exit 0 From caeb78dbd972d54068552c58ffce7cf1028cf76a Mon Sep 17 00:00:00 2001 From: kevinliu24 Date: Wed, 26 Jun 2024 08:27:39 +0800 Subject: [PATCH 2/4] revert unnecessary modification --- config/samples/raid-disks/eks-daemonset-raid-disks.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/samples/raid-disks/eks-daemonset-raid-disks.yaml b/config/samples/raid-disks/eks-daemonset-raid-disks.yaml index 732836ae..c9b67049 100644 --- a/config/samples/raid-disks/eks-daemonset-raid-disks.yaml +++ b/config/samples/raid-disks/eks-daemonset-raid-disks.yaml @@ -128,7 +128,7 @@ spec: device=${seen_arrays[0]} echo "Setting RAID array with Local SSDs on device ${device}" if [ ! -e "$device" ]; then - device="/dev/md0" + device="/dev/md/0" echo "y" | mdadm --create "${device}" --level=0 --force --raid-devices=$num_drives "${nvme_drives[@]}" fi From a5bd637503d7def94793cb3ff0e05957ae98995a Mon Sep 17 00:00:00 2001 From: kevinliu24 Date: Wed, 26 Jun 2024 14:56:42 +0800 Subject: [PATCH 3/4] remove unnecessary installation on gke --- .../raid-disks/gke-daemonset-raid-disks.yaml | 79 ------------------- 1 file changed, 79 deletions(-) diff --git a/config/samples/raid-disks/gke-daemonset-raid-disks.yaml b/config/samples/raid-disks/gke-daemonset-raid-disks.yaml index 2a3ca880..504c68de 100644 --- a/config/samples/raid-disks/gke-daemonset-raid-disks.yaml +++ b/config/samples/raid-disks/gke-daemonset-raid-disks.yaml @@ -28,85 +28,6 @@ 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 From 94f7aba176432476dcb4a7437af3de62f67093cb Mon Sep 17 00:00:00 2001 From: kevinliu24 Date: Wed, 26 Jun 2024 14:59:02 +0800 Subject: [PATCH 4/4] remove unneeded space --- config/samples/raid-disks/gke-daemonset-raid-disks.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/config/samples/raid-disks/gke-daemonset-raid-disks.yaml b/config/samples/raid-disks/gke-daemonset-raid-disks.yaml index 504c68de..0c430110 100644 --- a/config/samples/raid-disks/gke-daemonset-raid-disks.yaml +++ b/config/samples/raid-disks/gke-daemonset-raid-disks.yaml @@ -35,7 +35,6 @@ spec: devices+=("${ssd}") fi done - if [ "${#devices[@]}" -eq 0 ]; then echo "No Local NVMe SSD disks found." exit 0