diff --git a/libvirt/templates/bin/_libvirt.sh.tpl b/libvirt/templates/bin/_libvirt.sh.tpl index 5a5e38dd..7d2c5b61 100644 --- a/libvirt/templates/bin/_libvirt.sh.tpl +++ b/libvirt/templates/bin/_libvirt.sh.tpl @@ -54,17 +54,23 @@ if [ 0"$hp_count" -gt 0 ]; then # Kubernetes 1.10.x introduced cgroup changes that caused the container's # hugepage byte limit quota to zero out. This workaround sets that pod limit # back to the total number of hugepage bytes available to the baremetal host. + if [ -d /sys/fs/cgroup/hugetlb ]; then + # NOTE(portdirect): Kubelet will always create pod specific cgroups for + # hugetables so if the hugetlb cgroup is enabled, when k8s removes the pod + # it will also remove the hugetlb cgroup for the pod, taking any qemu + # processes with it. + echo "WARN: As the hugetlb cgroup is enabled, it will not be possible to restart the libvirt pod via k8s, without killing VMs." + for limit in $(ls /sys/fs/cgroup/hugetlb/kubepods/hugetlb.*.limit_in_bytes); do + target="/sys/fs/cgroup/hugetlb/$(dirname $(awk -F: '($2~/hugetlb/){print $3}' /proc/self/cgroup))/$(basename $limit)" + # Ensure the write target for the hugepage limit for the pod exists + if [ ! -f "$target" ]; then + echo "ERROR: Could not find write target for hugepage limit: $target" + fi - for limit in $(ls /sys/fs/cgroup/hugetlb/kubepods/hugetlb.*.limit_in_bytes); do - target="/sys/fs/cgroup/hugetlb/$(dirname $(awk -F: '($2~/hugetlb/){print $3}' /proc/self/cgroup))/$(basename $limit)" - # Ensure the write target for the hugepage limit for the pod exists - if [ ! -f "$target" ]; then - echo "ERROR: Could not find write target for hugepage limit: $target" - fi - - # Write hugetable limit for pod - echo "$(cat $limit)" > "$target" - done + # Write hugetable limit for pod + echo "$(cat $limit)" > "$target" + done + fi # Determine OS default hugepage size to use for the hugepage write test default_hp_kb="$(cat /proc/meminfo | grep Hugepagesize | tr -cd '[:digit:]')"