docs: update docs, deps, and tests for charms with libs#2281
docs: update docs, deps, and tests for charms with libs#2281dwilding merged 15 commits intocanonical:k8s-tutorial-uvfrom
Conversation
| # Workaround for a build error. | ||
| parts: | ||
| charm: | ||
| charm-binary-python-packages: | ||
| - cosl |
There was a problem hiding this comment.
I've already removed this from the relevant charm code in the k8s-tutorial-uv branch.
| If you're experiencing issues with your IDE or just trying to run the `charm.py` file on your own, make sure to set/update `PYTHONPATH` to include `lib` directory as well. | ||
| If you're experiencing issues with your IDE, make sure to set/update `PYTHONPATH` to include the `lib` directory as well. | ||
|
|
||
| ```bash | ||
| # from the charm project directory (~/fastapi-demo), set | ||
| # in your project directory (~/k8s-tutorial), set | ||
| export PYTHONPATH=lib | ||
| # or update | ||
| export PYTHONPATH=lib:$PYTHONPATH |
There was a problem hiding this comment.
I don't think it's fruitful for people to spend time trying to run charm.py. Also, focusing on IDEs lets us clarify that PYTHONPATH should be set in ~/k8s-tutorial, which is outside the VM.
james-garner-canonical
left a comment
There was a problem hiding this comment.
These changes look good to me!
dimaqq
left a comment
There was a problem hiding this comment.
Nice, especially running the tests in the same pipeline.
tonyandrewmeyer
left a comment
There was a problem hiding this comment.
Looks good, thanks!
I didn't run through the tutorial - I assume that'll be done by at least one person at the end when the merge through to main is ready.
| Your charm directory should now include the structure below: | ||
| You might see a warning that Charmcraft cannot get a keyring. You can ignore the warning. | ||
|
|
||
| After Charmcraft has downloaded the libraries, you project's `lib` directory contains: |
There was a problem hiding this comment.
| After Charmcraft has downloaded the libraries, you project's `lib` directory contains: | |
| After Charmcraft has downloaded the library, your project's `lib` directory contains: |
There was a problem hiding this comment.
Oops, thanks. Corrected "you" --> "your" but kept "libraries" as charmcraft fetch-libs is downloading several libraries in this chapter
…rofile (#2285) This PR makes significant changes to our [Kubernetes charm tutorial](https://documentation.ubuntu.com/ops/latest/tutorial/from-zero-to-hero-write-your-first-kubernetes-charm/). ### Main changes - Use similar environment setup instructions as our machine charm tutorial. The instructions explain how to use Concierge to prepare a Multipass VM with Canonical Kubernetes and charm dev tools. I'm recommending that the reader mounts a local directory into their VM so that they can use their IDE to edit charm code. **[Preview chapter](https://canonical-ubuntu-documentation-library--2285.com.readthedocs.build/ops/2285/tutorial/from-zero-to-hero-write-your-first-kubernetes-charm/set-up-your-development-environment/)** I also made a small clarification to the setup instructions of the machine charm tutorial. - Start the charm from the latest Charmcraft `kubernetes` profile. This removes the need for the reader to create several files, including `charmcraft.yaml`, `pyproject.toml`, and `tox.ini`. The charm expects uv for managing dependencies and uses Charmcraft's uv plugin. **[Preview chapter](https://canonical-ubuntu-documentation-library--2285.com.readthedocs.build/ops/2285/tutorial/from-zero-to-hero-write-your-first-kubernetes-charm/create-a-minimal-kubernetes-charm/)** - Manually find transitive dependencies of Charmhub-hosted libs. This makes the last chapter slightly more complicated, but is unavoidable because the observability libs haven't been migrated to `charmlibs` packages and Charmcraft's uv plugin doesn't extract `PYDEPS` from libs. **[Preview section](https://canonical-ubuntu-documentation-library--2285.com.readthedocs.build/ops/2285/tutorial/from-zero-to-hero-write-your-first-kubernetes-charm/observe-your-charm-with-cos-lite/#add-dependencies-from-libraries)** These changes were reviewed in my intermediate PRs #2258, #2259, and #2281. ### Unrelated changes - Mention that Charmcraft might show a warning when fetching libs. - I fixed a bug in the [demo server](https://github.com/canonical/api_demo_server) workload. Version 1.0.1 of the image returns version string `1.0.0` from the API. I'm switching the tutorial to use version 1.0.2 of the image, which correctly returns version string `1.0.2`. ### Adjustments after testing After the main changes had been reviewed, I tested the tutorial from end to end and made some small adjustments/fixes: f33ac24, 2851e1f, 71b9838, f8b22a8. Further adjustments during PR review: 7d36dce Final adjustments to add a note about issues accessing services inside the VM: 837df1b
This is an intermediate PR for switching the Kubernetes charm tutorial to use uv and the latest Charmcraft profiles. Target branch is
k8s-tutorial-uvThis PR:
PYTHONPATH.coslas a dependency.lib. As explained in the PostgreSQL chapter, what actually happens is that thedispatchscript setsPYTHONPATH. The note also mentioned how to import a lib, which isn't necessary because the chapter covers that later.coslas a dependency of the relevant charm code.The workflow doesn't run on PRs, so I temporarily enabled it here and checked that it succeeded: https://github.com/canonical/operator/actions/runs/21170536298/