afterburn icon indicating copy to clipboard operation
afterburn copied to clipboard

Write short form hostname

Open gabriel-samfira opened this issue 2 years ago • 9 comments

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
arrakis.local

to get the fqdn and still be able to get the short form hostname by calling:

:~$ hostname
arrakis

gabriel-samfira avatar May 11 '23 19:05 gabriel-samfira

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.

bgilbert avatar May 11 '23 19:05 bgilbert

Fair enough! Would a similar command line option like --short-hostname=/etc/hostname be ok? (I am terrible at naming things).

gabriel-samfira avatar May 11 '23 19:05 gabriel-samfira

Works for me. Note that there isn't a great way to configure the afterburn-hostname.service service at runtime, since it runs in the initrd. (For example, Ignition can't reconfigure the initrd.) So, if you wanted to use this, you'd have to configure a custom unit that runs in the booted system, which probably means you'd be setting the hostname after things have already started using the old one.

bgilbert avatar May 11 '23 19:05 bgilbert

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 kops. Here is the relevant issue with more context: https://github.com/kubernetes/kops/issues/15385

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.

gabriel-samfira avatar May 11 '23 20:05 gabriel-samfira

Ah, okay, cool. Happy to ship a command-line option to be invoked by a distro that integrates Afterburn.

bgilbert avatar May 11 '23 20:05 bgilbert

I added a new boolean flag --short and placed the --hostname in a group. The --short flag requires the --hostname flag and toggles whether or not to write the short form hostname. I also added a new test.

This is my first interaction with rust, so let me know if the changes are not idiomatic or just plain silly :smile:.

gabriel-samfira avatar May 12 '23 07:05 gabriel-samfira

Here is an example of the new flag in action.

Without the --short flag:

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.novalocal

With the --short flag:

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-dkfvy2

For 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.

gabriel-samfira avatar May 16 '23 14:05 gabriel-samfira

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.

bgilbert avatar Aug 01 '23 07:08 bgilbert

Thanks for the review @bgilbert !

I will make the changes today and push them.

gabriel-samfira avatar Aug 02 '23 10:08 gabriel-samfira