-
Notifications
You must be signed in to change notification settings - Fork 122
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
Create a demo of how to write a functional charm, starting from charmcraft's Kubernetes profile #1522
Comments
Hi David,
Using
While a demo sounds nice, demos in general are expensive to maintain and I'm also not sure it would be the most effective means in this case in particular either. I would personally prioritize updating the existing tutorial + how-to content. As in, I'd revisit all the places where we say "in your
I'm not sure this will be necessary. I mean, if there's a change in the behavior of tl;dr I think the TODO here is in fact smaller than we originally thought. |
For what it's worth, this is basically
I still feel that it's going to be difficult to really promote this approach using the profiles. On the other hand, I don't really know how else we'd encourage this behaviour, other than adjusting the docs. |
Thanks Tony! I'll see how far I get with experimenting today, and then maybe we can review tomorrow to see if anything looks promising? |
I'm experimenting in this repo: https://github.com/dwilding/demo-kubernetes-charm |
Here's an initial attempt at a template, with the logic split into charm.py and services.py: I went with the term "services" rather than "workload" because the level of abstraction I had in mind was "the stuff managed by Pebble". Somehow I like "services" more than "workload", which kind of refers to the container itself... but "services" wouldn't really make sense for machine charms - unless Pebble establishes itself there too. Anyway, right now I mainly want to see if this separation of concerns is reasonable as a starting point for charmers. |
Just a small FYI that "services" used to be Juju jargon. It was probably long enough ago that it wouldn't matter anymore. At the same time, the jargon mandated at present is "workload". |
Some initial notes: The Pebble LayerI understand that the Zinc charm does this, but I feel like having a Pebble layer defined in the workload module is wrong. I think it would be ideal if the workload module doesn't import anything from ops at all, so is entirely standalone from the charming world. This supports the goal of having modules that are potentially useful outside of charming, and could be published separately, and the inverse of that where there's already an existing Python package for managing a service and that's used by the charm. In a layer, there are some things that are quite specific to the workload and some that are more about Pebble itself. I think we could establish some sort of standard for defining the workload pieces inside the workload module (or class, if we're going to have a class). For example (this is off the cuff and not thought through in depth):
We'd need to also think about how checks and log targets would get added to this in a more complete charm. Module nameRather than TODOs
I think it is good to set this to the latest (minor) release. What you actually need is to have the latest release containing all the functionality you're using (and none of the bugs that would hit you). However, we want people to rapidly move to the latest version, and only really support that version, and one way we push people to that is to not specify which version features are added. So the safest thing is to just keep that version set to the latest. I would actually have the ops version in a
I think this would be the best choice, yes. If you wanted more than that, then you could have the charm have an action that added a name, or listed all the names, and then the workload module/class would need to support that too.
You could, but in my opinion (as above) I think we do not want to.
Yes, I'd do this - a function that returns the config. Note that the config might be a string that needs to be written to a file somewhere or it might be a set of environment variables that need to go into the Pebble layer. |
Thank you very much for the comments so far! Capturing some internal discussion within Charm Tech: If we recommend a pattern for how to split logic between charm.py and a workload module, it would be helpful to have a small & clear example (as planned with this issue) plus a real-sized reference charm that uses the same pattern. There's definitely a preference that the workload module shouldn't import anything from For instance, should the workload module even know how to start the workload? (Meaning, per Tony's comment, does the workload module provide the starting command to charm.py somehow?) Maybe not. What if we took the view that the workload module is supposed to be a "client" module that knows how to communicate with the workload's running process (via an HTTP API for example), then we could reasonably say that it's out of scope for the workload module to care about how the process gets started. Anyway, just one of many thoughts...! I'll let this sit over the weekend then work on adjusting the approach next week |
Our tutorial Create a minimal Kubernetes charm says:
I'd like to try doing this. Specifically, I'd like to create a minimal demo that:
charmcraft init --profile kubernetes
This is partly for my own learning 🙂 - but I expect it to be a helpful reference as we work on making the tutorial shorter.
As a follow-on task, I'd like to give new templates to the charmcraft team so that
charmcraft init
makes charms with observer and workload logic in separate files. Trying it for FastAPI first should help to iron out any kinks.TBD: This work might also be helpful if we want to update the Give it a try example in the Ops README.
The text was updated successfully, but these errors were encountered: