@@ -78,19 +78,50 @@ volumeMounts:
78
78
name: wait-for-{{ component }}-port-{{ port }}
79
79
image: {{ settings.discovery_container_image }}
80
80
imagePullPolicy: {{ benchmark.spec.image_pull_policy | default(settings.default_image_pull_policy) }}
81
- securityContext:
82
- privileged: true
83
81
args:
84
82
- bash
85
83
- -c
86
84
- |
87
85
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
+
91
101
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
94
125
fi
95
126
96
127
while read host; do
0 commit comments