Skip to content

Conversation

@alithethird
Copy link
Contributor

@alithethird alithethird commented Feb 11, 2025

Overview

Some applications require certain configuration options to function correctly. With this PR when a non-optional config option is missing, the charm will go into the blocked state with a message telling which config options are missing.

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.

Module Changes

2 new functions in paas_charm.charm_state.py are added to create the AppConfig class from the list of configuration options:

  • app_config_factory
  • _create_configuration_attribute

paas_charm.utils.build_validation_error_message function is changed. Now it returns a tuple of 2 strings.

The tuple consists of:

  • A list of error fields from a pydantic exception to print at charm status.
  • A detailed list of error fields from a pydantic exception with their error
    messages. Best fit for printing error logs.

A new function in paas_charm.utils.py:

  • is_user_defined_config: This function checks whether a config option is user-defined.

Add a new folder to unit tests to check functions not affected by the framework.
Add a new folder to integration tests to check functionality in every framework by parametrizing the framework. This way we only need to write 1 function to test functionality in every framework.

Checklist

@alithethird alithethird added enhancement New feature or request trivial labels Feb 11, 2025
@alithethird alithethird self-assigned this Feb 11, 2025
@alithethird alithethird requested a review from a team as a code owner February 11, 2025 10:15
@alithethird alithethird changed the title Feat(Interface): Interface commit. Feat(Block on missing config): Interface commit Feb 11, 2025
@alithethird alithethird requested review from jdkandersson and removed request for nrobinaubertin and weiiwang01 February 11, 2025 10:32
@jdkandersson
Copy link
Contributor

Is this fully ready? At the interface PR stage, this should be marked as draft please

@alithethird alithethird marked this pull request as draft February 17, 2025 04:02
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

license-eye has checked 283 files.

Valid Invalid Ignored Fixed
155 1 127 0
Click to see the invalid file list
  • tests/unit/general/conftest.py
Use this command to fix any missing license headers
```bash

docker run -it --rm -v $(pwd):/github/workspace apache/skywalking-eyes header fix

</details>

@alithethird alithethird changed the title Feat(Block on missing config): Interface commit Feat(Block on missing config) Feb 19, 2025
@alithethird alithethird marked this pull request as ready for review February 20, 2025 11:49
Copy link
Contributor

@jdkandersson jdkandersson left a comment

Choose a reason for hiding this comment

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

Please remember to update the charmcraft docs

@alithethird alithethird merged commit 122ed19 into main Feb 24, 2025
119 checks passed
@alithethird alithethird deleted the feat/block-on-missing branch February 24, 2025 13:23
github-merge-queue bot pushed a commit to canonical/charmcraft that referenced this pull request Feb 26, 2025
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request trivial

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants