diff --git a/README.md b/README.md index bc1b7ac..005d45d 100644 --- a/README.md +++ b/README.md @@ -74,3 +74,28 @@ FakeIPA simulate the IPA by: a queue of fake agents. - Faking the sync/async commands needed by ironic to inspect, clean and provision a node. + +## Keepalived + +Keepalived container used in Ironic deployments. Keepalived is used to +provide fixed IP address for Ironic in such a manner that even after pivoting +operations the IP of Ironic stays persistent. + +[Keepalived documentation](https://www.keepalived.org/manpage.html) + +Deployment configuration options: + +- `CUSTOM_CONF_DIR` - when specified, a subdirectory (named keepalived) will be +created under this path then the config files will be moved to the subdirectory +and the variable substitution will happen in this subdirectory +- `CUSTOM_DATA_DIR` - subdirectory (named keepalived) will be created here to +hold the keepalived and vrrp pid files +- `PROVISIONING_IP` - the fixed IP provided by keepalived +- `PROVISIONING_INTERFACE` - The name of the interface that will be used + to "host" the fixed IP (keepalived is used in a pod that is attached to + host network, thus the interface names are the same as the interface names + on the host) + +NOTE: If run with container that has read-only root file-system, then +`CUSTOM_CONF_DIR`, `CUSTOM_DATA_DIR` and `/var/log` paths have to mounted from +external volume. diff --git a/keepalived/manage-keepalived.sh b/keepalived/manage-keepalived.sh index 392077b..37088c0 100644 --- a/keepalived/manage-keepalived.sh +++ b/keepalived/manage-keepalived.sh @@ -2,10 +2,23 @@ set -eux +CUSTOM_CONF_DIR="${CUSTOM_CONF_DIR:-/conf}" +CUSTOM_DATA_DIR="${CUSTOM_DATA_DIR:-/data}" +KEEPALIVED_DEFAULT_CONF='/etc/keepalived/keepalived.conf' +KEEPALIVED_CONF_DIR="${CUSTOM_CONF_DIR}/keepalived" +KEEPALIVED_CONF="${KEEPALIVED_CONF_DIR}/keepalived.conf" +KEEPALIVED_DATA_DIR="${CUSTOM_DATA_DIR}/keepalived" + +mkdir -p "${KEEPALIVED_CONF_DIR}" "${KEEPALIVED_DATA_DIR}" +cp "${KEEPALIVED_DEFAULT_CONF}" "${KEEPALIVED_CONF}" + export assignedIP="${PROVISIONING_IP}/32" export interface="${PROVISIONING_INTERFACE}" -sed -i "s~INTERFACE~${interface}~g" /etc/keepalived/keepalived.conf -sed -i "s~CHANGEIP~${assignedIP}~g" /etc/keepalived/keepalived.conf +sed -i "s~INTERFACE~${interface}~g" "${KEEPALIVED_CONF}" +sed -i "s~CHANGEIP~${assignedIP}~g" "${KEEPALIVED_CONF}" -exec /usr/sbin/keepalived -n -l -p /run/keepalived/keepalived.pid -r /run/keepalived/vrrp.pid +exec /usr/sbin/keepalived --dont-fork --log-console \ + --pid="${KEEPALIVED_DATA_DIR}/keepalived.pid" \ + --vrrp_pid="${KEEPALIVED_DATA_DIR}/vrrp.pid" \ + --use-file="${KEEPALIVED_CONF}"