-
Notifications
You must be signed in to change notification settings - Fork 883
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
feat: check for create_hostname_file key before writing /etc/hostname #4330
Conversation
BSDs store the hostname in I can help bring it to feature parity |
@igalic Thank you for the offer! Looking through the BSD distro code, it looked to me like BSD and FreeBSD did update |
The |
Bikeshed schema key suggestion: having our preexisting "write_etc_hostname": {
"type": "string",
"default": true,
"description": "When true, statically set hostname across reboots by writing the appropriate hostname file under /etc with the preferred value from user-data and meta-data. Systemd prefers /etc/hostname, FreeBSD ``/etc/rc.conf`` or /etc/myname. Default: ``true``"
}, Also, given BSDs will be using different etc files for persisting hostname maybe it's not ideal to call out etc_hostname specifcally? 2nd alternative |
Re: keyname The original intention of this key would be to still write the file if it already existed. If it's named |
0e0767c
to
fac2306
Compare
@igalic (and anyone else with an opinion) what would you consider the correct BSD behavior if the I'm still looking into the OpenBSD |
@catmsred |
…ostname Some users would like to be able to bring up their systems without automatically creating /etc/hostname if it does not exist already. On distros with systemd, the hostname/hostnamectl command can be used to set the hostname transiently (which does not create /etc/hostname). To support this without changing previous behavior (that cloud-init will set the hostname statically and create /etc/hostname if it does not already exist), this change proposes a new key preserve_etchostname_state which is true, sets the hostname transiently and if not present or False, sets it statically. This change does not effect BSD or OpenBSD (or any distros that inherit their _write_hostname), as their hostname management does not use an /etc/hostname file.
Changed the key name for creating the hostname file if it does not exist to create_hostname_file since that is more intuitive the the previously proposed preserve_hostname_state. This commit still excludes BSD instances.
The new create_hostname_file is necessary for the distro to be aware of. This change adds create_hostname_file to the cfg distro uses when it runs cc_set_hostname and cc_update_hostname.
This config adds unit tests for all the non-BSD updated cc_set_hostname calls for the create_hostname_file being set to False (i.e. testing that the file is not created)
This commit normalizes the opensuse create_hostname_file variable to match the other distros.
ed5714d
to
b2537b5
Compare
@s-makin
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @catmsred, for improving cloud-init. I did a superficial review.
New cloud-config keys need to be added to the json-schema, in order to be validated and documented.
So adding something like #4330 (comment) including #4330 (comment) will do it.
If you want to validate the rendered documentation, execute:
tox -e doc && (cd doc/rtd_html/ && python -m http.server)
open http://0.0.0.0:8000
Add new create_hostname_file key to the schema for cc_set_hostname and cc_update_hostname so it is correctly documented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, looks great, thanks. I have left inline requests to fix/improve some things.
In addition to that, could you please reference, in the PR main comment, the Jira and SF tickets associated to this PR for future back tracing?
When key name was updated from preserve_etc_hostname_status to create_hostname_file, the opensuse logic was not correctly updated. This commit brings opensuse into alignment with the correct create_hostname_file key logic that is implemented in other distros.
create_hostname_file should be true by default. This change correctly sets that value as well as expanding the description to clarify the behavior on systemd distros.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks, @catmsred.
Proposed Commit Message
Test Steps
This change adds unit tests for all non-BSD distributions to ensure that if the create_hostname_file key is set to False, their hostname files are not created. The existing test_cc_set_hostname tests look for /etc/hostname to confirm the hostname has been set correctly so they provide validation that without the create_hostname_file key, there are no regressions in behaviour.
References
Jira card: https://warthogs.atlassian.net/browse/SC-1588
SF case: https://canonical.lightning.force.com/lightning/r/Case/5008e00000EHIhYAAX/view
Checklist: