9
9
# the Business Source License, use of this software will be governed
10
10
# by the Apache License, Version 2.0.
11
11
12
- set -xeo pipefail
12
+ set -xeuo pipefail
13
13
14
- # Volume group name
15
14
VG_NAME=" instance-store-vg"
15
+ CLOUD_PROVIDER=" "
16
+
17
+ while [[ $# -gt 0 ]]; do
18
+ case $1 in
19
+ --cloud-provider|-c)
20
+ CLOUD_PROVIDER=" $2 "
21
+ shift 2
22
+ ;;
23
+ --vg-name|-v)
24
+ VG_NAME=" $2 "
25
+ shift 2
26
+ ;;
27
+ --help|-h)
28
+ echo " Usage: $0 [options]"
29
+ echo " Options:"
30
+ echo " --cloud-provider, -c PROVIDER Specify cloud provider (aws, gcp, azure, generic)"
31
+ echo " --vg-name, -v NAME Specify volume group name (default: instance-store-vg)"
32
+ echo " --help, -h Show this help message"
33
+ exit 0
34
+ ;;
35
+ * )
36
+ echo " Unknown option: $1 "
37
+ exit 1
38
+ ;;
39
+ esac
40
+ done
16
41
17
- # Function to detect cloud provider
18
42
detect_cloud_provider () {
19
- # Check for AWS
20
- if curl -s -m 5 http://169.254.169.254/latest/meta-data/ > /dev/null; then
43
+ # Only attempt detection if not explicitly provided
44
+ if [[ -n " $CLOUD_PROVIDER " ]]; then
45
+ echo " $CLOUD_PROVIDER "
46
+ return
47
+ fi
48
+
49
+ # Fall back to AWS detection if no provider is specified
50
+ if curl -s -m 5 --fail http://169.254.169.254/latest/meta-data/ > /dev/null 2>&1 ; then
21
51
echo " aws"
22
52
return
23
53
fi
24
54
25
- # Default to generic
55
+ # Default to generic if detection fails
26
56
echo " generic"
27
57
}
28
58
29
- # Cloud provider-specific device detection
59
+ find_aws_bottlerocket_devices () {
60
+ local nvme_devices=()
61
+ local BOTTLEROCKET_ROOT=" /.bottlerocket/rootfs"
62
+
63
+ mapfile -t SSD_NVME_DEVICE_LIST < <( lsblk --json --output-all | \
64
+ jq -r ' .blockdevices[] | select(.model // empty | contains("Amazon EC2 NVMe Instance Storage")) | .path' )
65
+
66
+ for device in " ${SSD_NVME_DEVICE_LIST[@]} " ; do
67
+ nvme_devices+=(" $BOTTLEROCKET_ROOT$device " )
68
+ done
69
+
70
+ echo " ${nvme_devices[@]} "
71
+ }
72
+
73
+ find_aws_standard_devices () {
74
+ lsblk --json --output-all | \
75
+ jq -r ' .blockdevices[] | select(.model // empty | contains("Amazon EC2 NVMe Instance Storage")) | .path'
76
+ }
77
+
78
+ find_aws_devices () {
79
+ local nvme_devices=()
80
+
81
+ # Check if we're running in Bottlerocket
82
+ if [[ -d " /.bottlerocket" ]]; then
83
+ # Use mapfile to properly handle the output
84
+ mapfile -t nvme_devices < <( find_aws_bottlerocket_devices)
85
+ else
86
+ # Use mapfile to properly handle the output
87
+ mapfile -t nvme_devices < <( find_aws_standard_devices)
88
+ fi
89
+
90
+ echo " ${nvme_devices[@]} "
91
+ }
92
+
93
+ find_generic_devices () {
94
+ lsblk --json --output-all | \
95
+ jq -r ' .blockdevices[] | select(.name | startswith("nvme")) | select(.mountpoint == null and (.children | length == 0)) | .path'
96
+ }
97
+
30
98
find_nvme_devices () {
31
99
local cloud=$1
32
100
local nvme_devices=()
33
101
34
102
case $cloud in
35
103
aws)
36
- # Handle both standard Linux and Bottlerocket paths
37
- if [ -d " /.bottlerocket" ]; then
38
- # Bottlerocket specific path
39
- BOTTLEROCKET_ROOT=" /.bottlerocket/rootfs"
40
- mapfile -t SSD_NVME_DEVICE_LIST < <( lsblk --json --output-all | jq -r ' .blockdevices[] | select(.model // empty | contains("Amazon EC2 NVMe Instance Storage")) | .path' )
41
- for device in " ${SSD_NVME_DEVICE_LIST[@]} " ; do
42
- nvme_devices+=(" $BOTTLEROCKET_ROOT$device " )
43
- done
44
- else
45
- # Standard EC2 instances
46
- mapfile -t nvme_devices < <( lsblk --json --output-all | jq -r ' .blockdevices[] | select(.model // empty | contains("Amazon EC2 NVMe Instance Storage")) | .path' )
47
- fi
104
+ # Use mapfile to properly handle the output
105
+ mapfile -t nvme_devices < <( find_aws_devices)
48
106
;;
49
- # Add more cloud providers here
107
+ # Add more cloud providers here as we support them
108
+ # gcp)
109
+ # mapfile -t nvme_devices < <(find_gcp_devices)
110
+ # ;;
111
+ # azure)
112
+ # mapfile -t nvme_devices < <(find_azure_devices)
113
+ # ;;
50
114
* )
51
- # Generic approach - find all NVMe devices that are not mounted and don't have children (partitions)
52
- mapfile -t nvme_devices < <( lsblk --json --output-all | jq -r ' .blockdevices[] | select(.name | startswith("nvme")) | select(.mountpoint == null and (.children | length == 0)) | .path ' )
115
+ # Generic approach for any other cloud or environment
116
+ mapfile -t nvme_devices < <( find_generic_devices )
53
117
;;
54
118
esac
55
119
@@ -60,7 +124,7 @@ find_nvme_devices() {
60
124
setup_lvm () {
61
125
local -a devices=(" $@ " )
62
126
63
- if [ ${# devices[@]} -eq 0 ]; then
127
+ if [[ ${# devices[@]} -eq 0 ] ]; then
64
128
echo " No suitable NVMe devices found"
65
129
exit 1
66
130
fi
@@ -89,27 +153,19 @@ setup_lvm() {
89
153
return 0
90
154
}
91
155
92
- # Main execution
93
156
echo " Starting NVMe disk configuration..."
94
157
95
- # Detect cloud provider
158
+ # Detect or use provided cloud provider
96
159
CLOUD_PROVIDER=$( detect_cloud_provider)
97
- echo " Detected cloud provider: $CLOUD_PROVIDER "
160
+ echo " Using cloud provider: $CLOUD_PROVIDER "
98
161
99
162
# Find NVMe devices
100
163
mapfile -t NVME_DEVICES < <( find_nvme_devices " $CLOUD_PROVIDER " )
101
164
102
165
# Setup LVM
103
166
if setup_lvm " ${NVME_DEVICES[@]} " ; then
104
167
echo " NVMe disk configuration completed successfully"
105
- # Call taint management script to remove the taint
106
- /usr/local/bin/manage-taints.sh remove
107
-
108
- # Keep the container running
109
- echo " Setup complete. Container will now stay running for monitoring purposes."
110
- while true ; do
111
- sleep 3600
112
- done
168
+ exit 0
113
169
else
114
170
echo " NVMe disk configuration failed"
115
171
exit 1
0 commit comments