You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/howto/initialise-your-project.md
+27-6Lines changed: 27 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,20 +24,41 @@ To check that your preferred name isn't already in use, visit the (future) Charm
24
24
```text
25
25
https://charmhub.io/mega-calendar-k8s
26
26
```
27
-
(create-a-repository-and-initialise-it)=
28
-
## Create a repository and initialise it
27
+
28
+
Some charms do not operate a workload, such as integrator and configurator charms. These categories serve different purposes:
29
+
30
+
* An integrator charm allows integration with a service that is not managed through Juju. This can both apply to server side integrations (such as `s3-integrator`, which integrates an externally managed S3 object storage) or to client side integrations (such as `data-integrator`, representing the integration of external client application that needs a database).
31
+
32
+
* A configurator charm provides logic to configure a particular charm or relation that is already in Juju. Examples include `cos-configuration` when it applies to a single charm (such as providing more fine-grained configuration of the Prometheus scraping) or for a relation (such as `ingress-configurator` to provide additional configuration of ingress requests).
33
+
34
+
Since workload-less charms can work both on machines and on Kubernetes, avoid using the `k8s` suffix when naming integrator charms and configurator charms, unless the charm is only relevant for Kubernetes (for example, managing K8s resources within the charm logic using `lightkube`).
35
+
36
+
When naming the charm, use `-integrator` and `-configurator` to signal the category of the charm. For example, `foo-integrator` or `bar-configurator`.
37
+
38
+
(create-a-repository)=
39
+
## Create a repository
29
40
30
41
Create a repository with your source control of choice.
31
42
32
43
```{admonition} Best practice
33
44
:class: hint
34
45
35
-
Name the repository using the pattern ``<charm name>-operator`` for a single
36
-
charm, or ``<base charm name>-operators`` when the repository will hold
37
-
multiple related charms. For the charm name, see [](#decide-your-charms-name).
46
+
If your charm operates a workload, name the repository `<charm name>-operator`. For advice about the charm name, see [](#decide-your-charms-name). If your charm doesn't operate a workload (as in the case of integrator charms and configurator charms), the `-operator` suffix isn't needed. For example, `foo-integrator` and `bar-configurator`.
47
+
48
+
Repositories that contain multiple charms or one or more charms and other artefacts (like rocks) will need to use other naming patterns.
38
49
```
39
50
40
-
For example, name the repository `mega-calendar-k8s-operator` if your charm will be called `mega-calendar-k8s`.
51
+
Examples:
52
+
53
+
-[kafka-operator](https://github.com/canonical/kafka-operator) - Contains a single charm that operates a machine workload.
54
+
-[kafka-k8s-operator](https://github.com/canonical/kafka-k8s-operator) - Contains a single charm that operates a K8s workload.
-[data-integrator](https://github.com/canonical/data-integrator) - Contains a charm that integrates an externally managed service (such as a client application).
57
+
-[s3-integrator](https://github.com/canonical/object-storage-integrators) - Contains multiple charms that integrate an externally managed service (such as different kinds of object storage backends).
58
+
-[request-authentication-configurator](https://github.com/canonical/request-authentication-configurator) - Contains a charm that configures Gateway to perform request authentication.
59
+
60
+
(initialise-the-repository)=
61
+
## Initialise the repository
41
62
42
63
Next, use {external+charmcraft:doc}`Charmcraft <index>` to generate the recommended project structure in the repository:
Copy file name to clipboardExpand all lines: docs/howto/manage-storage.md
+27-21Lines changed: 27 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -86,6 +86,30 @@ self.model.storages.request('cache', 2) # Request two more instances.
86
86
87
87
The additional instances won't be available immediately after the call. As with `juju add-storage`, your charm will receive a storage-attached event as each additional instance becomes available.
88
88
89
+
### Clean up storage
90
+
91
+
Juju emits a [storage-detaching](ops.StorageDetachingEvent) event whenever attached storage is being released: when a user runs `juju detach-storage` (or `juju remove-storage --force`), and during unit teardown. Observe this event to cleanly release resources before the storage goes away.
92
+
93
+
In the `src/charm.py` file, in the `__init__` function of your charm, set up an observer for the detaching event associated with your storage and pair that with an event handler. For example:
Now, in the body of the charm class, define the event handler, or adjust an existing holistic one. For example, to warn users that data won't be cached:
'Caching disabled; provide storage to boost performance'
108
+
)
109
+
```
110
+
111
+
> Examples: [MongoDB updating the set before storage is removed](https://github.com/canonical/mongodb-operator/blob/b33d036173f47c68823e08a9f03189dc534d38dc/src/charm.py#L596)
Alternatively, use {external+charmlibs:class}`pathops.ContainerPath` to access `web_cache_path` in the workload container. This approach is more appropriate if you need to reference additional data in the workload container.
166
190
167
-
## Handle storage detaching
168
-
169
-
In the `src/charm.py` file, in the `__init__` function of your charm, set up an observer for the detaching event associated with your storage and pair that with an event handler. For example:
Now, in the body of the charm definition, define the event handler, or adjust an existing holistic one. For example, to warn users that data won't be cached:
'Caching disabled; provide storage to boost performance'
186
-
)
187
-
```
193
+
On Kubernetes, `juju detach-storage` isn't supported, so storage is only detached during unit teardown. Juju emits a [storage-detaching](ops.StorageDetachingEvent) event during teardown, along with `stop`, `remove`, and other teardown events.
188
194
189
-
> Examples: [MySQL handling cluster management](https://github.com/canonical/mysql-k8s-operator/blob/4c575b478b7ae2a28b09dde9cade2d3370dd4db6/src/charm.py#L823), [MongoDB updating the set before storage is removed](https://github.com/canonical/mongodb-operator/blob/b33d036173f47c68823e08a9f03189dc534d38dc/src/charm.py#L596)
Copy file name to clipboardExpand all lines: docs/reuse/best-practices.txt
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
**[How to initialise your project](https://documentation.ubuntu.com/ops/latest/howto/initialise-your-project/)**
2
-
- Name the repository using the pattern ``<charm name>-operator`` for a single charm, or ``<base charm name>-operators`` when the repository will hold multiple related charms. For the charm name, see [](#decide-your-charms-name). See [Create a repository and initialise it](#create-a-repository-and-initialise-it).
2
+
- If your charm operates a workload, name the repository `<charm name>-operator`. For advice about the charm name, see [](#decide-your-charms-name). If your charm doesn't operate a workload (as in the case of integrator charms and configurator charms), the `-operator` suffix isn't needed. For example, `foo-integrator` and `bar-configurator`. Repositories that contain multiple charms or one or more charms and other artefacts (like Rocks) will need to use other naming patterns. See [Create a repository](#create-a-repository).
3
3
4
4
**[How to log from your charm](https://documentation.ubuntu.com/ops/latest/howto/log-from-your-charm/)**
5
5
- Capture output to `stdout` and `stderr` in your charm and use the logging and warning functionality to send messages to the charm user, rather than rely on Juju capturing output. In particular, you should avoid `print()` calls, and ensure that any subprocess calls capture output.
0 commit comments