diff --git a/templates/common/_base/files/usr-local-bin-mco-hostname.yaml b/templates/common/_base/files/usr-local-bin-mco-hostname.yaml index 6e9da98408..dbe088e122 100644 --- a/templates/common/_base/files/usr-local-bin-mco-hostname.yaml +++ b/templates/common/_base/files/usr-local-bin-mco-hostname.yaml @@ -3,6 +3,8 @@ path: "/usr/local/bin/mco-hostname" contents: inline: | #!/bin/bash + set -euo pipefail + # First, we need to wait until DHCP finishes and the node has a non-`localhost` # hostname before `kubelet.service` starts. # That's the `--wait` argument as used by `node-valid-hostname.service`. @@ -57,9 +59,27 @@ contents: exit 0 } + set_openstack_hostname() { + # Read metadata written by afterburn service + . /run/metadata/afterburn + + # node-valid-hostname sets persistent hostname from /proc/sys/kernel/hostname + echo "$AFTERBURN_OPENSTACK_HOSTNAME" > /proc/sys/kernel/hostname + } + + set_powervs_hostname() { + # Read metadata written by afterburn service + . /run/metadata/afterburn + + # node-valid-hostname sets persistent hostname from /proc/sys/kernel/hostname + echo "$AFTERBURN_POWERVS_LOCAL_HOSTNAME" > /proc/sys/kernel/hostname + } + arg=${1}; shift; case "${arg}" in --wait) wait_localhost;; --gcp) set_gcp_hostname;; + --openstack) set_openstack_hostname;; + --powervs) set_powervs_hostname;; *) echo "Unhandled arg $arg"; exit 1 esac diff --git a/templates/common/openstack/files/usr-local-bin-openstack-afterburn-hostname.yaml b/templates/common/openstack/files/usr-local-bin-openstack-afterburn-hostname.yaml deleted file mode 100644 index 0428a6ae8d..0000000000 --- a/templates/common/openstack/files/usr-local-bin-openstack-afterburn-hostname.yaml +++ /dev/null @@ -1,10 +0,0 @@ -mode: 0755 -path: "/usr/local/bin/openstack-afterburn-hostname" -contents: - inline: | - #!/bin/bash - set -euo pipefail - - # Fetch hostname from OpenStack. Set both transient and static hostnames to - # ensure node-valid-hostname sees the new hostname immediately. - /usr/bin/afterburn --provider openstack --hostname=/dev/stdout | xargs hostnamectl set-hostname diff --git a/templates/common/openstack/units/afterburn-hostname.service.yaml b/templates/common/openstack/units/openstack-hostname.service.yaml similarity index 76% rename from templates/common/openstack/units/afterburn-hostname.service.yaml rename to templates/common/openstack/units/openstack-hostname.service.yaml index 2d3515aaa3..1be98736b1 100644 --- a/templates/common/openstack/units/afterburn-hostname.service.yaml +++ b/templates/common/openstack/units/openstack-hostname.service.yaml @@ -1,4 +1,4 @@ -name: afterburn-hostname.service +name: openstack-hostname.service enabled: true contents: | [Unit] @@ -9,6 +9,9 @@ contents: | After=NetworkManager-wait-online.service # Run before hostname checks Before=node-valid-hostname.service + # We require afterburn to have run first + Requires=afterburn.service + After=afterburn.service [Service] # Would prefer to do Restart=on-failure instead of this bash retry loop, but @@ -16,7 +19,7 @@ contents: | # available in systemd v244 and higher. ExecStart=/bin/bash -c " \ until \ - /usr/local/bin/openstack-afterburn-hostname; \ + /usr/local/bin/mco-hostname --openstack; \ do \ sleep 10; \ done" @@ -26,4 +29,4 @@ contents: | RemainAfterExit=true [Install] - WantedBy=network-online.target + WantedBy=node-valid-hostname.service diff --git a/templates/common/powervs/units/afterburn-hostname.service.yaml b/templates/common/powervs/units/powervs-hostname.service.yaml similarity index 61% rename from templates/common/powervs/units/afterburn-hostname.service.yaml rename to templates/common/powervs/units/powervs-hostname.service.yaml index bba221326a..9205498262 100644 --- a/templates/common/powervs/units/afterburn-hostname.service.yaml +++ b/templates/common/powervs/units/powervs-hostname.service.yaml @@ -1,4 +1,4 @@ -name: afterburn-hostname.service +name: powervs-hostname.service enabled: true contents: | [Unit] @@ -9,10 +9,13 @@ contents: | After=NetworkManager-wait-online.service # Run before hostname checks Before=node-valid-hostname.service + # We require afterburn to have run first + Requires=afterburn.service + After=afterburn.service [Service] - ExecStart=/usr/bin/afterburn --provider powervs --hostname=/etc/hostname Type=oneshot + ExecStart=/usr/local/bin/mco-hostname --powervs [Install] - WantedBy=network-online.target + WantedBy=node-valid-hostname.service