Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ptp_kvm to coreos-platform-chrony system-generator #2263

Merged
merged 2 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ConditionKernelCommandLine=|ignition.platform.id=azurestack
ConditionKernelCommandLine=|ignition.platform.id=azure
ConditionKernelCommandLine=|ignition.platform.id=aws
ConditionKernelCommandLine=|ignition.platform.id=gcp
ConditionKernelCommandLine=|ignition.platform.id=qemu
Before=NetworkManager.service
Before=chronyd.service

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ if ! cmp {/usr,}/etc/chrony.conf >/dev/null; then
exit 0
fi

mkdir -p /run/coreos
confpath=/run/coreos/platform-chrony.conf
altenvfilepath=/run/coreos/sysconfig-chrony
cmdline=( $(</proc/cmdline) )
cmdline_arg() {
local name="$1" value
Expand All @@ -34,19 +31,33 @@ cmdline_arg() {
}
platform=$(cmdline_arg ignition.platform.id)

# Exit early if the ptp_kvm module can't be loaded for the qemu platform
if [[ ${platform} == "qemu" ]]; then
modprobe -q ptp_kvm || exit 0
fi

mkdir -p /run/coreos
confpath=/run/coreos/platform-chrony.conf
altenvfilepath=/run/coreos/sysconfig-chrony

# If not set already (by host customization or this script), set
# PEERNTP=no so that DHCP-provided NTP servers are not added to chrony.
# By doing this we assume the better NTP server choice is the
# platform-provided link-local NTP server rather than others from DHCP.
# TODO: once https://bugzilla.redhat.com/show_bug.cgi?id=1828434 is
# resolved, this won't be required.
if [ ! -e /etc/sysconfig/network ] || ! grep -q "PEERNTP" /etc/sysconfig/network; then
cat <<EOF >> /etc/sysconfig/network
# Historically on QEMU, we haven't been disabling PEERNTP. Let's keep doing
# that even if we have ptp_kvm. chrony will just use the NTP servers as
# additional sources.
if [[ ${platform} != "qemu" ]]; then
cat <<EOF >> /etc/sysconfig/network
# PEERNTP=no is automatically added by default when a platform-provided time
# source is available, but this behavior may be overridden through an Ignition
# config specifying PEERNTP=yes. See https://github.com/coreos/fedora-coreos-config/pull/412.
PEERNTP=no
EOF
fi
fi

(echo "# Generated by $self - do not edit directly"
Expand Down Expand Up @@ -77,6 +88,11 @@ case "${platform}" in
echo '# and https://cloud.google.com/compute/docs/images/configuring-imported-images'
echo 'server metadata.google.internal prefer iburst'
) >> "${confpath}" ;;
qemu)
sed -i s,'^#pool,pool,' "${confpath}"
(echo '# KVM virtual PHC'
echo 'refclock PHC /dev/ptp0 poll 2'
) >> "${confpath}" ;;
*) echo "should not be reached" 1>&2; exit 1 ;;
esac
# Policy doesn't allow chronyd to read run_t
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
## kola:
## exclusive: false
## platforms: "aws azure gce"
## platforms: "aws azure gce qemu"
#
# Test the coreos-platform-chrony generator.

Expand All @@ -14,5 +14,11 @@ case "${platform}" in
aws) chronyc sources |grep '169.254.169.123'; echo "ok chrony aws" ;;
azure) chronyc sources |grep 'PHC'; echo "ok chrony azure" ;;
gcp) chronyc sources | grep '169.254.169.254'; echo "ok chrony gcp" ;;
qemu)
# ptp_kvm isn't available on all arches nor all hosts, so don't assume it's always there; see
# https://github.com/coreos/fedora-coreos-config/pull/2263#discussion_r1157694192
if lsmod | grep -q ptp_kvm; then
chronyc sources | grep 'PHC0'; echo "ok chrony qemu"
fi ;;
*) echo "unhandled platform ${platform} ?"; exit 1 ;;
esac