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

Add infra to skip inapplicable modules #1597

Merged
merged 12 commits into from Jul 21, 2022

Conversation

aciba90
Copy link
Contributor

@aciba90 aciba90 commented Jul 15, 2022

Proposed Commit Message

meta-schema: add infra to skip inapplicable modules

Add new `activate_by_schema_keys` property to `MetaSchema` defining
the schema keys that must be present, to avoid skipping the module.
Add this new key to our schema docs.
Add documentation to `topics/module_creation`.

Additional Context

SC-1132
Original draft PR: #1515

Test Steps

$ lxc launch ubuntu-daily:jammy jj
$ lxc exec jj -- grep -i 'no applicable' /var/log/cloud-init.log
2022-07-15 15:15:56,292 - modules.py[INFO]: Skipping modules 'snap' because no applicable config is provided.

Checklist:

  • My code follows the process laid out in the documentation
  • I have updated or added any unit tests accordingly
  • I have updated or added any documentation accordingly

@aciba90 aciba90 force-pushed the poc-skip-inapplicable-modules branch from a2f7c2f to 5b82d30 Compare July 15, 2022 15:07
@aciba90 aciba90 force-pushed the poc-skip-inapplicable-modules branch from 5b82d30 to bfa2f80 Compare July 15, 2022 15:13
@aciba90 aciba90 marked this pull request as ready for review July 15, 2022 15:20
@blackboxsw blackboxsw self-assigned this Jul 19, 2022
Copy link
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aciba90 looks really good and behaves well. A couple of minor comments, one related to moving the importlib changes out of this PR if we can.

I think there could be a possibility that we may not want to continue to do the initial "skip inapplicable" modules check if cloud-config instance-data hasn't changed. But, that is a minor recurring cost per boot during module discovery. It may be nice at some point if we grew the ability to report module status from cloud-init status --long [--format json] that could report whether the module participated in boot, or was skipped (either due to previously running or due to inactivity/inapplicable config). This is not something for this PR, but future feature question for us to discuss long-term.

medium term, maybe for separate PR as well: the write_files vs write_files_deferred case is potentially interesting. If we have write_files: defered: true in config we could skip running the base cc_write_files. This is the only case like this were specific values of config key indicates whether or not to skip the module. But, I think it's a corner case that may not be worth investing time in.

cloudinit/config/schema.py Show resolved Hide resolved
if not meta.get("skip_by_schema"):
return ""
schema_keys = ", ".join(meta["skip_by_schema"])
return f"**Skipped if keys not present:** {schema_keys}\n\n"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😄 on doc updates.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to:

return f"**Activate only if given keys:** {schema_keys}\n\n"

cloudinit/importer.py Outdated Show resolved Hide resolved
cloudinit/config/schema.py Outdated Show resolved Hide resolved
doc/rtd/topics/module_creation.rst Outdated Show resolved Hide resolved
cloudinit/config/schema.py Outdated Show resolved Hide resolved
tests/unittests/config/test_schema.py Outdated Show resolved Hide resolved
tests/unittests/config/test_schema.py Outdated Show resolved Hide resolved
tests/unittests/config/test_schema.py Outdated Show resolved Hide resolved
tests/unittests/config/test_schema.py Outdated Show resolved Hide resolved
@aciba90 aciba90 force-pushed the poc-skip-inapplicable-modules branch from bfa2f80 to 58e89c7 Compare July 20, 2022 09:18
@aciba90
Copy link
Contributor Author

aciba90 commented Jul 20, 2022

A couple of minor comments, one related to moving the importlib changes out of this PR if we can.

Extracted to #1605

I think there could be a possibility that we may not want to continue to do the initial "skip inapplicable" modules check if cloud-config instance-data hasn't changed. But, that is a minor recurring cost per boot during module discovery. It may be nice at some point if we grew the ability to report module status from cloud-init status --long [--format json] that could report whether the module participated in boot, or was skipped (either due to previously running or due to inactivity/inapplicable config). This is not something for this PR, but future feature question for us to discuss long-term.

That would be interesting. Added to SC-1192 to not forget about its discussion.

medium term, maybe for separate PR as well: the write_files vs write_files_deferred case is potentially interesting. If we have write_files: defered: true in config we could skip running the base cc_write_files. This is the only case like this were specific values of config key indicates whether or not to skip the module. But, I think it's a corner case that may not be worth investing time in.

If this is the only corner case, I would say that it is not worth to implement a more complex way to express logic within activate_by_schema_keys. I am thinking about something like:

{
    "activate_by_schema_keys": ["write_files.defered == True"]
}

But if this necessity grows, for sure we could do it.

Thanks, @blackboxsw, for the review and constructive feedback!
I think I have covered all the open topics. Please, have a second review.

@aciba90 aciba90 requested a review from blackboxsw July 20, 2022 09:47
Copy link
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good. one minor rendered text change request (which I realize affects your unit tests). Otherwise +1 from me. I'm testing this now

cloudinit/config/schema.py Show resolved Hide resolved
Comment on lines 916 to 917
schema_keys = ", ".join(meta["activate_by_schema_keys"])
return f"**Activate only if given keys:** {schema_keys}\n\n"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's mark up the key names with ``<key_name>`` to align with other doc config key references. It makes readthedocs decorate it in red.

Suggested change
schema_keys = ", ".join(meta["activate_by_schema_keys"])
return f"**Activate only if given keys:** {schema_keys}\n\n"
schema_keys = ", ".join(
f"``{k}``" for k in meta["activate_by_schema_keys"]
)
return f"**Activate only on keys:** {schema_keys}\n\n"

@holmanb
Copy link
Member

holmanb commented Jul 20, 2022

I think the commit message needs to be updated, but otherwise looks good to me!

@blackboxsw
Copy link
Collaborator

blackboxsw commented Jul 21, 2022

Pushed the minor doc change and will land when CI passes

@blackboxsw blackboxsw merged commit 4564ce6 into canonical:main Jul 21, 2022
@aciba90
Copy link
Contributor Author

aciba90 commented Jul 21, 2022

Thanks, @blackboxsw and @holmanb, for handling and landing this.

@aciba90 aciba90 deleted the poc-skip-inapplicable-modules branch July 21, 2022 07:24
@aciba90 aciba90 mentioned this pull request Jul 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants