-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(extension): Block on missing required config (#2187)
This PR is related to 12 Factor [Block on missing required config PR](canonical/paas-charm#42) ## Rationale Some applications require certain config options to run and would crash if these options are not provided. To prevent this, we need to add an optional field to the config options and block the charm if a config option marked as non-optional has not been provided with a message that explains which config options are missing. To stay backward compatible the default value for the optional field will be true. Since it doesn’t make sense for config options that are non-optional to have a default value, charmcraft will look for this condition at pack time and error out. ## Extension Changes Adds a check for non-optional options with default values and throws `ExtensionError` when found. Adds documentation about the non-optional options. Reviewers: @jdkandersson @javierdelapuente @erinecon
- Loading branch information
1 parent
ecd6b41
commit c65d0dc
Showing
7 changed files
with
89 additions
and
5 deletions.
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,22 @@ | ||
|
||
In addition to this, you can set the configuration option to be | ||
mandatory by setting the ``optional`` key to ``false``. This will | ||
block the charm and stop services until the configuration is supplied. For example, | ||
if your application needs an ``api-token`` to function correctly you can set | ||
``optional``, as shown below. This will block the charm and stop the | ||
services until the ``api-token`` configuration is supplied. | ||
|
||
.. code-block:: yaml | ||
:caption: charmcraft.yaml | ||
config: | ||
options: | ||
api-token: | ||
description: The token necessary for the service to run. | ||
type: string | ||
optional: false | ||
.. note:: | ||
|
||
A configuration with ``optional: false`` can't also have a ``default`` key. | ||
If it has both, the charm will fail to pack. |
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