Skip to content

Commit 16a9adc

Browse files
authored
Fix clock sync flakiness for docker-based clusters (#1472)
* Fix clock sync flakiness for debian and ubuntu
1 parent b8be733 commit 16a9adc

File tree

7 files changed

+34
-14
lines changed

7 files changed

+34
-14
lines changed

dev/distros/dockerfiles/almalinux-8.Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
FROM almalinux:8
22

3+
# Only required for systemd-timesyncd
4+
RUN dnf install -y epel-release
5+
36
# Install necessary packages
47
RUN dnf install -y \
58
sudo \
@@ -13,7 +16,7 @@ RUN dnf install -y \
1316
ipvsadm \
1417
kmod \
1518
iproute \
16-
chrony \
19+
systemd-timesyncd \
1720
expect \
1821
vim \
1922
--allowerasing

dev/distros/dockerfiles/centos-9.Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
FROM quay.io/centos/centos:stream9
22

3+
# Only required for systemd-timesyncd
4+
RUN dnf install -y epel-release
5+
36
# Install necessary packages
47
RUN dnf install -y \
58
sudo \
@@ -13,7 +16,7 @@ RUN dnf install -y \
1316
ipvsadm \
1417
kmod \
1518
iproute \
16-
chrony \
19+
systemd-timesyncd \
1720
expect \
1821
vim \
1922
--allowerasing

dev/distros/dockerfiles/debian-bookworm.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ RUN apt-get update && apt-get install -y \
1313
ipvsadm \
1414
kmod \
1515
iproute2 \
16-
chrony \
16+
systemd-timesyncd \
1717
expect \
1818
vim
1919

dev/distros/dockerfiles/debian-bullseye.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ RUN apt-get update && apt-get install -y \
1313
ipvsadm \
1414
kmod \
1515
iproute2 \
16-
chrony \
16+
systemd-timesyncd \
1717
expect \
1818
vim
1919

dev/distros/dockerfiles/ubuntu-jammy.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ RUN apt-get update && apt-get install -y \
1313
ipvsadm \
1414
kmod \
1515
iproute2 \
16-
chrony \
16+
systemd-timesyncd \
1717
expect \
1818
vim
1919

dev/distros/entrypoint.sh

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,27 @@ systemctl mask \
1717
# A unique machine ID is required for multi-node clusters in k0s <= v1.29
1818
# https://github.com/k0sproject/k0s/blob/443e28b75d216e120764136b4513e6237cea7cc5/docs/external-runtime-deps.md#a-unique-machine-id-for-multi-node-setups
1919
if [ ! -f "/etc/machine-id.persistent" ]; then
20-
dbus-uuidgen --ensure=/etc/machine-id.persistent
20+
tr -dc 'a-z0-9' < /dev/urandom | head -c32 > /etc/machine-id.persistent
2121
fi
22+
mkdir -p /var/lib/dbus
2223
ln -sf /etc/machine-id.persistent /etc/machine-id
2324
ln -sf /etc/machine-id.persistent /var/lib/dbus/machine-id
2425

25-
# Sync time
26-
chronyc -a makestep
26+
# Override timesyncd config to allow it to run in containers
27+
mkdir -p /etc/systemd/system/systemd-timesyncd.service.d/
28+
cat > /etc/systemd/system/systemd-timesyncd.service.d/override.conf << EOF
29+
[Unit]
30+
ConditionVirtualization=
31+
EOF
32+
33+
# Wait for systemd then start timesyncd
34+
(
35+
until systemctl is-system-running -q; do
36+
sleep 1
37+
done
38+
systemctl enable systemd-timesyncd
39+
systemctl start systemd-timesyncd
40+
) &
2741

2842
# Launch the system
2943
exec /sbin/init

e2e/cluster/docker/container.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func (c *Container) WaitForSystemd() {
200200
c.t.Fatalf("timeout waiting for systemd to start: %v: %s: %s", err, stdout, stderr)
201201
case <-tick:
202202
status, _, _ := c.Exec([]string{"systemctl is-system-running"})
203-
c.t.Logf("systemd stdout: %s", strings.TrimSpace(status))
203+
c.t.Logf("systemd stdout: %s", status)
204204
if strings.TrimSpace(status) == "running" {
205205
return
206206
}
@@ -214,12 +214,12 @@ func (c *Container) WaitForClockSync() {
214214
for {
215215
select {
216216
case <-timeout:
217-
stdout, stderr, err := c.Exec([]string{"chronyc tracking"})
218-
c.t.Fatalf("timeout waiting for chronyd to start: %v: %s: %s", err, stdout, stderr)
217+
stdout, stderr, err := c.Exec([]string{"timedatectl show -p NTP -p NTPSynchronized"})
218+
c.t.Fatalf("timeout waiting for clock sync: %v: %s: %s", err, stdout, stderr)
219219
case <-tick:
220-
status, _, _ := c.Exec([]string{"chronyc tracking | grep 'Leap status'"})
221-
c.t.Logf("chronyd stdout: %s", strings.TrimSpace(status))
222-
if strings.Contains(status, "Normal") {
220+
status, _, _ := c.Exec([]string{"timedatectl show -p NTP -p NTPSynchronized"})
221+
c.t.Logf("timedatectl stdout: %s", status)
222+
if strings.Contains(status, "NTP=yes") && strings.Contains(status, "NTPSynchronized=yes") {
223223
return
224224
}
225225
}

0 commit comments

Comments
 (0)