Skip to content

Commit

Permalink
shfmt and .editorconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
rustydb committed Oct 1, 2024
1 parent ec053c0 commit 313d19c
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 103 deletions.
24 changes: 24 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
insert_final_newline = true
trim_trailing_spaces = true
trim_trailing_whitespace = true

# 4 space indentation
[*.{py,go}]
indent_size = 4

# 2 space indentation
[*.{json,yml,yaml}]
indent_size = 2

[*.sh]
indent_size = 2

[*.{adoc,md}]
trim_trailing_whitespace = false
indent_size = 4
46 changes: 23 additions & 23 deletions 93metaldmk8s/metal-dmk8s-disks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,34 @@ scan_ephemeral
# Make the ephemeral disk if it didn't exist.
if [ ! -f "$EPHEMERAL_DONE_FILE" ]; then

# Offset the search by the number of disks used up by the main metal dracut module.
ephemeral=''
disks="$(metal_scand)"
IFS=" " read -r -a pool <<< "$disks"
for disk in "${pool[@]}"; do
if [ -n "${ephemeral}" ]; then
break
fi
ephemeral=$(metal_resolve_disk "$disk" "$METAL_DISK_LARGE")
done

# If no disks were found, die.
# When rd.luks is disabled, this hook-script expects to find a disk. Die if one isn't found.
if [ -z "${ephemeral}" ]; then
metal_dmk8s_die "No disks were found for ephemeral use."
exit 1
else
echo >&2 "Found the following disk for ephemeral storage: $ephemeral"
# Offset the search by the number of disks used up by the main metal dracut module.
ephemeral=''
disks="$(metal_scand)"
IFS=" " read -r -a pool <<< "$disks"
for disk in "${pool[@]}"; do
if [ -n "${ephemeral}" ]; then
break
fi
ephemeral=$(metal_resolve_disk "$disk" "$METAL_DISK_LARGE")
done

# If no disks were found, die.
# When rd.luks is disabled, this hook-script expects to find a disk. Die if one isn't found.
if [ -z "${ephemeral}" ]; then
metal_dmk8s_die "No disks were found for ephemeral use."
exit 1
else
echo >&2 "Found the following disk for ephemeral storage: $ephemeral"
fi

# Make the ephemeral disk.
make_ephemeral "$ephemeral"
# Make the ephemeral disk.
make_ephemeral "$ephemeral"
else
echo 0 > "$EPHEMERAL_DONE_FILE"
echo 0 > "$EPHEMERAL_DONE_FILE"
fi

# If our disk was created, satisfy the wait_for_dev hook, otherwise keep waiting.
if [ -f "$EPHEMERAL_DONE_FILE" ]; then
ln -s null /dev/metal-k8s
exit 0
ln -s null /dev/metal-k8s
exit 0
fi
20 changes: 10 additions & 10 deletions 93metaldmk8s/metal-dmk8s-genrules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@

command -v getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh

case "$(getarg root)" in
kdump)
# do not do anything for kdump
exit 0
;;
case "$(getarg root)" in
kdump)
# do not do anything for kdump
exit 0
;;
esac

command -v wait_for_dev > /dev/null 2>&1 || . /lib/dracut-lib.sh

# Only run when luks is disabled and a deployment server is present.
if ! getargbool 0 rd.luks -d -n rd_NO_LUKS; then
metal_server=$(getarg metal.server=)
if [ -n "${metal_server:-}" ]; then
wait_for_dev -n /dev/metal-k8s
/sbin/initqueue --settled --onetime --unique /sbin/metal-dmk8s-disks
fi
metal_server=$(getarg metal.server=)
if [ -n "${metal_server:-}" ]; then
wait_for_dev -n /dev/metal-k8s
/sbin/initqueue --settled --onetime --unique /sbin/metal-dmk8s-disks
fi
fi
109 changes: 54 additions & 55 deletions 93metaldmk8s/metal-dmk8s-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,28 @@ command -v info > /dev/null 2>&1 || . /lib/dracut-lib.sh
# Creates a "done" file if the ephemeral disk and its partitions exist.
#
scan_ephemeral() {
local conrun_scheme=${METAL_CONRUN%=*}
local conrun_authority=${METAL_CONRUN#*=}
local conlib_scheme=${METAL_CONLIB%=*}
local conlib_authority=${METAL_CONLIB#*=}
local k8slet_scheme=${METAL_K8SLET%=*}
local k8slet_authority=${METAL_K8SLET#*=}
local disks=()
disks+=( "/dev/disk/by-${conrun_scheme,,}/${conrun_authority^^}" )
disks+=( "/dev/disk/by-${conlib_scheme,,}/${conlib_authority^^}" )
disks+=( "/dev/disk/by-${k8slet_scheme,,}/${k8slet_authority^^}" )
for disk in "${disks[@]}"; do
if blkid -s UUID -o value "$disk" >/dev/null; then
local conrun_scheme=${METAL_CONRUN%=*}
local conrun_authority=${METAL_CONRUN#*=}
local conlib_scheme=${METAL_CONLIB%=*}
local conlib_authority=${METAL_CONLIB#*=}
local k8slet_scheme=${METAL_K8SLET%=*}
local k8slet_authority=${METAL_K8SLET#*=}
local disks=()
disks+=("/dev/disk/by-${conrun_scheme,,}/${conrun_authority^^}")
disks+=("/dev/disk/by-${conlib_scheme,,}/${conlib_authority^^}")
disks+=("/dev/disk/by-${k8slet_scheme,,}/${k8slet_authority^^}")
for disk in "${disks[@]}"; do
if blkid -s UUID -o value "$disk" > /dev/null; then

# echo 0 to signal that nothing was done; the disks exist
echo 0 > $EPHEMERAL_DONE_FILE
else
# A disk doesn't exist yet.
# Remove the file if it was created and then exit the loop to start making the disks.
rm -f $EPHEMERAL_DONE_FILE
break
fi
done
# echo 0 to signal that nothing was done; the disks exist
echo 0 > $EPHEMERAL_DONE_FILE
else
# A disk doesn't exist yet.
# Remove the file if it was created and then exit the loop to start making the disks.
rm -f $EPHEMERAL_DONE_FILE
break
fi
done
}

##############################################################################
Expand All @@ -74,52 +74,51 @@ scan_ephemeral() {
# paths.
make_ephemeral() {

local target="${1:-}" && shift
[ -z "$target" ] && info 'No ephemeral disk.' && return 0
command -v _trip_udev > /dev/null 2>&1 || . /lib/metal-lib.sh
local target="${1:-}" && shift
[ -z "$target" ] && info 'No ephemeral disk.' && return 0
command -v _trip_udev > /dev/null 2>&1 || . /lib/metal-lib.sh

parted --wipesignatures -m --align=opt --ignore-busy -s "/dev/${target}" -- mktable gpt \
mkpart extended xfs 2048s "${METAL_SIZE_CONRUN:-75}GB" \
mkpart extended xfs "${METAL_SIZE_CONRUN:-75}GB" "${METAL_SIZE_CONLIB:-25}%" \
mkpart extended xfs "${METAL_SIZE_CONLIB:-25}%" "$((${METAL_SIZE_CONLIB:-25} + ${METAL_SIZE_K8SLET:-25}))%"
parted --wipesignatures -m --align=opt --ignore-busy -s "/dev/${target}" -- mktable gpt \
mkpart extended xfs 2048s "${METAL_SIZE_CONRUN:-75}GB" \
mkpart extended xfs "${METAL_SIZE_CONRUN:-75}GB" "${METAL_SIZE_CONLIB:-25}%" \
mkpart extended xfs "${METAL_SIZE_CONLIB:-25}%" "$((${METAL_SIZE_CONLIB:-25} + ${METAL_SIZE_K8SLET:-25}))%"

# NVME partitions have a "p" to delimit the partition number.
if [[ "$target" =~ "nvme" ]]; then
nvme=1
fi
# NVME partitions have a "p" to delimit the partition number.
if [[ $target =~ "nvme" ]]; then
nvme=1
fi

partprobe "/dev/${target}"
_trip_udev
mkfs.xfs -f -L "${METAL_CONRUN#*=}" "/dev/${target}${nvme:+p}1" || metal_dmk8s_die "Failed to create ${METAL_CONRUN#*=}"
partprobe "/dev/${target}"
_trip_udev
mkfs.xfs -f -L "${METAL_CONLIB#*=}" "/dev/${target}${nvme:+p}2" || metal_dmk8s_die "Failed to create ${METAL_CONLIB#*=}"
partprobe "/dev/${target}"
_trip_udev
mkfs.xfs -f -L "${METAL_K8SLET#*=}" "/dev/${target}${nvme:+p}3" || metal_dmk8s_die "Failed to create ${METAL_K8SLET#*=}"
partprobe "/dev/${target}"
_trip_udev
mkfs.xfs -f -L "${METAL_CONRUN#*=}" "/dev/${target}${nvme:+p}1" || metal_dmk8s_die "Failed to create ${METAL_CONRUN#*=}"
partprobe "/dev/${target}"
_trip_udev
mkfs.xfs -f -L "${METAL_CONLIB#*=}" "/dev/${target}${nvme:+p}2" || metal_dmk8s_die "Failed to create ${METAL_CONLIB#*=}"
partprobe "/dev/${target}"
_trip_udev
mkfs.xfs -f -L "${METAL_K8SLET#*=}" "/dev/${target}${nvme:+p}3" || metal_dmk8s_die "Failed to create ${METAL_K8SLET#*=}"

mkdir -p /run/containerd /var/lib/kubelet /var/lib/containerd
{
printf '% -18s\t% -18s\t%s\t%s 0 0\n' "${METAL_CONRUN}" /run/containerd xfs "$METAL_FSOPTS_XFS"
printf '% -18s\t% -18s\t%s\t%s 0 0\n' "${METAL_CONLIB}" /var/lib/containerd xfs "$METAL_FSOPTS_XFS"
printf '% -18s\t% -18s\t%s\t%s 0 0\n' "${METAL_K8SLET}" /var/lib/kubelet xfs "$METAL_FSOPTS_XFS"
} >> "$METAL_FSTAB"
mkdir -p /run/containerd /var/lib/kubelet /var/lib/containerd
{
printf '% -18s\t% -18s\t%s\t%s 0 0\n' "${METAL_CONRUN}" /run/containerd xfs "$METAL_FSOPTS_XFS"
printf '% -18s\t% -18s\t%s\t%s 0 0\n' "${METAL_CONLIB}" /var/lib/containerd xfs "$METAL_FSOPTS_XFS"
printf '% -18s\t% -18s\t%s\t%s 0 0\n' "${METAL_K8SLET}" /var/lib/kubelet xfs "$METAL_FSOPTS_XFS"
} >> "$METAL_FSTAB"

# Mount filesystems. Failure to mount here is fatal.
mount -a -v -T "$METAL_FSTAB"
# Mount filesystems. Failure to mount here is fatal.
mount -a -v -T "$METAL_FSTAB"

# echo 1 to signal that this module create a disk.
echo 1 > $EPHEMERAL_DONE_FILE && return
# echo 1 to signal that this module create a disk.
echo 1 > $EPHEMERAL_DONE_FILE && return
}


##############################################################################
# function: metal_dmk8s_die
#
# Calls metal_die, printing this module's URL to its source code first.
#
metal_dmk8s_die() {
command -v metal_die > /dev/null 2>&1 || . /lib/metal-lib.sh
echo >&2 "GitHub/Docs: https://github.com/Cray-HPE/dracut-metal-dmk8s"
metal_die "$@"
command -v metal_die > /dev/null 2>&1 || . /lib/metal-lib.sh
echo >&2 "GitHub/Docs: https://github.com/Cray-HPE/dracut-metal-dmk8s"
metal_die "$@"
}
30 changes: 15 additions & 15 deletions 93metaldmk8s/module-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,32 @@

# called by dracut
check() {
require_binaries blkid lsblk mkfs.xfs mount parted partprobe || return 1
return
require_binaries blkid lsblk mkfs.xfs mount parted partprobe || return 1
return
}

# called by dracut
depends() {
# Needed so overlayFS is available, that's where the new fstab is dropped.
echo metalmdsquash
return 0
# Needed so overlayFS is available, that's where the new fstab is dropped.
echo metalmdsquash
return 0
}

installkernel() {
instmods hostonly=''
instmods hostonly=''
}

# called by dracut
install() {
# the rest is needed by metal-squashfs-url-dract.
# rmdir is needed by dmsquash-live/livenet
inst_multiple chmod lsblk mkfs.xfs parted partprobe sort tail
# the rest is needed by metal-squashfs-url-dract.
# rmdir is needed by dmsquash-live/livenet
inst_multiple chmod lsblk mkfs.xfs parted partprobe sort tail

# shellcheck disable=SC2154
inst_simple "$moddir/metal-dmk8s-lib.sh" "/lib/metal-dmk8s-lib.sh"
inst_script "$moddir/metal-dmk8s-disks.sh" /sbin/metal-dmk8s-disks
# shellcheck disable=SC2154
inst_simple "$moddir/metal-dmk8s-lib.sh" "/lib/metal-dmk8s-lib.sh"
inst_script "$moddir/metal-dmk8s-disks.sh" /sbin/metal-dmk8s-disks

inst_hook cmdline 10 "$moddir/parse-metal-dmk8s.sh"
inst_hook pre-udev 10 "$moddir/metal-dmk8s-genrules.sh"
dracut_need_initqueue
inst_hook cmdline 10 "$moddir/parse-metal-dmk8s.sh"
inst_hook pre-udev 10 "$moddir/metal-dmk8s-genrules.sh"
dracut_need_initqueue
}

0 comments on commit 313d19c

Please sign in to comment.