canonical / canonical/cloud-init

Metadata fetched twice if cache invalid and BOOT event enabled

Open
#5,114 2 comments 0 reactions 0 assignees View on GitHub
bug priority
Dominant language
Python
Stars
3.8k
Forks
1.1k
Avg merge
2d 23h
Merged PRs (30d)
18

Description

Any datasource that doesn't override [check_instance_id](https://github.com/canonical/cloud-init/blob/4de8dc2a2666b2401221c157373a982372d526f7/cloudinit/sources/__init__.py#L925) will have cache invalidated every boot. This causes cloud-init to fetch IMDS data every boot. Any datasource whose [default_update_events](https://github.com/canonical/cloud-init/blob/4de8dc2a2666b2401221c157373a982372d526f7/cloudinit/sources/__init__.py#L257) include `EventType.BOOT` will also fetch IMDS data every boot.

If both conditions are true for a datasource, the datasource will fetch IMDS data twice every boot. We should instead ensure that it is only fetched once.

We should also consider if we can have a better default implementation of `check_instance_id`. There's a bit of a chicken and egg problem in that we don't know for sure if cache should be invalidated until we get a new instance id, but we often can't know the instance id without querying the IMDS. `check_instance_id` allows us to define an IMDS-less way of checking this, but for datasources that can't rely on a local machine id, invalidating the entire cache every boot is a fairly heavy hammer.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.