Skip to content

feat(profile): add example action to kubernetes and machine init profiles - #2813

Open
tonyandrewmeyer wants to merge 3 commits into
canonical:mainfrom
tonyandrewmeyer:claude/profile-action
Open

feat(profile): add example action to kubernetes and machine init profiles#2813
tonyandrewmeyer wants to merge 3 commits into
canonical:mainfrom
tonyandrewmeyer:claude/profile-action

Conversation

@tonyandrewmeyer

Copy link
Copy Markdown
Contributor

Extends both the kubernetes and machine profiles so that charmcraft init scaffolds 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/resume is by a wide margin the most common pair in machine charms, and restart is 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 existing config: block.

In the machine profile, pause and resume:

pause stops the workload and leaves the unit deployed in maintenance status, so an operator can take a unit out of service without removing it; resume starts it again. src/workload.py.j2 gains a stop() stub alongside the existing install() and start().

In the kubernetes profile, restart:

Restarts the Pebble service in the workload container, waits for the workload to be ready, and sets the unit active again.


  • I've followed the contribution guidelines.
  • I've signed the CLA.
  • I've successfully run 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.
  • I've updated the relevant release notes.

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.
@tonyandrewmeyer

Copy link
Copy Markdown
Contributor Author

@dwilding could you please have a look over this?

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.

1 participant