Conversation
While setting the hostname as a FQDN is perfectly valid, in most cases the expectation is that /etc/hostname holds the short form hostname and the FQDN is added as a canonical hostname, i.e. as the first column in /etc/hosts after the local IP address. This will allow clients to use: hostname -f to get the fqdn and still be able to get the host form hostname by calling: hostname Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
|
We arrived at Afterburn's current hostname policy after much debate and debugging, and changing it would likely break existing users. If you'd like to add a command-line option to write only the hostname part, we could consider it. |
|
Fair enough! Would a similar command line option like |
|
Works for me. Note that there isn't a great way to configure the |
|
I was a bit sparse on context 😄 . The need for this came up recently when we noticed that we can't bring up a k8s cluster on OpenStack using Flatcar as a base OS with For OpenStack we have a fix merged in coreos-cloudinit, but the goal is to eventually use afterburn to set the hostname. The short hostname option will most likely be (eventually) included in future releases of Flatcar. |
|
Ah, okay, cool. Happy to ship a command-line option to be invoked by a distro that integrates Afterburn. |
The --short command line option is a bool which requires the --hostname option and which will toggles writing the short form hostname to /etc/hostname. Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
|
I added a new boolean flag This is my first interaction with rust, so let me know if the changes are not idiomatic or just plain silly 😄. |
|
Here is an example of the new flag in action. Without the control-plane-nova-dkfvy2 ~ # ./afterburn --provider openstack-metadata --hostname=/root/test
May 16 14:51:15.352 INFO Fetching http://169.254.169.254/latest/meta-data/hostname: Attempt #1
May 16 14:51:15.542 INFO Fetch successful
May 16 14:51:15.542 INFO wrote hostname control-plane-nova-dkfvy2.novalocal to /root/test
control-plane-nova-dkfvy2 ~ # cat /root/test
control-plane-nova-dkfvy2.novalocalWith the control-plane-nova-dkfvy2 ~ # ./afterburn --provider openstack-metadata --short --hostname=/root/test
May 16 14:51:24.876 INFO Fetching http://169.254.169.254/latest/meta-data/hostname: Attempt #1
May 16 14:51:24.908 INFO Fetch successful
May 16 14:51:24.908 INFO wrote hostname control-plane-nova-dkfvy2 to /root/test
control-plane-nova-dkfvy2 ~ # cat /root/test
control-plane-nova-dkfvy2For systems that don't explicitly set the new flag, things work as they did before. Opting to use the new flag will set the short form hostname. |
bgilbert
left a comment
There was a problem hiding this comment.
Your first commit is a development checkpoint rather than an incremental logical change, so please squash it. CI also expects a release note to be added in docs/release-notes.md.
| hostname_file: Option<String>, | ||
| /// Parse the hostname retrieved from metadata as a short hostname | ||
| #[arg(long = "short", requires = "hostname")] | ||
| short_hostname: bool, |
There was a problem hiding this comment.
I think I prefer your original idea of having --short-hostname=/etc/hostname. Rather than adding a mode switch that controls the behavior of another option, let's just support --hostname and --short-hostname as two output switches that operate independently.
| assert_eq!( | ||
| try_write_hostname("hostname7.example.com", true), | ||
| "hostname7" | ||
| ); |
There was a problem hiding this comment.
Let's at least also test short hostnames where the input value doesn't have an FQDN.
|
Thanks for the PR! I won't be able to do future review rounds on this, unfortunately, but hopefully someone else on the team can take a look. Closing/reopening to kick CI. |
|
Thanks for the review @bgilbert ! I will make the changes today and push them. |
While setting the hostname as a FQDN is perfectly valid, in most cases the expectation is that
/etc/hostnameholds the short form hostname and the FQDN is added as a canonical hostname, i.e. as the first column in/etc/hostsafter the local IP address.This will allow clients to use:
to get the fqdn and still be able to get the short form hostname by calling: