Skip to content

Commit fe7c079

Browse files
Merge pull request #436 from stackhpc/2024.1-neutron-cherries
neutron: Add agents wrappers in the neutron-base image
2 parents 50b3c6e + 34488af commit fe7c079

File tree

12 files changed

+290
-0
lines changed

12 files changed

+290
-0
lines changed

docker/neutron/neutron-base/Dockerfile.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ ADD plugins-archive /
6868

6969
COPY neutron_sudoers /etc/sudoers.d/kolla_neutron_sudoers
7070
COPY extend_start.sh /usr/local/bin/kolla_extend_start
71+
RUN mkdir -p /usr/local/lib/neutron-wrappers /usr/local/etc/neutron-wrappers
72+
COPY dnsmasq haproxy keepalived neutron-keepalived-state-change radvd copy-wrappers delete-wrappers /usr/local/lib/neutron-wrappers/
73+
RUN chmod +x /usr/local/lib/neutron-wrappers/copy-wrappers \
74+
&& chmod +x /usr/local/lib/neutron-wrappers/delete-wrappers
7175

7276
RUN ln -s neutron-base-source/* neutron \
7377
&& {{ macros.install_pip(neutron_base_pip_packages | customizable("pip_packages")) }} \
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
for binary in dnsmasq haproxy keepalived neutron-keepalived-state-change radvd; do
3+
cp /usr/local/lib/neutron-wrappers/${binary} /usr/local/bin/${binary}
4+
chmod +x /usr/local/bin/${binary}
5+
done
6+
7+
echo "KOLLA_IMAGE=${KOLLA_IMAGE}" > /usr/local/etc/neutron-wrappers/config
8+
echo "KOLLA_NAME=${KOLLA_NAME}" >> /usr/local/etc/neutron-wrappers/config
9+
echo "KOLLA_SERVICE_NAME=${KOLLA_SERVICE_NAME}" >> /usr/local/etc/neutron-wrappers/config
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
for binary in dnsmasq haproxy keepalived neutron-keepalived-state-change radvd; do
3+
rm -f /usr/local/bin/${binary}
4+
done
5+
6+
rm -f /usr/local/etc/neutron-wrappers/config
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
source /usr/local/etc/neutron-wrappers/config
4+
5+
ARGS="$@"
6+
7+
# Extract the network namespace UUID from the command line args provided by
8+
# neutron. Typically of the form (with dnsmasq as an example):
9+
#
10+
# dnsmasq --no-hosts --no-resolv --except-interface=lo \
11+
# --pid-file=/var/lib/neutron/dhcp/317716b8-919a-4a6f-8db1-78128ec3b100/pid \
12+
# --dhcp-hostsfile=/var/lib/neutron/dhcp/317716b8-919a-4a6f-8db1-78128ec3b100/host ...
13+
NETNS=$(ip netns identify)
14+
NAME=${KOLLA_NAME}_dnsmasq_${NETNS}
15+
16+
if [[ -S "/var/run/docker.sock" ]]; then
17+
CLI="docker"
18+
CMD="ip netns exec ${NETNS} /usr/sbin/dnsmasq -k"
19+
elif [[ -S "/run/podman/podman.sock" ]]; then
20+
CLI="nsenter --net=/run/netns/${NETNS} --preserve-credentials -m -t1 podman"
21+
CMD="/usr/sbin/dnsmasq -k"
22+
else
23+
echo "Could not detect a supported container runtime, exiting."
24+
exit 1
25+
fi
26+
27+
LIST=$($CLI ps -a --filter name=${SERVICE}_dnsmasq_ --format '{{.ID}}:{{.Names}}:{{.Status}}' | awk '{print $1}')
28+
29+
# If the NAME is already taken by a container, give it an unique name
30+
printf "%s\n" "${LIST}" | grep -q "${NAME}$" && NAME="${NAME}_$(date +%Y-%m-%d-%H%M%S-%N)"
31+
32+
echo "Starting a new child container ${NAME} using image ${KOLLA_IMAGE}"
33+
$CLI run --rm --detach \
34+
-v /etc/kolla/${KOLLA_SERVICE_NAME}:/etc/neutron:ro \
35+
-v /run/netns:/run/netns:shared \
36+
-v neutron_metadata_socket:/var/lib/neutron/kolla/ \
37+
-v kolla_logs:/var/log/kolla \
38+
--net host \
39+
--pid host \
40+
--cgroupns host \
41+
--privileged \
42+
-u root \
43+
--name $NAME \
44+
${KOLLA_IMAGE} \
45+
$CMD $ARGS
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
source /usr/local/etc/neutron-wrappers/config
4+
5+
ARGS="$@"
6+
7+
# Extract the network namespace UUID from the command line args provided by
8+
# neutron. Typically of the form (with dnsmasq as an example):
9+
#
10+
# dnsmasq --no-hosts --no-resolv --except-interface=lo \
11+
# --pid-file=/var/lib/neutron/dhcp/317716b8-919a-4a6f-8db1-78128ec3b100/pid \
12+
# --dhcp-hostsfile=/var/lib/neutron/dhcp/317716b8-919a-4a6f-8db1-78128ec3b100/host ...
13+
NETNS=$(ip netns identify)
14+
NAME=${KOLLA_NAME}_haproxy_${NETNS}
15+
HAPROXY_CMD='$(if [ -f /usr/sbin/haproxy-systemd-wrapper ]; then echo "/usr/sbin/haproxy -Ds"; else echo "/usr/sbin/haproxy -Ws"; fi)'
16+
if [[ -S "/var/run/docker.sock" ]]; then
17+
CLI="docker"
18+
CMD="ip netns exec ${NETNS} "'$HAPROXY'
19+
elif [[ -S "/run/podman/podman.sock" ]]; then
20+
CLI="nsenter --net=/run/netns/${NETNS} --preserve-credentials -m -t 1 podman"
21+
CMD='$HAPROXY'
22+
else
23+
echo "Could not detect a supported container runtime, exiting."
24+
exit 1
25+
fi
26+
27+
LIST=$($CLI ps -a --filter name=${KOLLA_NAME}_haproxy_ --format '{{.ID}}:{{.Names}}:{{.Status}}' | awk '{print $1}')
28+
29+
# If the NAME is already taken by a container, give it an unique name
30+
printf "%s\n" "${LIST}" | grep -q "${NAME}$" && NAME="${NAME}_$(date +%Y-%m-%d-%H%M%S-%N)"
31+
32+
echo "Starting a new child container ${NAME} using image ${KOLLA_IMAGE}"
33+
$CLI run --rm --detach \
34+
-v /etc/kolla/${KOLLA_SERVICE_NAME}:/etc/neutron:ro \
35+
-v /run/netns:/run/netns:shared \
36+
-v neutron_metadata_socket:/var/lib/neutron/kolla \
37+
-v kolla_logs:/var/log/kolla \
38+
--net host \
39+
--pid host \
40+
--cgroupns host \
41+
--privileged \
42+
-u root \
43+
--name $NAME \
44+
${KOLLA_IMAGE} \
45+
/bin/bash -c "HAPROXY=\"$HAPROXY_CMD\"; exec $CMD $ARGS"
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
source /usr/local/etc/neutron-wrappers/config
4+
5+
ARGS="$@"
6+
7+
# Extract the network namespace UUID from the command line args provided by
8+
# neutron. Typically of the form (with dnsmasq as an example):
9+
#
10+
# dnsmasq --no-hosts --no-resolv --except-interface=lo \
11+
# --pid-file=/var/lib/neutron/dhcp/317716b8-919a-4a6f-8db1-78128ec3b100/pid \
12+
# --dhcp-hostsfile=/var/lib/neutron/dhcp/317716b8-919a-4a6f-8db1-78128ec3b100/host ...
13+
NETNS=$(ip netns identify)
14+
NAME=${KOLLA_NAME}_keepalived_${NETNS}
15+
16+
if [[ -S "/var/run/docker.sock" ]]; then
17+
CLI="docker"
18+
CMD="ip netns exec ${NETNS} /usr/sbin/keepalived -n -l -D"
19+
elif [[ -S "/run/podman/podman.sock" ]]; then
20+
CLI="nsenter --net=/run/netns/${NETNS} --preserve-credentials -m -t 1 podman"
21+
CMD='/usr/sbin/keepalived -n -l -D'
22+
else
23+
echo "Could not detect a supported container runtime, exiting."
24+
exit 1
25+
fi
26+
27+
LIST=$($CLI ps -a --filter name=${KOLLA_SERVICE}_keepalived_ --format '{{.ID}}:{{.Names}}:{{.Status}}' | awk '{print $1}')
28+
29+
# If the NAME is already taken by a container, give it an unique name
30+
printf "%s\n" "${LIST}" | grep -q "${NAME}$" && NAME="${NAME}_$(date +%Y-%m-%d-%H%M%S-%N)"
31+
32+
echo "Starting a new child container ${NAME} using image ${KOLLA_IMAGE}"
33+
$CLI run --detach \
34+
-v /etc/kolla/${KOLLA_SERVICE_NAME}:/etc/neutron:ro \
35+
-v /lib/modules:/lib/modules:ro \
36+
-v /sbin/modprobe:/sbin/modprobe:ro \
37+
-v /run/netns:/run/netns:shared \
38+
-v neutron_metadata_socket:/var/lib/neutron/kolla/ \
39+
-v kolla_logs:/var/log/kolla \
40+
--net host \
41+
--pid host \
42+
--cgroupns host \
43+
--privileged \
44+
-u root \
45+
--name $NAME \
46+
${KOLLA_IMAGE} \
47+
$CMD $ARGS
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
source /usr/local/etc/neutron-wrappers/config
4+
5+
ARGS="$@"
6+
7+
# Extract the network namespace UUID from the command line args provided by
8+
# neutron. Typically of the form (with dnsmasq as an example):
9+
#
10+
# dnsmasq --no-hosts --no-resolv --except-interface=lo \
11+
# --pid-file=/var/lib/neutron/dhcp/317716b8-919a-4a6f-8db1-78128ec3b100/pid \
12+
# --dhcp-hostsfile=/var/lib/neutron/dhcp/317716b8-919a-4a6f-8db1-78128ec3b100/host ...
13+
NETNS=$(ip netns identify)
14+
NAME=${KOLLA_NAME}_keepalived_${NETNS}
15+
if [[ -S "/var/run/docker.sock" ]]; then
16+
CLI="docker exec --detach"
17+
CMD="ip netns exec ${NETNS} /usr/bin/neutron-keepalived-state-change"
18+
elif [[ -S "/run/podman/podman.sock" ]]; then
19+
CLI="nsenter --net=/run/netns/${NETNS} --preserve-credentials -m -t 1 podman exec"
20+
CMD="/usr/bin/neutron-keepalived-state-change"
21+
else
22+
echo "Could not detect a supported container runtime, exiting."
23+
exit 1
24+
fi
25+
26+
# The state change daemon only runs as a daemon for the moment so we need to
27+
# run it within an existing container with a sensibly matching lifetime. The
28+
# related keepalived container seems an obvious choice.
29+
container_id=$($CLI ps --filter name=$NAME --format "{{.ID}}")
30+
31+
if [[ -z $container_id ]];
32+
then
33+
echo "WARNING: keepalived container is not running."
34+
exit 0
35+
fi
36+
37+
$CLI -u root \
38+
--privileged \
39+
$NAME \
40+
$CMD $ARGS

docker/neutron/neutron-base/neutron_sudoers

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ neutron ALL = (root) NOPASSWD: /usr/sbin/update-alternatives --set iptables /usr
88
neutron ALL = (root) NOPASSWD: /usr/sbin/update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
99
neutron ALL = (root) NOPASSWD: /usr/sbin/update-alternatives --auto iptables
1010
neutron ALL = (root) NOPASSWD: /usr/sbin/update-alternatives --auto ip6tables
11+
neutron ALL = (root) NOPASSWD: /usr/local/lib/neutron-wrappers/copy-wrappers, /usr/local/lib/neutron-wrappers/delete-wrappers

docker/neutron/neutron-base/radvd

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
source /usr/local/etc/neutron-wrappers/config
4+
5+
ARGS="$@"
6+
# Extract the network namespace UUID from the command line args provided by
7+
# neutron. Typically of the form (with dnsmasq as an example):
8+
#
9+
# dnsmasq --no-hosts --no-resolv --except-interface=lo \
10+
# --pid-file=/var/lib/neutron/dhcp/317716b8-919a-4a6f-8db1-78128ec3b100/pid \
11+
# --dhcp-hostsfile=/var/lib/neutron/dhcp/317716b8-919a-4a6f-8db1-78128ec3b100/host ...
12+
NETWORK_ID=$(echo $ARGS| awk '{if (match($0, /(\w{8}-\w{4}-\w{4}-\w{4}-\w{12})/,m)) print m[0] }')
13+
NAME=${KOLLA_NAME}_radvd_${NETWORK_ID}
14+
if [[ -S "/var/run/docker.sock" ]]; then
15+
CLI="docker"
16+
CMD="ip netns exec qrouter-${NETWORK_ID} /usr/sbin/radvd -n"
17+
elif [[ -S "/run/podman/podman.sock" ]]; then
18+
CLI="nsenter --net=/run/netns/${NETNS} --preserve-credentials -m -t 1 podman"
19+
CMD="/usr/sbin/radvd -n"
20+
else
21+
echo "Could not detect a supported container runtime, exiting."
22+
exit 1
23+
fi
24+
25+
LIST=$($CLI ps -a --filter name=${KOLLA_NAME}_radvd_ --format '{{.ID}}:{{.Names}}:{{.Status}}' | awk '{print $1}')
26+
# If the NAME is already taken by a container, give it an unique name
27+
printf "%s\n" "${LIST}" | grep -q "${NAME}$" && NAME="${NAME}_$(date +%Y-%m-%d-%H%M%S-%N)"
28+
29+
echo "Starting a new child container ${NAME} using image ${KOLLA_IMAGE}"
30+
$CLI run --rm --detach \
31+
-v /etc/kolla/${KOLLA_SERVICE_NAME}:/etc/neutron:ro \
32+
-v /run/netns:/run/netns:shared \
33+
-v neutron_metadata_socket:/var/lib/neutron/kolla/ \
34+
-v kolla_logs:/var/log/kolla \
35+
--net host \
36+
--pid host \
37+
--cgroupns host \
38+
--privileged \
39+
-u root \
40+
--name $NAME \
41+
${KOLLA_IMAGE} \
42+
$CMD $ARGS

docker/neutron/neutron-dhcp-agent/extend_start.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,12 @@ if [[ ! -f "/var/log/kolla/neutron/dnsmasq.log" ]]; then
66
chown neutron:kolla /var/log/kolla/neutron/dnsmasq.log
77
fi
88

9+
if [[ "${KOLLA_NEUTRON_WRAPPERS:-false}" == "true" ]]; then
10+
echo "Copying neutron agent wrappers to /usr/local/bin"
11+
sudo -E /usr/local/lib/neutron-wrappers/copy-wrappers
12+
else
13+
echo "Removing neutron agent wrappers from /usr/local/bin"
14+
sudo -E /usr/local/lib/neutron-wrappers/delete-wrappers
15+
fi
16+
917
. /usr/local/bin/kolla_neutron_extend_start

0 commit comments

Comments
 (0)