Skip to content
This repository was archived by the owner on Oct 6, 2022. It is now read-only.

Commit 16b5bf2

Browse files
committed
Fix /dev/kmsg linking regardless of which image is used
The previous approach to link `/dev/kmsg` to `/dev/console` only works on images that we build ourselves. The new approach is to do the linking at runtime, parallel to kind brining up the cluster: We run a function parallel to kind, which tries to exec into the control plane node and do the linking. This should succeed as soon as the node container is up, in which case the function will terminate gracefully. As this is fixed in kind already [0], we can remove that hack probably when kind 0.5.0 is out. Why is this linking even needed? See also [0]! [0]: kubernetes-sigs/kind#662
1 parent d1bad52 commit 16b5bf2

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

entrypoint.sh

+26-27
Original file line numberDiff line numberDiff line change
@@ -188,32 +188,6 @@ docker::stop() {
188188
log::info "Docker exited after ${duration} seconds."
189189
}
190190

191-
# Starting with k8s 1.15 nodes need to have /dev/kmsg available, otherwise the
192-
# kubelet will fail to start.
193-
# For systems which don't have /dev/kmsg, we try to symlink to /dev/console.
194-
# This is implemented by injecting a systemd service override file into the
195-
# image in question, which does the symlinking (if needed) before the kubelet
196-
# is started.
197-
kind::hack::inject_kmsg_linking() {
198-
local imgName="$1"
199-
(
200-
tmpDir="$(mktemp -d)"
201-
trap 'rm -rf -- "$tmpDir"' EXIT
202-
203-
cd "$tmpDir"
204-
{
205-
echo '[Service]'
206-
echo 'ExecStartPre=/bin/sh -c "[ -e /dev/kmsg ] || ln -s /dev/console /dev/kmsg"'
207-
} > 10-kmsg.conf
208-
{
209-
echo "FROM ${imgName}"
210-
echo "COPY 10-kmsg.conf /etc/systemd/system/kubelet.service.d/10-kmsg.conf"
211-
} > Dockerfile
212-
213-
docker build -t "$imgName" .
214-
)
215-
}
216-
217191
# Until kind/kindnet properly supports non-IPv6 systems, we use flannel as a CNI.
218192
# To do so, we also need to use a custom kind config when starting kind.
219193
# See also:
@@ -239,21 +213,46 @@ kind::start::fromSource() {
239213
# create the node image
240214
GOPATH="$(pwd)/go" \
241215
kind build node-image --image "$imageName"
242-
kind::hack::inject_kmsg_linking "$imageName"
243216

244217
# bring up kind
218+
kind::hack::kmsg_linker "$clusterName" &
245219
kind create cluster --config "$KIND_CONFIG" --image "$imageName" --name "$clusterName" --loglevel "$loglevel" --retain
246220

247221
# get the (compiled) version of kubectl
248222
cp ./go/src/k8s.io/kubernetes/_output/dockerized/bin/linux/amd64/kubectl ./bin/kubectl
249223
}
250224

225+
kind::hack::kmsg_linker() {
226+
local node nodeCmd clusterName sleepDur tries
227+
228+
clusterName="$1"
229+
nodeCmd='set -e; [ -e /dev/kmsg ] || ln -s /dev/console /dev/kmsg'
230+
sleepDur="1s"
231+
tries=300
232+
233+
log::info 'kmsg-linker starting in the background'
234+
235+
while (( tries-- ))
236+
do
237+
sleep "$sleepDur"
238+
node="$(kind get nodes --name "$clusterName" 2>/dev/null)" || continue
239+
docker exec "$node" sh -c "$nodeCmd" 2>/dev/null || continue
240+
241+
log::info 'kms-linker was successful, exiting'
242+
return
243+
done
244+
245+
log::error "kmsg-linker failed after ${tries} tries"
246+
return 1
247+
}
248+
251249
# Start kind with the (latest) node image published by kind upstream
252250
kind::start::fromUpstream() {
253251
local clusterName="$1"
254252

255253
log::warn "no k8s source found, using newest node image from kind upstream"
256254

255+
kind::hack::kmsg_linker "$clusterName" &
257256
kind create cluster --config "$KIND_CONFIG" --name "$clusterName" --loglevel "$loglevel" --retain
258257

259258
# get kubectl from upstream

0 commit comments

Comments
 (0)