Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly parse hostname from metadata #19

Merged
merged 2 commits into from
May 11, 2023

Conversation

gabriel-samfira
Copy link
Member

@gabriel-samfira gabriel-samfira commented May 9, 2023

Properly parse hostname from metadata

This change splits the hostname supplied by the metadata service using dot as a delimiter instead of a single space. This API should return a single FQDN on most clouds.

Sample output from fetching the hostname from the AWS metadata service can be seen here:

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html

OpenStack has the same kind of output.

We also make sure that the resulting hostname is no longer than 63 characters long.

This will ensure that /etc/hostname will contain a proper short form hostname instead of a FQDN.

How to use

Build and then run:

./coreos-cloudinit --oem=ec2-compat

on any VM spun up on a cloud with an ec2 compatible metadata service.

Testing done

Build a flatcar image using this commit and spun up a k8s cluster using kops. Hostname was properly set to the short form, not the FQDN.

Addresses the following issue: kubernetes/kops#15385

  • Changelog entries added in the respective changelog/ directory (user-facing change, bug fix, security fix, update)
  • Inspected CI output for image differences: /boot and /usr size, packages, list files for any missing binaries, kernel modules, config files, kernel modules, etc.

This change splits the hostname supplied by the metadata service using
dot as a delimiter instead of a single space. We also validate that the
resulting hostname is no longer than 63 characters long.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
@gabriel-samfira
Copy link
Member Author

Hmm. The test case expects that we may have more than one hostname set, delimited by an empty space. Is this documented anywhere? From what I could find, there should be only one hostname returned. When multiple NICs are attached, the hostname on eth0 is preferred.

@jepio Should I split by space and then by dot, or would you prefer I change the test?

@jepio
Copy link
Member

jepio commented May 10, 2023

I think it's fine to fix the test case.

@gabriel-samfira
Copy link
Member Author

Added a log message and a new test to validate that truncating the hostname works.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants