From 631db8912255db54551e2a54f4709ccd70bd6d14 Mon Sep 17 00:00:00 2001 From: Ben Howard Date: Thu, 12 Nov 2020 11:22:39 -0700 Subject: [PATCH 1/2] templates: use Afterburn for setting GCP hostnames The only platform where over-log hostnames have been encountered is on GCP. The code has proven buggy, racy and caused a bunch of BZ. To unwind this mess, on GCP, the new behavior: - leaves disabling NetworkManager on GCP - on each boot run Afterburn to fetch the hostname and writes it an ephemeral location - uses the existing checks to truncate the length Finally, this DROPS the NetworkManager dispatcher. FCOS/RHCOS is pursuing a more permanent solution. Signed-off-by: Ben Howard --- ...manager-dispatcher.d-90-long-hostname.yaml | 32 ------------------- .../gcp/units/gcp-hostname.service.yaml | 21 ++++++++++++ 2 files changed, 21 insertions(+), 32 deletions(-) delete mode 100644 templates/common/_base/files/etc-networkmanager-dispatcher.d-90-long-hostname.yaml create mode 100644 templates/common/gcp/units/gcp-hostname.service.yaml diff --git a/templates/common/_base/files/etc-networkmanager-dispatcher.d-90-long-hostname.yaml b/templates/common/_base/files/etc-networkmanager-dispatcher.d-90-long-hostname.yaml deleted file mode 100644 index 4465f5e71a..0000000000 --- a/templates/common/_base/files/etc-networkmanager-dispatcher.d-90-long-hostname.yaml +++ /dev/null @@ -1,32 +0,0 @@ -mode: 0755 -path: "/etc/NetworkManager/dispatcher.d/90-long-hostname" -contents: - inline: | - #!/bin/bash - # - # 90-long-hostname is a wrapper around /usr/local/sbin/set-valid-hostname.sh, - # which ensures that a node has a valid hostname. - IF=$1 - STATUS=$2 - - log() { logger --tag "network-manager/$(basename $0)" "${@}"; } - - if [[ ! "$STATUS" =~ (up|hostname|dhcp4-change|dhcp6-change) ]]; then - exit 0 - fi - - kn="$(< /proc/sys/kernel/hostname)" - if [[ ! "${kn}" =~ (localhost|localhost.localdomain) ]] && [ "${#kn}" -le 63 ]; then - log "hostname is already set" - exit 0 - fi - - # source the script since NetworkManager execution rules do - # allow sourcing from /usr/local. RHCOS has an read-only rootfs - # which limits where this can be stashed. - source /usr/local/sbin/set-valid-hostname.sh - host_name="${DHCP4_HOST_NAME:-$DHCP6_HOST_NAME}" - - if [ -n "${host_name}" ]; then - set_valid_hostname "${host_name}" - fi diff --git a/templates/common/gcp/units/gcp-hostname.service.yaml b/templates/common/gcp/units/gcp-hostname.service.yaml new file mode 100644 index 0000000000..ef18a614e1 --- /dev/null +++ b/templates/common/gcp/units/gcp-hostname.service.yaml @@ -0,0 +1,21 @@ +name: gcp-hostname.service +enabled: true +contents: | + [Unit] + Description=Set GCP Transient Hostname + # Block services relying on Networking being up. + Before=network-online.target + # Wait for NetworkManager to report its online + After=NetworkManager-wait-online.service + # Run before hostname checks + Before=node-valid-hostname.service + + [Service] + Type=oneshot + RemainAfterExit=yes + ExecStartPre=/usr/bin/afterburn --provider gcp --hostname=/run/afterburn.hostname + ExecStart=/bin/bash -c "source /usr/local/sbin/set-valid-hostname.sh; set_valid_hostname `cat /run/afterburn.hostname`" + + [Install] + WantedBy=multi-user.target + WantedBy=network-online.target From 0a646d2a30f9f6082ca63bcc23ad48fd30127780 Mon Sep 17 00:00:00 2001 From: Ben Howard Date: Tue, 17 Nov 2020 06:46:01 -0700 Subject: [PATCH 2/2] Update templates/common/gcp/units/gcp-hostname.service.yaml Co-authored-by: Vadim Rutkovsky --- templates/common/gcp/units/gcp-hostname.service.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/common/gcp/units/gcp-hostname.service.yaml b/templates/common/gcp/units/gcp-hostname.service.yaml index ef18a614e1..d89c109a96 100644 --- a/templates/common/gcp/units/gcp-hostname.service.yaml +++ b/templates/common/gcp/units/gcp-hostname.service.yaml @@ -3,6 +3,8 @@ enabled: true contents: | [Unit] Description=Set GCP Transient Hostname + # Removal of this file signals firstboot completion + ConditionPathExists=!/etc/ignition-machine-config-encapsulated.json # Block services relying on Networking being up. Before=network-online.target # Wait for NetworkManager to report its online