Properly parse hostname from metadata#19
Merged
jepio merged 2 commits intoflatcar:flatcar-masterfrom May 11, 2023
Merged
Conversation
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>
jepio
reviewed
May 10, 2023
jepio
approved these changes
May 10, 2023
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 @jepio Should I split by space and then by dot, or would you prefer I change the test? |
Member
|
I think it's fine to fix the test case. |
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>
b7e25d1 to
247df6d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/hostnamewill contain a proper short form hostname instead of a FQDN.How to use
Build and then run:
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/directory (user-facing change, bug fix, security fix, update)/bootand/usrsize, packages, list files for any missing binaries, kernel modules, config files, kernel modules, etc.