Dynamically determine disk for images & bindmounts

This removes an assumption in the ephemeral cloud-init that
vda should be used to hold ironic images and container bindmounts.
Cloud-init will now use the ram-backed FS if there's enough
memory, and otherwise will default to vda or sda as appropriate.

Change-Id: If2a05348df7fae99598ff76e171b0e88fc2e6f88
This commit is contained in:
Matt McEuen 2020-08-31 13:13:20 -05:00
parent 61633d30fc
commit 76f89f40b3

View File

@ -105,15 +105,30 @@ stringData:
path: /tmp/kubeadm.yaml
permissions: "0640"
bootcmd:
- /usr/sbin/mkfs.ext4 /dev/vda
- mkdir /mnt/vda
- mount /dev/vda /mnt/vda
- mkdir -p /opt/metal3-dev-env/ironic/html/images
- mkdir -p /mnt/vda/opt/metal3-dev-env/ironic/html/images
- mount --bind /mnt/vda/opt/metal3-dev-env/ironic/html/images /opt/metal3-dev-env/ironic/html/images
- mkdir -p /var/lib/docker /mnt/vda/var/lib/docker
- mount --bind /mnt/vda/var/lib/docker /var/lib/docker
- mkdir -p /var/lib/docker-engine /mnt/vda/var/lib/docker-engine
- mount --bind /mnt/vda/var/lib/docker-engine /var/lib/docker-engine
- mkdir -p /mnt/vda/var/lib/kubelet/ /var/lib/kubelet/
- mount --bind /mnt/vda/var/lib/kubelet/ /var/lib/kubelet/
- NEED_MB=16384 # MB of storage needed for ironic images & bindmounts
- FREE_MB=$(df -m --output=avail /var/lib | tail -n 1)
# if there's not enough memory-backed storage, mount an available disk
- if [ ${FREE_MB} -lt ${NEED_MB} ]; then
- mkdir /mnt/ephemeral
# Use vda if provided by a hypervisor
- if [ -e /dev/vda ]; then
- mkfs.ext4 /dev/vda
- mount /dev/vda /mnt/ephemeral
# Fall back to sda
- elif [ -e /dev/sda ]; then
- mkfs.ext4 -F /dev/sda
- mount /dev/sda /mnt/ephemeral
- else
- echo "Not enough RAM to host images, and no available disks found"
- exit 1
- fi
- mkdir -p /opt/metal3-dev-env/ironic/html/images
- mkdir -p /mnt/ephemeral/opt/metal3-dev-env/ironic/html/images
- mount --bind /mnt/ephemeral/opt/metal3-dev-env/ironic/html/images /opt/metal3-dev-env/ironic/html/images
- mkdir -p /var/lib/docker /mnt/ephemeral/var/lib/docker
- mount --bind /mnt/ephemeral/var/lib/docker /var/lib/docker
- mkdir -p /var/lib/docker-engine /mnt/ephemeral/var/lib/docker-engine
- mount --bind /mnt/ephemeral/var/lib/docker-engine /var/lib/docker-engine
- mkdir -p /mnt/ephemeral/var/lib/kubelet/ /var/lib/kubelet/
- mount --bind /mnt/ephemeral/var/lib/kubelet/ /var/lib/kubelet/
- fi