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

Expose Juju payloads hook tools #1377

Open
tonyandrewmeyer opened this issue Sep 17, 2024 · 2 comments
Open

Expose Juju payloads hook tools #1377

tonyandrewmeyer opened this issue Sep 17, 2024 · 2 comments
Labels
feature New feature or request low priority Non-urgent issue we may (or may not) consider later needs design needs more thought or spec

Comments

@tonyandrewmeyer
Copy link
Contributor

tonyandrewmeyer commented Sep 17, 2024

The payloads hook tools are the only ones (other than deprecated functionality and tools for working directly with K8s) that ops does not expose (the CharmMeta object does load any payloads that are in the metadata).

I assume this would look something like this, although I suspect we could make the DX nicer particularly the type, class, id args:

class PayloadStatus(enum.Enum):
    STARTING = "starting"
    STARTED = "started"
    STOPPING = "stopping"
    STOPPED = "stopped"

class Unit(...):
    ...
    def register_payload(self, payload_type: str, payload_class: str, id: str, *tags: str):
        # calls `payload-register` via the model backend

    def set_payload_status(self, payload_class: str, id: str, status: PayloadStatus):
        # calls `payload-status-set` via the model backend

    def unregister_payload(self, payload_class: str, id: str):
        # calls `payload-status-set` via the model backend

This could be used like:

self.unit.register_payload('usertype', 'mypayload', 'foo')
self.unit.set_payload_status('mypayload', PayloadStatus.STARTING)

To get something like:

$ juju payloads
[Unit Payloads]
Unit                Machine  Payload class  Status    Type      Id   Tags  
testing-payloads/0  63       mypayload      starting  usertype  foo        

It seems like this could be a useful way to provide more detail to the Juju admin than the per-unit status offers.

Note that at the moment charmcraft.yaml doesn't work with payloads, so to use this feature you need to use the old style of having a separate metadata.yaml file. The Juju team said that it's still available and didn't say that it was deprecated.

@benhoyt
Copy link
Collaborator

benhoyt commented Sep 17, 2024

Interesting -- I didn't know about payloads. All I see is the bare and brief doc at https://juju.is/docs/juju/juju-payloads -- is the concept of payload documented somewhere else?

@tonyandrewmeyer
Copy link
Contributor Author

tonyandrewmeyer commented Sep 18, 2024

All I see is the bare and brief doc at https://juju.is/docs/juju/juju-payloads -- is the concept of payload documented somewhere else?

Not that I've found. I've looked on juju.is/docs and bugs.launchpad.net and at what seem to be the main Go files in the Juju code for payloads and at the PR that I think added the feature and on specs.canonical.com and not found anything. The 1.25 release notes have a short mention, but it's the same content as in the hook tool help.

We should definitely talk to the Juju team before doing this 😄.

@benhoyt benhoyt added feature New feature or request needs design needs more thought or spec low priority Non-urgent issue we may (or may not) consider later labels Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request low priority Non-urgent issue we may (or may not) consider later needs design needs more thought or spec
Projects
None yet
Development

No branches or pull requests

2 participants