From 47d54a38e766a30c7ab9caabf2292e885505ffe0 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Mon, 15 Jan 2024 14:53:11 +0100 Subject: [PATCH] Restore old behavior of not setting empty hostnames The refactoring in https://github.com/flatcar/coreos-cloudinit/pull/21 caused hostnames to be set unconditionally compared to the old behavior of only setting the hostname if it not empty. When running coreos-cloudinit with datasources that do not provide metadata such as the `file` datasource, the refactored code caused the hostname to always be reset to `localhost`. This leads to various problems like preventing k8s nodes from joining their cluster. This change restores the old behavior by not applying empty hostnames. Fixes https://github.com/flatcar/Flatcar/issues/1262 --- initialize/config.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/initialize/config.go b/initialize/config.go index 17931af..e630f91 100644 --- a/initialize/config.go +++ b/initialize/config.go @@ -39,6 +39,9 @@ type CloudConfigUnit interface { } func ApplyHostname(hostname string) error { + if hostname == "" { + return nil + } if err := system.SetHostname(hostname); err != nil { return fmt.Errorf("error setting hostname: %w", err) }