cloud-id: publish /run/cloud-init/cloud-id-<cloud-type> files#1244
Conversation
|
Looks good to me! @blackboxsw Would something like this be sufficient to make sure the file would be in place and condition on it in a systemd unit? Also, since the content of this new file is the cloud-id as well, could the cat /run/cloud-init/cloud-id? |
I think you might have to use a systemd.path type unit because you want to get activated via inotify events on a running system, not just initial systemd boot goal compilation. Here's what I'm thinking:
@orndorffgrant thanks for the once over here. Yes I was definitely thinking we can address that optimization in a separate PR. There is a potential for inconsistency in cloud-id continuing to properly represent the 'disabled' status if the /run/cloud-init/cloud-id file was also present on the system. I was thinking we'd follow up with a separate PR for that discussion as it could lead to some refactoring that I expect will be a bit of back and forth. |
TheRealFalcon
left a comment
There was a problem hiding this comment.
Some minor comments inline, but LGTM. I think you can go ahead with integration tests.
| prev_cloud_id_file = cloud_id_file | ||
| util.sym_link(f"{cloud_id_file}-{cloud_id}", cloud_id_file, force=True) | ||
| if prev_cloud_id_file != cloud_id_file: | ||
| util.del_file(prev_cloud_id_file) |
There was a problem hiding this comment.
Is this necessary? /run/cloud-init gets removed every boot. Do we support changing a datasource post-boot? It doesn't hurt anything though.
There was a problem hiding this comment.
I know of some AWS customers whose upgrade and deployment strategy involves executing cloud-init clean --logs; cloud-init init --locl; cloud-init init. If someone injected NoCloud seed files before upgrade I could see a stale /run/cloud-init/cloud-id-ec2 left around instead of /run/cloud-init/cloud-id-no-cloud. Just didn't want occasion to have artifactts around that are no longer correct. There also may be folks that live-migrate a VM to a sandboxed environment which may no longer have visibility to the original IMDS. If they trigger a persist_instance_data() we'd want to cleanup any no longer applicable DS in case something else reacts to it's presence.
Not sure there's an easy way around that. If I write /etc/cloud/cloud-init.disabled, until I reboot |
9989124 to
48ec41f
Compare
I think having both of these in the path unit will make it react to either of them - it isn't a logical and. A potential issue I see could be the type=oneshot, that considers you "active" after exiting.
This PR is about cloud-init providing that data, right now I do not have in mind how your daemon works - maybe it is enough to start and stay up? Could you ensure when trying that a late update of the json after the service has been started once already indeed does what you want? |
|
@blackboxsw I have one more integration test suggestion. I think we should add a check (probably as a separate test in the test combined class) that |
Hi sorry I missed this comment yesterday. Based on my testing, ua only needs Because cloud-inits services are Moving beyond the scope of this PR, but as far as the other dependency on machine-token.json, that is handled with a That is sufficient to make sure the daemon doesn't start when the machine is already attached to UA. Instead of using a .path to detect when that file changes automagically, I'm just adding a call to start/stop the daemon appropriately when |
Once a valid datasource is detected, publish the following artifacts to expedite cloud-identification without having to invoke cloud-id from shell scripts or sheling out from python. These files can also be relied on in systemd ConditionPathExists directives to limit execution of services and units to specific clouds. /run/cloud-init/cloud-id: - A symlink with content that is the canonical cloud-id of the datasource detected. This content is the same lower-case value as the output of /usr/bin/cloud-id. /run/cloud-init/cloud-id-<canonical-cloud-id>: - A single file which will contain the canonical cloud-id encoded in the filename
48ec41f to
5731a01
Compare
instnace.read_from_file rstrips white space to integration tests will expect dropped trailing newline.
44fa8f5 to
13ec578
Compare
Once a valid datasource is detected, publish the following artifacts
to expedite cloud-identification without having to invoke cloud-id from
shell scripts or sheling out from python.
These files can also be relied on in systemd ConditionPathExists
directives to limit execution of services and units to specific
clouds.
/run/cloud-init/cloud-id:
as the output of /usr/bin/cloud-id.
/run/cloud-init/cloud-id-<canonical-cloud-id>:
in the filename
Proposed Commit Message
Additional Context
Test Steps
Checklist: