Skip to content

Commit a8f2521

Browse files
authored
Fix inotify pre-flight check for PROM_ENABLED on macOS (llm-d#1654)
* Evaluate inotify limit on the kind node, not the host The Prometheus config-reloader inotify pre-flight check ran an unconditional cat of /proc/sys/fs/inotify/max_user_instances on the host, before the cluster existed. On macOS that proc file is absent (kind runs inside the container-runtime VM), so the check aborted env-dev-kind with PROM_ENABLED=true. The limit that applies to pods is the kind node's kernel: the host kernel on Linux, the runtime VM kernel on macOS. Move the check to after the node container is created and read the value from inside it, which is correct on both platforms. Update the remediation message to cover raising the limit on the host (Linux) and in the runtime VM (macOS). Signed-off-by: roytman <roytman@il.ibm.com> * fix copilot comments Signed-off-by: roytman <roytman@il.ibm.com> --------- Signed-off-by: roytman <roytman@il.ibm.com>
1 parent 20e61b8 commit a8f2521

1 file changed

Lines changed: 30 additions & 6 deletions

File tree

scripts/kind-dev-env.sh

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,17 +198,34 @@ for cmd in kind kubectl ${CONTAINER_RUNTIME}; do
198198
fi
199199
done
200200

201-
# Prometheus config-reloader needs sufficient inotify resources
202-
if [ "${PROM_ENABLED}" == "true" ]; then
203-
INOTIFY_INSTANCES=$(cat /proc/sys/fs/inotify/max_user_instances)
204-
if [ "${INOTIFY_INSTANCES}" -lt 512 ]; then
205-
echo "Error: fs.inotify.max_user_instances is ${INOTIFY_INSTANCES} (need >= 512) for Prometheus."
201+
# The Prometheus config-reloader needs a sufficient inotify instance limit. The
202+
# argument is the limit read from the kernel backing the kind node: the host on
203+
# Linux, the runtime VM on macOS. A non-numeric value means the limit could not
204+
# be read; warn and skip rather than fail or compare a garbage string.
205+
check_inotify_limit() {
206+
local limit="$1"
207+
if ! [[ "${limit}" =~ ^[0-9]+$ ]]; then
208+
echo "Warning: could not read fs.inotify.max_user_instances; skipping Prometheus inotify check." >&2
209+
return 0
210+
fi
211+
if [ "${limit}" -lt 512 ]; then
212+
echo "Error: fs.inotify.max_user_instances is ${limit} (need >= 512) for Prometheus."
206213
echo ""
214+
echo "Raise it on the kind node's kernel. On Linux this is the host:"
207215
echo " sudo sysctl -w fs.inotify.max_user_instances=512"
208-
echo ""
209216
echo "To persist: echo 'fs.inotify.max_user_instances=512' | sudo tee /etc/sysctl.d/99-inotify.conf"
217+
echo ""
218+
echo "On macOS the kind node runs in the container runtime VM; raise it there, e.g.:"
219+
echo " ${CONTAINER_RUNTIME} exec ${CLUSTER_NAME}-control-plane sysctl -w fs.inotify.max_user_instances=512"
210220
exit 1
211221
fi
222+
}
223+
224+
# On Linux the host kernel is shared with kind's node containers, so the limit
225+
# can be verified before creating the cluster to fail fast. Hosts where kind
226+
# runs inside a VM have no inotify proc file and are checked from the node below.
227+
if [ "${PROM_ENABLED}" == "true" ] && [ -r /proc/sys/fs/inotify/max_user_instances ]; then
228+
check_inotify_limit "$(cat /proc/sys/fs/inotify/max_user_instances)"
212229
fi
213230

214231
# TARGET_PORTS is substituted directly into the `targetPorts: ${TARGET_PORTS}` field
@@ -265,6 +282,13 @@ set -x
265282
CONTAINER_NAME="${CLUSTER_NAME}-control-plane"
266283
${CONTAINER_RUNTIME} exec ${CONTAINER_NAME} /bin/bash -c "sysctl net.ipv4.conf.all.arp_ignore=0"
267284

285+
# Hosts where kind runs inside a VM (e.g. macOS) have no inotify proc file, so
286+
# the limit is read from the node, whose kernel is the runtime VM's. The host
287+
# case is handled by the fast-fail check before cluster creation.
288+
if [ "${PROM_ENABLED}" == "true" ] && [ ! -r /proc/sys/fs/inotify/max_user_instances ]; then
289+
check_inotify_limit "$(${CONTAINER_RUNTIME} exec "${CONTAINER_NAME}" cat /proc/sys/fs/inotify/max_user_instances 2>/dev/null || true)"
290+
fi
291+
268292
# Wait for all pods to be ready
269293
kubectl --context ${KUBE_CONTEXT} -n kube-system wait --for=condition=Ready --all pods --timeout=300s
270294

0 commit comments

Comments
 (0)