Skip to content

Commit 2ce74e6

Browse files
committed
root-hints: improve installation to disk
In case no root-hints.yaml is provided we fall back to select the first available smallest device
1 parent 658bd7e commit 2ce74e6

File tree

7 files changed

+56
-20
lines changed

7 files changed

+56
-20
lines changed

.github/actions/test/integration/build/action.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,21 @@ runs:
9999
chmod 600 /opt/ssh_host_ed25519_key
100100
SSH_KEY=$(cat /opt/ssh_host_ed25519_key.pub)
101101
echo "SSH_KEY=$SSH_KEY" >> $GITHUB_ENV
102-
sed -i "s|SSH_KEY_GOES_HERE|$SSH_KEY|g" ./.github/actions/test/integration/build/dev-user-butane.yaml
102+
cp ./.github/actions/test/integration/build/dev-user-butane.yaml ./.github/actions/test/integration/build/dev-user-butane-hv1.yaml
103+
yq '.storage.files += load("./.github/actions/test/integration/build/root-hints.yaml")' ./.github/actions/test/integration/build/dev-user-butane.yaml > ./.github/actions/test/integration/build/dev-user-butane-hv2.yaml
104+
105+
sed -i "s|SSH_KEY_GOES_HERE|$SSH_KEY|g" ./.github/actions/test/integration/build/dev-user-butane-hv1.yaml
106+
sed -i "s|SSH_KEY_GOES_HERE|$SSH_KEY|g" ./.github/actions/test/integration/build/dev-user-butane-hv2.yaml
103107
104108
PASSWORD=$(openssl passwd "password")
105109
echo "PASSWORD=$PASSWORD" >> $GITHUB_ENV
106-
sed -i "s|PASSWORD_GOES_HERE|$PASSWORD|g" ./.github/actions/test/integration/build/dev-user-butane.yaml
107-
sed -i "s|TAG_GOES_HERE|${{ inputs.image_tag }}|g" ./.github/actions/test/integration/build/dev-user-butane.yaml
110+
sed -i "s|PASSWORD_GOES_HERE|$PASSWORD|g" ./.github/actions/test/integration/build/dev-user-butane-hv1.yaml
111+
sed -i "s|PASSWORD_GOES_HERE|$PASSWORD|g" ./.github/actions/test/integration/build/dev-user-butane-hv2.yaml
112+
sed -i "s|TAG_GOES_HERE|${{ inputs.image_tag }}|g" ./.github/actions/test/integration/build/dev-user-butane-hv1.yaml
113+
sed -i "s|TAG_GOES_HERE|${{ inputs.image_tag }}|g" ./.github/actions/test/integration/build/dev-user-butane-hv2.yaml
108114
109-
butane --pretty --strict ./.github/actions/test/integration/build/dev-user-butane.yaml > "/opt/${TAG}.ign"
115+
butane --pretty --strict ./.github/actions/test/integration/build/dev-user-butane-hv1.yaml > "/opt/${TAG}-hv1.ign"
116+
butane --pretty --strict ./.github/actions/test/integration/build/dev-user-butane-hv2.yaml > "/opt/${TAG}-hv2.ign"
110117
111118
- name: Download ubuntu cloud image
112119
shell: bash
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
- path: /opt/persist/root-hints.yaml
2+
mode: 0644
3+
contents:
4+
inline: |
5+
hints:
6+
- size: lt 500G

.github/actions/test/integration/setup/action.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ runs:
1515
- name: Copy ignition file
1616
shell: bash
1717
run: |
18-
sudo cp "/opt/${TAG}.ign" /var/lib/libvirt/images/hv.ign
18+
sudo cp "/opt/${TAG}-hv1.ign" /var/lib/libvirt/images/HV1.ign
19+
sudo cp "/opt/${TAG}-hv2.ign" /var/lib/libvirt/images/HV2.ign
1920
2021
- name: Create HyperVisor 1
2122
shell: bash

.github/actions/test/integration/setup/hv.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
</devices>
3333
<qemu:commandline>
3434
<qemu:arg value='-fw_cfg' />
35-
<qemu:arg value='name=opt/com.coreos/config,file=/var/lib/libvirt/images/hv.ign' />
35+
<qemu:arg value='name=opt/com.coreos/config,file=/var/lib/libvirt/images/HV_NAME_GOES_HERE.ign' />
3636
</qemu:commandline>
3737
</domain>

features/_usi/initrd.include/usr/bin/detect_disk

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ set -Eeuo pipefail
44

55
ROOT_HINTS_FILE="/sysroot/opt/persist/root-hints.yaml"
66

7-
if ! [[ -f $ROOT_HINTS_FILE ]]; then
8-
echo "no root-hints.yaml provided, error"
9-
exit 1
10-
fi
117
if kname=$(/usr/bin/root-hints $ROOT_HINTS_FILE); then
128
echo "/dev/${kname}"
139
else

features/_usi/initrd.include/usr/bin/persist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ if ! disk_dev=$(/usr/bin/detect_disk); then
66
exit 1
77
fi
88

9+
if [[ ! -b "$disk_dev" ]]; then
10+
echo "Device $disk_dev not found, exiting"
11+
exit 1
12+
fi
13+
914
# clean up the disk
1015
sgdisk -Z "$disk_dev"
1116
sgdisk -o "$disk_dev"

features/_usi/initrd.include/usr/bin/root-hints

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,46 @@ function filter() {
2727
fi
2828
if [[ $val =~ ^[0-9]+[KMGT]+$ ]]; then
2929
val=$(echo "$val" | numfmt --from=iec)
30-
echo "and ${col^^} $op ${val}"
30+
echo "${col^^} $op ${val}"
3131
else
32-
echo "and ${col^^} $op \"${val}\""
32+
echo "${col^^} $op \"${val}\""
3333
fi
34-
3534
}
3635

3736
yamlFile="$1"
3837

38+
# TODO: likely go rather with device uuid or alike
3939
#if dev=$(yq -e .dev "$yamlFile" 2> /dev/null); then
4040
# echo "$dev"
4141
# exit 0
4242
#fi
4343

44-
flsblk="TYPE eq \"disk\""
45-
while IFS= read -r r; do
46-
f=$(filter "$r")
47-
flsblk="$flsblk $f"
48-
done < <(yqroot "$yamlFile" )
44+
declare -a flsblk=()
45+
# check if yaml file exists and is valid, if so, use it to build the filter for lsblk
46+
if [ -f "$yamlFile" ] && yq -e . "$yamlFile" >/dev/null 2>&1; then
47+
while IFS= read -r r; do
48+
flsblk+=("$(filter "$r")")
49+
done < <(yqroot "$yamlFile")
50+
fi
51+
52+
LSBLK_JSON=""
53+
54+
function join {
55+
local SEPARATOR="$1"
56+
shift
57+
printf "%s${SEPARATOR}" "$@" | sed --unbuffered "s/${SEPARATOR}$//"
58+
}
59+
60+
# if flsblk contains elements, we join them by 'and' and use the filter with lsblk
61+
if [ ${#flsblk[@]} -gt 0 ]; then
62+
flsfilter=$(join " and " "${flsblk[@]}")
63+
echo "Using filter: $flsfilter" 1>&2
64+
LSBLK_JSON=$(lsblk --sort size --exclude 1,2,3,4,7,11 --filter "$flsfilter" -OJ)
65+
else
66+
# no hints, hence we choose the smallest disk we find. we exclude ram disk,
67+
# floppy, ide, dynamically allocated, loopback and scsi cd-rom devices
68+
LSBLK_JSON=$(lsblk --sort size --exclude 1,2,3,4,7,11 -OJ)
69+
fi
4970

50-
#echo "$flsblk"
51-
lsblk --filter "$flsblk" --noheadings -o kname
71+
# from the resulting list of disks we pick the first disk that are writeable
72+
echo "$LSBLK_JSON" | jq -r '[.blockdevices.[]|select(.type? == "disk" and .ro? == false)][0].kname // ""'

0 commit comments

Comments
 (0)