From c20e5119f11590239ccd0cf74e94ab5f32bff99b Mon Sep 17 00:00:00 2001 From: Ben Nemec Date: Tue, 5 Jan 2021 17:42:34 -0600 Subject: [PATCH] Add support for infinite DHCP leases The proper way to do this would be to set the lease length in the libvirt network config, but unfortunately the version of libvirt we have in CentOS 8 right now doesn't support that. This adds a script that manually modifies the libvirt dnsmasq configuration to make the leases infinite. It is started in the background, and killed when make clean is run. It can be enabled by setting INFINITE_LEASES=1. Currently, due to a bug with libvirt's handling of infinite leases, this will cause make to fail. The cluster will deploy fine, but some of the post-deploy steps don't work. This is "normal" and should be fixed in future versions of libvirt. Background: This is to support testing and dev of a feature that converts infinite DHCP leases to static configuration so a node no longer has a dependency on the DHCP server. --- 02_configure_host.sh | 10 ++++++++++ host_cleanup.sh | 6 ++++++ infinite-leases.sh | 19 +++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100755 infinite-leases.sh diff --git a/02_configure_host.sh b/02_configure_host.sh index d22fb3586..0fa7542b3 100755 --- a/02_configure_host.sh +++ b/02_configure_host.sh @@ -243,3 +243,13 @@ if [ "$DISABLE_MULTICAST" == "true" ]; then sudo ebtables -A OUTPUT --pkttype-type multicast -p ip6 --ip6-dst ${dst} -j DROP done fi + +# Hack to force use of infinite leases in versions of libvirt that don't +# support setting the lease time in the network config. +# This should be removed when we have a new enough version of libvirt to +# do it properly. I believe any version 6.3.0 or above should have the feature. +if [ ${INFINITE_LEASES:-0} -eq 1 ] +then + ./infinite-leases.sh & + echo "$!" > "${WORKING_DIR}/infinite-lease-pid" +fi diff --git a/host_cleanup.sh b/host_cleanup.sh index 99c4e51ec..a3ab65f92 100755 --- a/host_cleanup.sh +++ b/host_cleanup.sh @@ -60,3 +60,9 @@ sudo ebtables --flush # Kill any lingering proxy sudo pkill -f oc.*proxy + +# Kill the infinite lease script +if [ -s "${WORKING_DIR}/infinite-lease-pid" ]; then + kill $(cat "${WORKING_DIR}/infinite-lease-pid") + rm "${WORKING_DIR}/infinite-lease-pid" +fi diff --git a/infinite-leases.sh b/infinite-leases.sh new file mode 100755 index 000000000..744af6edd --- /dev/null +++ b/infinite-leases.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +NETWORK_NAME=${CLUSTER_NAME}bm +FILENAME=/var/lib/libvirt/dnsmasq/${NETWORK_NAME}.hostsfile + +# We need to keep running even after setting the infinite leases because +# they are overwritten multiple times in the deployment process. +while : +do + if grep -q -v infinite $FILENAME + then + sudo perl -pi -e 's/(.*?)(,infinite|)$/\1,infinite/' $FILENAME + + pid=$(ps aux | grep dnsmasq | grep "$NETWORK_NAME" | grep -v root | awk '{print $2}') + sudo kill -s SIGHUP $pid + echo "Added infinite leases to $FILENAME" + fi + sleep 10 +done