feat(profile): add example action to kubernetes and machine init profiles - #2813
Open
tonyandrewmeyer wants to merge 3 commits into
Open
feat(profile): add example action to kubernetes and machine init profiles#2813tonyandrewmeyer wants to merge 3 commits into
tonyandrewmeyer wants to merge 3 commits into
Conversation
Declare pause and resume actions in charmcraft.yaml and handle them in the charm. The pause action stops the workload and leaves the unit deployed in maintenance status; resume starts it again. Both are imperative operations with no config equivalent, which is what actions are for. The workload module gains a stop() stub alongside the existing install() and start(). Unit tests drive each action through ops.testing.Context; an integration test runs the pair against a deployed unit with jubilant.
Declare a restart action in charmcraft.yaml and handle it in the charm: restart the Pebble service, wait for the workload to be ready, and set the unit active again. Rather than checking 'can_connect' first, the handler catches ops.pebble.ConnectionError, so there's no window in which the container stops being reachable between the check and the restart. Unit tests cover both the happy path and the unreachable-container failure, which shows how event.fail() surfaces in ops.testing. An integration test runs the action against a deployed unit with jubilant.
Contributor
Author
|
@dwilding could you please have a look over this? |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Extends both the
kubernetesandmachineprofiles so thatcharmcraft initscaffolds a working example action alongside the existing lifecycle hook code, with unit and integration tests for it.The profile is a strong signal to human and agentic charmers for best practices. Including an example of an action is concrete input without needing the charmer to go find documentation, or have that in training data (human or model).
The actions here were chosen from what charms in the wild actually declare, rather than invented. Across ~400 charms that declare actions,
pause/resumeis by a wide margin the most common pair in machine charms, andrestartis the most common workload-lifecycle action in Kubernetes charms once the copy-paste families are discounted.Changes
Both profiles in
charmcraft.yaml.j2:Adds an
actions:block with links to the charmcraft and Juju reference docs, matching the style of the existingconfig:block.In the
machineprofile,pauseandresume:pausestops the workload and leaves the unit deployed in maintenance status, so an operator can take a unit out of service without removing it;resumestarts it again.src/workload.py.j2gains astop()stub alongside the existinginstall()andstart().In the
kubernetesprofile,restart:Restarts the Pebble service in the workload container, waits for the workload to be ready, and sets the unit active again.
make lint && make test.I've added or updated any relevant documentation.In documents I changed, I added a meta description if one was missing.