Skip to content

Commit 5e67815

Browse files
committed
Ensure pod IP discovery works first time every time
1 parent 78ab29c commit 5e67815

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

python/perftest/templates/_macros.j2

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,50 @@ volumeMounts:
7878
name: wait-for-{{ component }}-port-{{ port }}
7979
image: {{ settings.discovery_container_image }}
8080
imagePullPolicy: {{ benchmark.spec.image_pull_policy | default(settings.default_image_pull_policy) }}
81-
securityContext:
82-
privileged: true
8381
args:
8482
- bash
8583
- -c
8684
- |
8785
set -e
88-
89-
# containerd bind mounts /etc/hosts, so unmount it and
90-
# symlink our version
86+
87+
# Make sure that /etc/hosts both gets populated with benchmark pod IPs
88+
# and mounted correctly before checking port liveness.
89+
# If /etc/hosts is mounted before it is populated, it can stay empty
90+
# despite it's underlying configMap being populated asynchronously.
91+
# The logic here is:
92+
# 1. If /etc/hosts is empty, wait for all of the pods participating in
93+
# the benchmark to be populated in /etc/kube-perftest/hosts. When all
94+
# pod IPs are available in /etc/kube-perftest/hosts, exit 1 to allow
95+
# Kubelet to restart the container and remount a fully populated
96+
# /etc/hosts.
97+
# 2. If /etc/hosts is not empty, check that a record is present for
98+
# every pod participating in the benchmark, and exit 1 if a
99+
# record for a pod is not found.
100+
91101
if [ ! -s /etc/hosts ]; then
92-
umount /etc/hosts
93-
ln -sf /etc/kube-perftest/hosts /etc/hosts
102+
echo "/etc/hosts is empty, waiting for hosts to be populated..."
103+
104+
while read host; do
105+
until grep -q "${host}" /etc/kube-perftest/hosts; do
106+
sleep 1
107+
done
108+
echo "IP populated for ${host}"
109+
done < /etc/kube-perftest/all-hosts
110+
111+
echo "All hosts populated, exiting to ensure /etc/hosts is mounted correctly."
112+
113+
exit 1
114+
else
115+
echo "Checking for all benchmark hosts in /etc/hosts"
116+
117+
while read host; do
118+
if ! grep -q "${host}" /etc/hosts; then
119+
echo "No record for ${host} in /etc/hosts, quitting."
120+
exit 1
121+
else
122+
echo "Found ${host} in /etc/hosts, continuing..."
123+
fi
124+
done < /etc/kube-perftest/all-hosts
94125
fi
95126

96127
while read host; do

0 commit comments

Comments
 (0)