Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/example-charm-integration-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
matrix:
dir:
- examples/httpbin-demo
- examples/k8s-1-minimal
steps:
- uses: actions/checkout@v6
with:
Expand Down Expand Up @@ -78,7 +79,6 @@ jobs:
fail-fast: false
matrix:
dir:
- examples/k8s-1-minimal
- examples/k8s-2-configurable
- examples/k8s-3-postgresql
- examples/k8s-4-action
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -109,42 +109,42 @@ First, repack and refresh your charm:
```text
charmcraft pack
juju refresh \
--path="./demo-api-charm_ubuntu-22.04-amd64.charm" \
demo-api-charm --force-units --resource \
--path="./fastapi-demo_amd64.charm" \
fastapi-demo --force-units --resource \
demo-server-image=ghcr.io/canonical/api_demo_server:1.0.1
```

Next, test that the basic action invocation works:

```text
juju run demo-api-charm/0 get-db-info
juju run fastapi-demo/0 get-db-info
```

It might take a few seconds, but soon you should see an output similar to the one below, showing the database host and port:

```text
Running operation 1 with 1 task
- task 2 on unit-demo-api-charm-0
- task 2 on unit-fastapi-demo-0

Waiting for task 2...
db-host: postgresql-k8s-primary.welcome-k8s.svc.cluster.local
db-host: postgresql-k8s-primary.testing.svc.cluster.local
db-port: "5432"
```

Now, test that the action parameter (`show-password`) works as well by setting it to `True`:

```text
juju run demo-api-charm/0 get-db-info show-password=True
juju run fastapi-demo/0 get-db-info show-password=True
```

The output should now include the username and the password:

```text
Running operation 3 with 1 task
- task 4 on unit-demo-api-charm-0
- task 4 on unit-fastapi-demo-0

Waiting for task 4...
db-host: postgresql-k8s-primary.welcome-k8s.svc.cluster.local
db-host: postgresql-k8s-primary.testing.svc.cluster.local
db-password: RGv80aF9WAJJtExn
db-port: "5432"
db-username: relation_id_4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ This tells Charmcraft that your charm requires the [`data_interfaces`](https://c
Next, run the following command to download the library:

```text
ubuntu@charm-dev:~/fastapi-demo$ charmcraft fetch-libs
ubuntu@juju-sandbox-k8s:~/fastapi-demo$ charmcraft fetch-libs
```

Your charm directory should now contain the structure below:
Expand Down Expand Up @@ -351,8 +351,8 @@ First, repack and refresh your charm:
```text
charmcraft pack
juju refresh \
--path="./demo-api-charm_ubuntu-22.04-amd64.charm" \
demo-api-charm --force-units --resource \
--path="./fastapi-demo_amd64.charm" \
fastapi-demo --force-units --resource \
demo-server-image=ghcr.io/canonical/api_demo_server:1.0.1
```

Expand All @@ -365,7 +365,7 @@ juju deploy postgresql-k8s --channel=14/stable --trust
Now, integrate our charm with the newly deployed `postgresql-k8s` charm:

```text
juju integrate postgresql-k8s demo-api-charm
juju integrate postgresql-k8s fastapi-demo
```

> Read more: {external+juju:ref}`Juju | Relation (integration) <relation>`, [`juju integrate`](inv:juju:std:label#command-juju-integrate)
Expand All @@ -376,22 +376,22 @@ Finally, run:
juju status --relations --watch 1s
```

You should see both applications get to the `active` status, and also that the `postgresql-k8s` charm has a relation to the `demo-api-charm` over the `postgresql_client` interface, as below:
You should see both applications get to the `active` status, and also that the `postgresql-k8s` charm has a relation to the `fastapi-demo` over the `postgresql_client` interface, as below:

```text
Model Controller Cloud/Region Version SLA Timestamp
welcome-k8s microk8s microk8s/localhost 3.6.8 unsupported 13:50:39+01:00
Model Controller Cloud/Region Version SLA Timestamp
testing concierge-microk8s microk8s/localhost 3.6.12 unsupported 13:50:39+01:00

App Version Status Scale Charm Channel Rev Address Exposed Message
demo-api-charm active 1 demo-api-charm 2 10.152.183.233 no
fastapi-demo active 1 fastapi-demo 2 10.152.183.233 no
postgresql-k8s 14.15 active 1 postgresql-k8s 14/stable 495 10.152.183.195 no

Unit Workload Agent Address Ports Message
demo-api-charm/0* active idle 10.1.157.90
fastapi-demo/0* active idle 10.1.157.90
postgresql-k8s/0* active idle 10.1.157.92 Primary

Integration provider Requirer Interface Type Message
postgresql-k8s:database demo-api-charm:database postgresql_client regular
postgresql-k8s:database fastapi-demo:database postgresql_client regular
postgresql-k8s:database-peers postgresql-k8s:database-peers postgresql_peers peer
postgresql-k8s:restart postgresql-k8s:restart rolling_op peer
postgresql-k8s:upgrade postgresql-k8s:upgrade upgrade peer
Expand Down Expand Up @@ -536,7 +536,7 @@ def test_database_integration(juju: jubilant.Juju):
In your Multipass Ubuntu VM, run the test again:

```text
ubuntu@charm-dev:~/fastapi-demo$ tox -e integration
ubuntu@juju-sandbox-k8s:~/fastapi-demo$ tox -e integration
```

The test may again take some time to run.
Expand All @@ -547,9 +547,9 @@ When it's done, the output should show two passing tests:
tests/integration/test_charm.py::test_deploy
...
INFO jubilant.wait:_juju.py:1164 wait: status changed:
- .apps['demo-api-charm'].units['demo-api-charm/0'].juju_status.current = 'executing'
- .apps['demo-api-charm'].units['demo-api-charm/0'].juju_status.message = 'running start hook'
+ .apps['demo-api-charm'].units['demo-api-charm/0'].juju_status.current = 'idle'
- .apps['fastapi-demo'].units['fastapi-demo/0'].juju_status.current = 'executing'
- .apps['fastapi-demo'].units['fastapi-demo/0'].juju_status.message = 'running start hook'
+ .apps['fastapi-demo'].units['fastapi-demo/0'].juju_status.current = 'idle'
PASSED
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,21 +174,21 @@ First, repack and refresh your charm:
```text
charmcraft pack
juju refresh \
--path="./demo-api-charm_ubuntu-22.04-amd64.charm" \
demo-api-charm --force-units --resource \
--path="./fastapi-demo_amd64.charm" \
fastapi-demo --force-units --resource \
demo-server-image=ghcr.io/canonical/api_demo_server:1.0.1
```

Now, check the available configuration options:

```text
juju config demo-api-charm
juju config fastapi-demo
```

Our newly defined `server-port` option is there. Let's try to configure it to something else, e.g., `5000`:

```text
juju config demo-api-charm server-port=5000
juju config fastapi-demo server-port=5000
```

Now, let's validate that the app is actually running and reachable on the new port by sending the HTTP request below, where `10.1.157.74` is the IP of our pod and `5000` is the new application port:
Expand All @@ -202,29 +202,29 @@ You should see JSON string with the version of the application: `{"version":"1.0
Let's also verify that our invalid port number check works by setting the port to `22` and then running `juju status`:

```text
juju config demo-api-charm server-port=22
juju config fastapi-demo server-port=22
juju status
```

As expected, the application is indeed in the `blocked` state:

```text
Model Controller Cloud/Region Version SLA Timestamp
welcome-k8s microk8s microk8s/localhost 3.6.8 unsupported 18:19:24+01:00
Model Controller Cloud/Region Version SLA Timestamp
testing concierge-microk8s microk8s/localhost 3.6.12 unsupported 18:19:24+01:00

App Version Status Scale Charm Channel Rev Address Exposed Message
demo-api-charm blocked 1 demo-api-charm 1 10.152.183.215 no Invalid port number, 22 is reserved for SSH
fastapi-demo blocked 1 fastapi-demo 1 10.152.183.215 no Invalid port number, 22 is reserved for SSH

Unit Workload Agent Address Ports Message
demo-api-charm/0* blocked idle 10.1.157.74 Invalid port number, 22 is reserved for SSH
fastapi-demo/0* blocked idle 10.1.157.74 Invalid port number, 22 is reserved for SSH
```

Congratulations, you now know how to make your charm configurable!

Before continuing, reset the port to `8000` and check that the application is in `active` status:

```text
juju config demo-api-charm server-port=8000
juju config fastapi-demo server-port=8000
juju status
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ charm-libs:
Next, run the following command to download the libraries:

```text
ubuntu@charm-dev:~/fastapi-demo$ charmcraft fetch-libs
ubuntu@juju-sandbox-k8s:~/fastapi-demo$ charmcraft fetch-libs
```

Your charm directory should now include the structure below:
Expand Down Expand Up @@ -236,8 +236,8 @@ First, repack and refresh your charm:
```text
charmcraft pack
juju refresh \
--path="./demo-api-charm_ubuntu-22.04-amd64.charm" \
demo-api-charm --force-units --resource \
--path="./fastapi-demo_amd64.charm" \
fastapi-demo --force-units --resource \
demo-server-image=ghcr.io/canonical/api_demo_server:1.0.1
```

Expand Down Expand Up @@ -282,17 +282,17 @@ microk8s admin/cos-lite.prometheus admin prometheus_scrape:metrics-endpoint
microk8s admin/cos-lite.grafana admin grafana_dashboard:grafana-dashboard
```

As you might notice from your knowledge of Juju, this is essentially preparing these endpoints, which exist in the `cos-lite` model, for a cross-model relation with your charm, which you've deployed to the `welcome-k8s` model.
As you might notice from your knowledge of Juju, this is essentially preparing these endpoints, which exist in the `cos-lite` model, for a cross-model relation with your charm, which you've deployed to the `testing` model.

## Integrate your charm with COS Lite

Now switch back to the charm model and integrate your charm with the exposed endpoints, as below. This effectively integrates your application with Prometheus, Loki, and Grafana.

```text
juju switch welcome-k8s
juju integrate demo-api-charm admin/cos-lite.grafana
juju integrate demo-api-charm admin/cos-lite.loki
juju integrate demo-api-charm admin/cos-lite.prometheus
juju switch testing
juju integrate fastapi-demo admin/cos-lite.grafana
juju integrate fastapi-demo admin/cos-lite.loki
juju integrate fastapi-demo admin/cos-lite.prometheus
```

<a href="#heading--access-your-applications-from-the-host-machine"><h3 id="heading--access-your-applications-from-the-host-machine">Access your applications from the host machine</h3></a>
Expand All @@ -311,8 +311,8 @@ juju status -m cos-lite
This should result in an output similar to the one below:

```text
Model Controller Cloud/Region Version SLA Timestamp
cos-lite microk8s microk8s/localhost 3.6.8 unsupported 18:05:07+01:00
Model Controller Cloud/Region Version SLA Timestamp
cos-lite concierge-microk8s microk8s/localhost 3.6.12 unsupported 18:05:07+01:00

App Version Status Scale Charm Channel Rev Address Exposed Message
alertmanager 0.27.0 active 1 alertmanager-k8s 1/stable 160 10.152.183.70 no
Expand All @@ -333,13 +333,13 @@ Do not mix up Apps and Units -- Units represent Kubernetes pods while Apps repre
Now open a terminal on your host machine and run:

```text
multipass info charm-dev
multipass info juju-sandbox-k8s
```

This should result in an output similar to the one below:

```text
Name: charm-dev
Name: juju-sandbox-k8s
State: Running
IPv4: 10.112.13.157
10.49.132.1
Expand All @@ -349,7 +349,7 @@ Image hash: 1d24e397489d (Ubuntu 22.04 LTS)
Load: 0.31 0.25 0.28
Disk usage: 15.9G out of 19.2G
Memory usage: 2.1G out of 7.8G
Mounts: /home/maksim/fastapi-demo => ~/fastapi-demo
Mounts: /home/me/k8s-tutorial => ~/fastapi-demo
UID map: 1000:default
GID map: 1000:default
```
Expand Down Expand Up @@ -390,7 +390,7 @@ http://10.152.183.132:3000/?orgId=1&search=open
Click on `FastAPI Monitoring`
-->

Next, in the `Juju model` drop down field, select `welcome-k8s`.
Next, in the `Juju model` drop down field, select `testing`.

Now, call a couple of API points on the application, as below. To produce some successful requests and some requests with code 500 (internal server error), call several times, in any order.

Expand Down
Loading