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

docs: add howto guides for switching from the charm plugin #1967

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lengau
Copy link
Collaborator

@lengau lengau commented Oct 17, 2024

This adds howto guides to switch from the charm plugin to the python and poetry plugins.

@lengau lengau requested review from medubelko and a team October 17, 2024 20:25
@lengau lengau linked an issue Oct 17, 2024 that may be closed by this pull request
This adds howto guides to switch from the charm plugin to the python
and poetry plugins.
Copy link
Contributor

@mattculler mattculler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clear!

@jnsgruk
Copy link
Member

jnsgruk commented Oct 18, 2024

Gave this a go here: jnsgruk/zinc-k8s-operator#288

Might be worth including a section about using override-pull as a place where people can generate requirements'txt if they need to.

I guess they could also use override-build and just place their generation code before craftctl default.

Edit: lots of failed integration tests when I changed to this; will investigate.

@jnsgruk
Copy link
Member

jnsgruk commented Oct 18, 2024

Heh. The python plugin doesn't seem to have included any dispatch file...

ubuntu@ubuntu-noble-2e39:~/zinc_charm_unzipped$ ls -la
total 39480
drwxrwxr-x 5 ubuntu ubuntu     4096 Oct 18 10:30 .
drwxr-xr-x 9 ubuntu ubuntu     4096 Oct 18 10:30 ..
drwxrwxr-x 2 ubuntu ubuntu     4096 Oct 18 10:30 bin
drwxrwxr-x 3 ubuntu ubuntu     4096 Oct 18 10:30 lib
drwxrwxr-x 3 ubuntu ubuntu     4096 Oct 18 10:30 lib64
-rw-r--r-- 1 ubuntu ubuntu      255 Oct 18 10:21 manifest.yaml
-rw-r--r-- 1 ubuntu ubuntu     1402 Oct 18 10:21 metadata.yaml
-rw-r--r-- 1 ubuntu ubuntu      169 Oct 18 10:21 pyvenv.cfg

Edit: switched to the latest/edge channel and things seem better:

ubuntu@ubuntu-noble-2e39:~/data/code/charms/zinc-k8s-operator$ unzip -l ./zinc-k8s_amd64.charm | grep -v python3
Archive:  ./zinc-k8s_amd64.charm
  Length      Date    Time    Name
---------  ---------- -----   ----
      272  2024-10-18 10:38   manifest.yaml
     1402  2024-10-18 10:38   metadata.yaml
      673  2024-10-18 10:38   dispatch
      188  2024-10-18 10:34   venv/pyvenv.cfg
     2680  2024-10-03 08:44   src/zinc.py
     3922  2024-10-03 08:44   src/charm.py
        0  2022-05-31 14:57   src/prometheus_alert_rules/.gitkeep
      294  2022-07-30 20:33   src/prometheus_alert_rules/zinc_missing.rule
        0  2022-05-31 14:57   src/loki_alert_rules/.gitkeep
    20957  2023-08-23 13:19   src/grafana_dashboards/zinc.json.tmpl
    99854  2024-08-19 14:12   lib/charms/loki_k8s/v0/loki_push_api.py
    30560  2024-08-28 16:53   lib/charms/traefik_k8s/v2/ingress.py
    96662  2024-08-19 14:12   lib/charms/prometheus_k8s/v0/prometheus_scrape.py
    34280  2024-10-02 08:52   lib/charms/parca/v0/parca_scrape.py
    80536  2024-08-19 14:12   lib/charms/grafana_k8s/v0/grafana_dashboard.py
     9975  2024-10-02 08:52   lib/charms/observability_libs/v0/juju_topology.py
---------                     -------
 41499875                     2412 files

Alas, no dice on deploying, though...

ubuntu@ubuntu-noble-2e39:~/zinc_charm/venv$ juju debug-log
unit-zinc-k8s-0: 10:39:59 WARNING unit.zinc-k8s/0.install ln: failed to create symbolic link '/var/lib/juju/agents/unit-zinc-k8s-0/charm/venv/bin/python': No such file or directory
unit-zinc-k8s-0: 10:39:59 WARNING unit.zinc-k8s/0.install /var/lib/juju/agents/unit-zinc-k8s-0/charm/dispatch: 16: exec: /var/lib/juju/agents/unit-zinc-k8s-0/charm/venv/bin/python: not found
unit-zinc-k8s-0: 10:39:59 ERROR juju.worker.uniter.operation hook "install" (via hook dispatching script: dispatch) failed: exit status 127

@lengau
Copy link
Collaborator Author

lengau commented Oct 18, 2024

Thanks @jnsgruk! Looks like I forgot to test with python-keep-bins: false (the default). I've made a fix PR, but as a temporary workaround you should also be able to set python-keep-bins: true in the part definition.

@lengau
Copy link
Collaborator Author

lengau commented Oct 18, 2024

@jnsgruk re: the override-pull - while people could do that, I'd prefer not to document it here as I'd like to encourage people to check in some sort of lock file. For the uv case, @bepri is heading up our addition of uv plugins for 25.04

Copy link
Contributor

@medubelko medubelko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting these together!

Ensure a recent enough version of ``pip``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The ``python`` plugin requires at least pip 22.3, released in October 2022. If the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pip 22.3, released in October 2022

Rather than mentioning the date, can we link to https://pypi.org/project/pip/22.3 instead?

@@ -0,0 +1,107 @@
.. _howto-migrate-to-poetry:

Migrate from the ``charm`` plugin to Poetry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency with existing docs and docs best practices, we should use the form Charm plugin and Python plugin.

.. code-block:: yaml

parts:
my-charm: # This can be named anything you want
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A morsel for thought: we generally discourage the use of comments in bash, but I'm not sure where configs fit in, since we encourage users to copy them. As a general principle it's better to use the doc to explain things.

plugin: poetry
source: .

Ensure a recent enough version of ``pip`` and ``poetry``
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Ensure a recent enough version of ``pip`` and ``poetry``
Select compatible versions of ``pip`` and ``poetry``

The ``poetry`` plugin requires at least pip 22.3, released in October 2022. If the
charm's base uses an older version of pip, a newer version can be installed in the
build environment using a dependency part. Likewise, a charm may require a newer
version of poetry than is available in the distribution's repositories. The following
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
version of poetry than is available in the distribution's repositories. The following
version of Poetry than is available in the distribution's repositories. The following


.. note::
This is useful and encouraged, though not mandatory, for keeping track of
library dependencies (see below). For an example, see
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
library dependencies (see below). For an example, see
library dependencies, as covered in the next section. For an example, see

Unlike the ``charm`` plugin, the ``poetry`` plugin does not install the dependencies
for included charmlibs. If any of the charm libraries used have PYDEPS, these will
need to be added to the charm's dependencies, potentially as their own
`dependency group <dependency groups>`_.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unspecified link.

Migrate from the ``charm`` plugin to the ``python`` plugin
==========================================================

The ``python`` Charmcraft plugin offers a faster, stricter means of packing an operator
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Charmcraft plugin

Do we need to be this specific here? "Python Charmcraft plugin" tripped me up as a phrase.

python-requirements:
- requirements.txt # Or whatever your requirements file is called.

Ensure a recent enough version of ``pip``
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Ensure a recent enough version of ``pip``
Select a compatible version of ``pip``

==========================================================

The ``python`` Charmcraft plugin offers a faster, stricter means of packing an operator
charm with a virtual environment. This guide shows how to migrate from a charm using
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"packing with" is slightly ambiguous, so we might want to take special care with how we express this. If I'm understanding this correctly, could we say "packing a virtual environment inside an operator charm"?

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.

Document the python and poetry plugins
4 participants