Skip to content

Commit

Permalink
templates: add node-valid-hostname.service for hostname check
Browse files Browse the repository at this point in the history
This seeks to address the problem with "localhost" nodes attempting to
join a cluster by holding up network-online.target until the node gets a
valid hostname (not localhost).

Bug 1845885: race condition during installation between nodes getting their
             hostnames and crio+kubelet starting

Signed-off-by: Ben Howard <ben.howard@redhat.com>
  • Loading branch information
Ben Howard committed Jun 16, 2020
1 parent 6581715 commit cb12bb8
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions templates/common/_base/units/node-valid-hostname.service
@@ -0,0 +1,24 @@
name: node-valid-hostname.service
enabled: true
contents: |
[Unit]
Description=Ensure hostname is not localhost
# Only run when the host has a localhost name.
ConditionHost=|localhost
ConditionHost=|localhost.localdomain
Before=network-online.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStartPre=/bin/echo "Node has localhost hostname. Waiting for new hostname."
# Get the short hostname. This is more reliable than a regex.
ExecStartPre=/bin/bash -c 'while [ `hostname -s` == "localhost" ]; do sleep 1; done;'
ExecStart=/bin/sh -c "echo Node changed hostname to `hostname`"
# Wait up to 5min for the node to get a real hostname.
TimeoutSec=300

[Install]
WantedBy=multi-user.target
# Ensure that network-online.target will not complete until the node has a real hostname.
RequiredBy=network-online.target

0 comments on commit cb12bb8

Please sign in to comment.