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

fix: update the simple profile to avoid Container.can_connect #1927

Merged
merged 3 commits into from
Oct 10, 2024

Conversation

tonyandrewmeyer
Copy link
Contributor

Using Container.can_connect as a guard for Pebble is a poor pattern, because it introduces a race condition. We recommend that charms use the "easier to ask forgiveness than permission" pattern by executing the container calls and catching any errors that occur. This PR updates the simple profile to use that pattern.

There are two other small changes:

  • The message in the blocked status was intending to use an f-string, but was just a regular string, so would have always shown the literal text "{log_level}" rather than the value of that variable.
  • WaitingStatus should be used when waiting on an integrated charm, not the local charm. MaintenanceStatus is the correct class to use when waiting on the local charm.

@tonyandrewmeyer tonyandrewmeyer marked this pull request as draft September 26, 2024 23:54
@tonyandrewmeyer tonyandrewmeyer marked this pull request as ready for review September 27, 2024 03:32
Copy link
Collaborator

@lengau lengau left a comment

Choose a reason for hiding this comment

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

Always great to see improvements like this. Thanks!

@lengau lengau requested a review from a team October 8, 2024 12:17
@lengau lengau added this pull request to the merge queue Oct 10, 2024
Merged via the queue into canonical:main with commit 71a2b6c Oct 10, 2024
22 of 23 checks passed
@tonyandrewmeyer tonyandrewmeyer deleted the avoid-can-connect branch October 10, 2024 22:33
lengau pushed a commit that referenced this pull request Oct 11, 2024
Using `Container.can_connect` as a guard for Pebble is a poor pattern,
because it introduces a race condition. We recommend that charms use the
"easier to ask forgiveness than permission" pattern by executing the
container calls and catching any errors that occur. This PR updates the
`simple` profile to use that pattern.

There are two other small changes:
* The message in the blocked status was intending to use an f-string,
but was just a regular string, so would have always shown the literal
text "{log_level}" rather than the value of that variable.
* `WaitingStatus` should be used when waiting on an integrated charm,
not the local charm. `MaintenanceStatus` is the correct class to use
when waiting on the local charm.
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.

3 participants