-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the sidecar containers in neutron_dhcp role
Similarly to what was done in Tripleo, neutron agents which are spawning some long running processes, like e.g. haproxy or dnsmasq should run them in the sidecar containers to avoid breakege in the dataplane when e.g. agent's container is restarted. This patch adds wrappers for haproxy and dnsmasq sidecars in the neutron_dhcp role. Those wrappers script are taken almost directly from the TripleO's puppet module [1] and are just converted to jinja2 format and to support only Podman as container_cli. [1] https://opendev.org/openstack/puppet-tripleo/src/branch/master/templates/neutron
- Loading branch information
Showing
6 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/bin/bash | ||
|
||
{% if edpm_neutron_dhcp_sidecar_debug -%} | ||
set -x | ||
{%- endif -%} | ||
|
||
ARGS="$@" | ||
|
||
IMAGE_NAME={{ edpm_neutron_dhcp_sidecar_dnsmasq_image_name }} | ||
|
||
{% raw -%} | ||
# Extract the network namespace UUID from the command line args provided by | ||
# neutron. Typically of the form (with dnsmasq as an example): | ||
# | ||
# dnsmasq --no-hosts --no-resolv --except-interface=lo \ | ||
# --pid-file=/var/lib/neutron/dhcp/317716b8-919a-4a6f-8db1-78128ec3b100/pid \ | ||
# --dhcp-hostsfile=/var/lib/neutron/dhcp/317716b8-919a-4a6f-8db1-78128ec3b100/host ... | ||
NETNS=$(ip netns identify) | ||
NAME=neutron-dnsmasq-${NETNS} | ||
|
||
CLI="nsenter --net=/run/netns/${NETNS} --preserve-credentials -m -t 1 podman" | ||
LOGGING="--log-driver k8s-file --log-opt path=/var/log/containers/stdouts/${NAME}.log" | ||
CMD='/usr/sbin/dnsmasq -k' | ||
|
||
LIST=$($CLI ps -a --filter name=neutron-dnsmasq- --format '{{.ID}}:{{.Names}}:{{.Status}}' | awk '{print $1}') | ||
|
||
# Find orphaned containers left for dead after its main process terminated by neutron parent process | ||
# FIXME(cjeanner): https://github.com/containers/libpod/issues/1703 | ||
ORPHANS=$(printf "%s\n" "${LIST}" | grep -E ":(Exited|Created)") | ||
if [ -n "${ORPHANS}" ]; then | ||
for orphant in $(printf "%s\n" "${ORPHANS}" | awk -F':' '{print $1}'); do | ||
echo "Removing orphaned container ${orphant}" | ||
# TODO(slaweq): script should at least log what error | ||
# prevented to stop or rm orphaned container if there will be any error | ||
$CLI stop ${orphant} || true | ||
$CLI rm -f ${orphant} || true | ||
done | ||
fi | ||
|
||
# If the NAME is already taken by a container, give it an unique name | ||
printf "%s\n" "${LIST}" | grep -q "${NAME}$" && NAME="${NAME}-$(date +%Y-%m-%d-%H%M%S-%N)" | ||
echo "Starting a new child container ${NAME}" | ||
$CLI run --detach ${LOGGING} \ | ||
-v /var/lib/config-data/puppet-generated/neutron/etc/neutron:/etc/neutron:ro \ | ||
-v /run/netns:/run/netns:shared \ | ||
-v /var/lib/neutron:/var/lib/neutron:shared \ | ||
-v /dev/log:/dev/log \ | ||
--net host \ | ||
--pid host \ | ||
--cgroupns host \ | ||
--privileged \ | ||
-u root \ | ||
--name $NAME \ | ||
${IMAGE_NAME} \ | ||
$CMD $ARGS | ||
{%- endraw %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/bin/bash | ||
|
||
{% if edpm_neutron_dhcp_sidecar_debug -%} | ||
set -x | ||
{%- endif -%} | ||
|
||
ARGS="$@" | ||
|
||
IMAGE_NAME={{ edpm_neutron_dhcp_sidecar_haproxy_image_name }} | ||
|
||
{% raw -%} | ||
# Extract the network namespace UUID from the command line args provided by | ||
# neutron. Typically of the form (with dnsmasq as an example): | ||
# | ||
# dnsmasq --no-hosts --no-resolv --except-interface=lo \ | ||
# --pid-file=/var/lib/neutron/dhcp/317716b8-919a-4a6f-8db1-78128ec3b100/pid \ | ||
# --dhcp-hostsfile=/var/lib/neutron/dhcp/317716b8-919a-4a6f-8db1-78128ec3b100/host ... | ||
NETNS=$(ip netns identify) | ||
NAME=neutron-haproxy-${NETNS} | ||
HAPROXY_CMD='$(if [ -f /usr/sbin/haproxy-systemd-wrapper ]; then echo "/usr/sbin/haproxy -Ds"; else echo "/usr/sbin/haproxy -Ws"; fi)' | ||
|
||
CLI="nsenter --net=/run/netns/${NETNS} --preserve-credentials -m -t 1 podman" | ||
LOGGING="--log-driver k8s-file --log-opt path=/var/log/containers/stdouts/${NAME}.log" | ||
CMD='$HAPROXY' | ||
|
||
LIST=$($CLI ps -a --filter name=neutron-haproxy- --format '{{.ID}}:{{.Names}}:{{.Status}}' | awk '{print $1}') | ||
|
||
# Find orphaned containers left for dead after its main process terminated by neutron parent process | ||
# FIXME(cjeanner): https://github.com/containers/libpod/issues/1703 | ||
ORPHANS=$(printf "%s\n" "${LIST}" | grep -E ":(Exited|Created)") | ||
if [ -n "${ORPHANS}" ]; then | ||
for orphant in $(printf "%s\n" "${ORPHANS}" | awk -F':' '{print $1}'); do | ||
echo "Removing orphaned container ${orphant}" | ||
# TODO(slaweq): script should at least log what error | ||
# prevented to stop or rm orphaned container if there will be any error | ||
$CLI stop ${orphant} || true | ||
$CLI rm -f ${orphant} || true | ||
done | ||
fi | ||
|
||
# If the NAME is already taken by a container, give it an unique name | ||
printf "%s\n" "${LIST}" | grep -q "${NAME}$" && NAME="${NAME}-$(date +%Y-%m-%d-%H%M%S-%N)" | ||
echo "Starting a new child container ${NAME}" | ||
$CLI run --detach ${LOGGING} \ | ||
-v /var/lib/config-data/puppet-generated/neutron/etc/neutron:/etc/neutron:ro \ | ||
-v /run/netns:/run/netns:shared \ | ||
-v /var/lib/neutron:/var/lib/neutron:shared \ | ||
-v /dev/log:/dev/log \ | ||
--net host \ | ||
--pid host \ | ||
--cgroupns host \ | ||
--privileged \ | ||
-u root \ | ||
--name $NAME \ | ||
${IMAGE_NAME} \ | ||
/bin/bash -c "HAPROXY=\"$HAPROXY_CMD\"; exec $CMD $ARGS" | ||
{%- endraw %} |