From 76f89f40b37f0581b51033c16ec961a854e84e14 Mon Sep 17 00:00:00 2001 From: Matt McEuen Date: Mon, 31 Aug 2020 13:13:20 -0500 Subject: [PATCH] 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 --- manifests/function/ephemeral/secret.yaml | 39 ++++++++++++++++-------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/manifests/function/ephemeral/secret.yaml b/manifests/function/ephemeral/secret.yaml index 9edc08825..12a838d42 100644 --- a/manifests/function/ephemeral/secret.yaml +++ b/manifests/function/ephemeral/secret.yaml @@ -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