-
Notifications
You must be signed in to change notification settings - Fork 918
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
Doc drop in 3rd party modules #5548
Merged
blackboxsw
merged 6 commits into
canonical:main
from
aciba90:doc-drop-in-3rd-party-modules
Jul 26, 2024
+175
−82
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3244c80
doc: restructure existent drop-in functionality (#5548)
aciba90 cf93b5d
doc: add doc for custom datasources (#5548)
aciba90 6284aa2
doc: add doc for custom config modules (#5548)
aciba90 c3a3eb7
comments
aciba90 b21f0f6
more comments
aciba90 c635543
chore: rename custom_cleaers -> custom_clean_scripts
blackboxsw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Custom Modules | ||
************** | ||
|
||
This includes reference documentation on how to extend cloud-init with | ||
custom / out-of-tree functionality. | ||
|
||
.. _custom_formats: | ||
|
||
Custom Formats | ||
============== | ||
|
||
One can define custom data formats by presenting a | ||
:ref:`#part-handler<user_data_formats-part_handler>` | ||
config via user-data or vendor-data. | ||
|
||
----- | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
|
||
custom_modules/custom_clean_scripts.rst | ||
custom_modules/custom_configuration_module.rst | ||
custom_modules/custom_datasource.rst | ||
custom_modules/custom_mergers.rst |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.. _custom_clean_scripts: | ||
|
||
Custom Clean Scripts | ||
******************** | ||
|
||
Cloud-init provides the directory :file:`/etc/cloud/clean.d/` for third party | ||
applications which need additional configuration artifact cleanup from | ||
the filesystem when the :ref:`cloud-init clean<cli_clean>` command is invoked. | ||
|
||
The :command:`clean` operation is typically performed by image creators | ||
when preparing a golden image for clone and redeployment. The clean command | ||
removes any cloud-init internal state, allowing cloud-init to treat the next | ||
boot of this image as the "first boot". | ||
Any executable scripts in this subdirectory will be invoked in lexicographical | ||
order when running the :command:`clean` command. | ||
|
||
Example | ||
======= | ||
|
||
.. code-block:: bash | ||
|
||
$ cat /etc/cloud/clean.d/99-live-installer | ||
#!/bin/sh | ||
sudo rm -rf /var/lib/installer_imgs/ | ||
sudo rm -rf /var/log/installer/ |
23 changes: 23 additions & 0 deletions
23
doc/rtd/reference/custom_modules/custom_configuration_module.rst
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.. _custom_configuration_module: | ||
|
||
Custom Configuration Module | ||
*************************** | ||
|
||
Custom 3rd-party out-of-tree configuration modules can be added to cloud-init | ||
by: | ||
|
||
#. :ref:`Implement a config module<module_creation>` in a Python file with its | ||
name starting with ``cc_``. | ||
|
||
#. Place the file where the rest of config modules are located. | ||
On Ubuntu this path is typically: | ||
`/usr/lib/python3/dist-packages/cloudinit/config/`. | ||
|
||
#. Extend the :ref:`base-configuration's <base_config_module_keys>` | ||
``cloud_init_modules``, ``cloud_config_modules`` or ``cloud_final_modules`` | ||
to let the config module run on one of those stages. | ||
aciba90 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.. warning :: | ||
The config jsonschema validation functionality is going to complain about | ||
unknown config keys introduced by custom modules and there is not an easy | ||
way for custom modules to define their keys schema-wise. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.. _custom_datasource: | ||
|
||
Custom DataSource | ||
***************** | ||
|
||
Custom 3rd-party out-of-tree DataSources can be added to cloud-init by: | ||
|
||
#. :ref:`Implement a DataSource<datasource_creation>` in a Python file. | ||
|
||
#. Place that file in as a single Python module or package in folder included | ||
in ``$PYTHONPATH``. | ||
|
||
#. Extend the base configuration's | ||
:ref:`datasource_pkg_list<base_config_datasource_pkg_list>` to include the | ||
Python package where the DataSource is located. | ||
|
||
#. Extend the :ref:`base-configuration<base_config_reference>`'s | ||
:ref:`datasource_list<base_config_datasource_list>` to include the name of | ||
the custom DataSource. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
.. _custom_mergers: | ||
aciba90 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Custom Mergers | ||
************** | ||
|
||
It is possible for users to inject their own :ref:`merging<merging_user_data>` | ||
files to handle specific types of merging as they choose (the | ||
basic ones included will handle lists, dicts, and strings). | ||
|
||
A `merge class` is a class definition providing functions that can be used | ||
to merge a given type with another given type. | ||
|
||
An example of one of these `merging classes` is the following: | ||
|
||
.. code-block:: python | ||
|
||
class Merger: | ||
def __init__(self, merger, opts): | ||
self._merger = merger | ||
self._overwrite = 'overwrite' in opts | ||
|
||
# This merging algorithm will attempt to merge with | ||
# another dictionary, on encountering any other type of object | ||
# it will not merge with said object, but will instead return | ||
# the original value | ||
# | ||
# On encountering a dictionary, it will create a new dictionary | ||
# composed of the original and the one to merge with, if 'overwrite' | ||
# is enabled then keys that exist in the original will be overwritten | ||
# by keys in the one to merge with (and associated values). Otherwise | ||
# if not in overwrite mode the 2 conflicting keys themselves will | ||
# be merged. | ||
def _on_dict(self, value, merge_with): | ||
if not isinstance(merge_with, (dict)): | ||
return value | ||
merged = dict(value) | ||
for (k, v) in merge_with.items(): | ||
if k in merged: | ||
if not self._overwrite: | ||
merged[k] = self._merger.merge(merged[k], v) | ||
else: | ||
merged[k] = v | ||
else: | ||
merged[k] = v | ||
return merged | ||
|
||
There is an ``_on_dict`` method here that will be given a | ||
source value, and a value to merge with. The result will be the merged object. | ||
|
||
This code itself is called by another merging class which "directs" the | ||
merging to happen by analysing the object types to merge, and attempting to | ||
find a known object that will merge that type. An example of this can be found | ||
in the :file:`mergers/__init__.py` file (see ``LookupMerger`` and | ||
``UnknownMerger``). | ||
|
||
Note how each | ||
merge can have options associated with it, which affect how the merging is | ||
performed. For example, a dictionary merger can be told to overwrite instead | ||
of attempting to merge, or a string merger can be told to append strings | ||
instead of discarding other strings to merge with. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,4 @@ matrices and so on. | |
ubuntu_stable_release_updates.rst | ||
breaking_changes.rst | ||
user_files.rst | ||
custom_modules.rst |
This file contains 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
Oops, something went wrong.
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.
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.
I'm wondering if the referenced page wouldn't make more sense here than in the dev docs. What do you think? There may be some overlap in the intent, but since the intent is that users should be able to do this I think that having it under the "custom_modules" umbrella makes more sense. I think that as far as contributing goes, there are probably more useful things for new contributors to be thinking about than writing custom configuration modules for niche purposes.
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.
Yes, I think it is okay either way because:
That content is in the gray are where the persona is an advanced user that is consuming cloud-init as a user but is giving input to cloud-init that requires develoment knowledge about cloud-init's internal.
The same question applies for the documentation on how to create a new datasource and for #5559.