Skip to content

Commit

Permalink
[PLAT-14563] Fixing disk mounting logic to use mount points defined i…
Browse files Browse the repository at this point in the history
…n the config

Summary: [PLAT-14563] Fixing disk mounting logic to use mount points defined in the config

Test Plan:
checked bash script,
will need to run on test node

Reviewers: svarshney

Reviewed By: svarshney

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D36351
  • Loading branch information
amannijhawan committed Jul 19, 2024
1 parent 225ddfe commit 9c9a059
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 68 deletions.
3 changes: 2 additions & 1 deletion managed/node-agent/resources/node-agent-provision.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ ynp:
use_system_level_systemd: false
ip_address: "127.0.0.1"
tmp_directory: /tmp
mount_points: /data # Comma separated values.

yba:
url: <url>
Expand All @@ -32,3 +31,5 @@ yba:
cores: cores
memory_size: size
volume_size: size
mount_points:
- /mnt/d1
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ def _generate_template(self):
context = self.config[key]

context["templatedir"] = os.path.join(os.path.dirname(module[1]), "templates")
logger.info(context)
module_instance = module[0]()
rendered_template = module_instance.render_templates(context)
if rendered_template is not None:
Expand Down
3 changes: 1 addition & 2 deletions managed/node-agent/resources/ynp/configs/config.j2
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ nproc_limit = 12000
vm_swappiness = 0
kernel_core_pattern = {{ ynp.yb_home_dir }}/cores/core_%%p_%%t_%%E
vm_max_map_count = 262144
mount_points = {{ ynp.mount_points }}
mount_points = {{ yba.instance_type.mount_points | join(' ') }}

[ConfigureOs.limits]
core = unlimited
Expand Down Expand Up @@ -71,5 +71,4 @@ ports = 7000 7100 9000 9100 18018 22 5433 9042 9070 9300 12000 13000
yb_user = yugabyte
yb_home_dir = {{ ynp.yb_home_dir }}
tmp_directory = {{ ynp.tmp_directory }}
mount_points = {{ ynp.mount_points }}

Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ else
add_result "kernel.core_pattern" "FAIL" "kernel.core_pattern is set to $kernel_core_pattern_value (expected: {{ kernel_core_pattern }})"
fi

threshold=49 #Gigabytes
mount_point_array={{ mount_points }}
# Verify each mount point
for mount_point in "${mount_point_array[@]}"; do
if [ -d "$mount_point" ]; then
if [ -w "$mount_point" ] && [ "$(stat -c %A "$mount_point" | cut -c 10)" == "w" ]; then
if [ -w "$mount_point" ] && [ $(( $(stat -c %a "$mount_point") % 10 & 2 )) -ne 0 ]; then
result="PASS"
message="Directory $mount_point exists and is world-writable."
echo "[PASS] $message"
Expand All @@ -107,6 +108,19 @@ for mount_point in "${mount_point_array[@]}"; do
echo "[FAIL] $message"
any_fail=1
fi

add_result "$mount_point Check" "$result" "$message"

# Get the available disk space in gigabytes.
free_space_gb=$(df -BG --output=avail "$MOUNT_POINT" | tail -n 1 | tr -d 'G ')
if [ "$free_space_gb" -gt "$threshold" ]; then
result="PASS"
message="Sufficient disk space available: ${AVAILABLE}G"
echo "[PASS] $message"
else
result="FAIL"
message="Insufficient disk space: ${AVAILABLE}G available, ${THRESHOLD}G required"
echo "[FAIL] $message"
any_fail=1
fi
add_result "$mount_point Free space check" "$result" "$message"
done
Original file line number Diff line number Diff line change
Expand Up @@ -68,66 +68,4 @@ sysctl -w vm.max_map_count={{ vm_max_map_count }}

echo "Kernel settings configured."


echo "Mounting volumes."
# Excluding the known mounts that we have to avoid.
{% set excluded_mounts = ["/", "boot", "efi"] %}

# Generate a unique backup filename for /etc/fstab
backup_file="/etc/fstab.bak.$(date +%s)"
cp /etc/fstab $backup_file
echo "Backup of /etc/fstab created at $backup_file."

# Get list of available volumes excluding the root and specified excluded mounts
volumes=$(lsblk -lnpo NAME,MOUNTPOINT | awk '$2 == "" {print $1}' | grep -vE 'NAME|MOUNTPOINT')

# Prepare and mount each volume
index=1
for volume in $volumes; do
if [[ $volume =~ /dev/nvme[0-9]n[0-9]p[0-9]+ ]]; then
echo "Skipping volume $volume"
continue
fi
mount_point="/mnt/d${index}"

mkdir -p ${mount_point}

if mount | grep -qE "^${volume}|^${volume}[0-9]"; then
echo "${volume} or one of its partitions is currently mounted. Skipping..."
continue
fi

# Check if filesystem already exists
if ! blkid ${volume} | grep -q "TYPE=\"xfs\""; then
mkfs -t xfs ${volume}
echo "Filesystem created on ${volume}."
else
echo "Filesystem already exists on ${volume}."
fi

# Add entry to /etc/fstab if it doesn't already exist
if ! grep -q "^${volume}" /etc/fstab; then
echo "${volume} ${mount_point} xfs noatime 0 0" | tee -a /etc/fstab
else
echo "Entry for ${volume} already exists in /etc/fstab."
fi

# Mount the volume if it's not already mounted
if ! mountpoint -q ${mount_point}; then
mount ${mount_point} || fail "Failed to mount ${volume} at ${mount_point}."
echo "Mounted ${volume} at ${mount_point}."
else
echo "${mount_point} is already mounted."
fi

# Set ownership and permissions
chown yugabyte:yugabyte ${mount_point} || fail "Failed to set ownership for ${mount_point}."
chmod 755 ${mount_point} || fail "Failed to set permissions for ${mount_point}."
echo "Set ownership and permissions for ${mount_point}."

index=$((index + 1))
done

echo "Volume mounting process completed."

echo "OS Configuration applied successfully."

0 comments on commit 9c9a059

Please sign in to comment.