Skip to content

Commit

Permalink
Merge pull request #3 from canonical/add-basics
Browse files Browse the repository at this point in the history
[DPE-4942] - add mongos charm basics pt2 - add more suggestions from Carl
  • Loading branch information
MiaAltieri authored Aug 5, 2024
2 parents fe84ba5 + bcc39c9 commit 527df8d
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 459 deletions.
29 changes: 15 additions & 14 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,27 @@ on:
jobs:
lint:
name: Lint
uses: canonical/data-platform-workflows/.github/workflows/lint.yaml@v16.7.0
uses: canonical/data-platform-workflows/.github/workflows/lint.yaml@v18.0.0

lib-check:
name: Check libraries
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
- run: |
# Workaround for https://github.com/canonical/charmcraft/issues/1389#issuecomment-1880921728
touch requirements.txt
- name: Check libs
uses: canonical/charming-actions/check-libraries@2.4.0
uses: canonical/charming-actions/check-libraries@2.6.0
with:
credentials: ${{ secrets.CHARMHUB_TOKEN }} # FIXME: current token will expire in 2023-07-04
credentials: ${{ secrets.CHARMHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
use-labels: false
fail-build: ${{ github.event_name == 'pull_request' }}

unit-test:
name: Unit test charm
Expand All @@ -50,27 +55,23 @@ jobs:
uses: codecov/codecov-action@v3

build:
name: Build charm | ${{ matrix.path }}
uses: canonical/data-platform-workflows/.github/workflows/[email protected]
strategy:
matrix:
path:
- .
name: Build charm
uses: canonical/data-platform-workflows/.github/workflows/[email protected]
with:
cache: true
path-to-charm-directory: ${{ matrix.path }}

integration-test:
name: Integration test charm | 3.4.4
needs:
- lint
- unit-test
- build
uses: canonical/data-platform-workflows/.github/workflows/integration_test_charm.yaml@v16.7.0
uses: canonical/data-platform-workflows/.github/workflows/integration_test_charm.yaml@v18.0.0
with:
artifact-prefix: packed-charm-cache-true
artifact-prefix: ${{ needs.build.outputs.artifact-prefix }}
cloud: microk8s
microk8s-snap-channel: 1.29-strict/stable
juju-agent-version: 3.4.4
juju-agent-version: 3.4.4 # renovate: juju-agent-pin-minor
_beta_allure_report: true
permissions:
contents: write # Needed for Allure Report beta
6 changes: 3 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ jobs:
uses: ./.github/workflows/ci.yaml
secrets: inherit
permissions:
contents: write # Needed for Allure Report beta
contents: write # Needed for Allure Report beta

build:
name: Build charm
uses: canonical/data-platform-workflows/.github/workflows/build_charm_without_cache.yaml@v16.7.0
uses: canonical/data-platform-workflows/.github/workflows/build_charm.yaml@v18.0.0

release-charm:
name: Release charm
needs:
- ci-tests
- build
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v16.7.0
uses: canonical/data-platform-workflows/.github/workflows/release_charm.yaml@v18.0.0
with:
channel: 6/edge
artifact-name: ${{ needs.build.outputs.artifact-name }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sync_issue_to_jira.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
sync:
name: Sync GitHub issue to Jira
uses: canonical/data-platform-workflows/.github/workflows/sync_issue_to_jira.yaml@v16.7.0
uses: canonical/data-platform-workflows/.github/workflows/sync_issue_to_jira.yaml@v18.0.0
with:
jira-base-url: https://warthogs.atlassian.net
jira-project-key: DPE
Expand Down
69 changes: 57 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,79 @@
# Contributing

To make contributions to this charm, you'll need a working [development setup](https://juju.is/docs/sdk/dev-setup).
## Overview

You can create an environment for development with `tox`:
This documents explains the processes and practices recommended for contributing enhancements to
this operator.

- Generally, before developing enhancements to this charm, you should consider
[opening an issue
](https://github.com/canonical/mongos-k8s-operator/issues) explaining
your use case.
- If you would like to chat with us about your use-cases or proposed
implementation, you can reach us at [Canonical Mattermost public
channel](https://chat.charmhub.io/charmhub/channels/charm-dev) or
[Discourse](https://discourse.charmhub.io/).
- Familiarising yourself with the [Charmed Operator
Framework](https://juju.is/docs/sdk) library will help you a lot when working
on new features or bug fixes.
- All enhancements require review before being merged. Code review typically
examines
- code quality
- test coverage
- user experience for Juju administrators this charm.
- Please help us out in ensuring easy to review branches by rebasing your pull
request branch onto the `main` branch. This also avoids merge commits and
creates a linear Git commit history.

## Developing
Install `tox`, `poetry`, and `charmcraftcache`

Install pipx: https://pipx.pypa.io/stable/installation/
```shell
tox devenv -e integration
source venv/bin/activate
pipx install tox
pipx install poetry
pipx install charmcraftcache
```

## Testing
You can create an environment for development:

```shell
poetry install
```

This project uses `tox` for managing test environments. There are some pre-configured environments
that can be used for linting and formatting code when you're preparing contributions to the charm:
### Testing

```shell
tox run -e format # update your code according to linting rules
tox run -e lint # code style
tox run -e static # static type checking
tox run -e unit # unit tests
tox run -e integration # integration tests
tox # runs 'format', 'lint', 'static', and 'unit' environments
tox # runs 'lint' and 'unit' environments
```

## Build the charm
## Build charm

Build the charm in this git repository using:

```shell
charmcraft pack
tox run -e build-dev
```

<!-- You may want to include any contribution/style guidelines in this document>
### Deploy

```bash
# Create a model
juju add-model dev
# Enable DEBUG logging
juju model-config logging-config="<root>=INFO;unit=DEBUG"
# Deploy the charm
# `--trust` needed if Role Based Access Control (RBAC) (https://kubernetes.io/docs/concepts/security/rbac-good-practices/) is enabled on Kubernetes
juju deploy ./mongos-k8s-operator_ubuntu-20.04-amd64.charm \
--resource ghcr.io/canonical/charmed-mongodb:6.0.6-22.04_edge@sha256:b4b3edb805b20de471da57802643bfadbf979f112d738bc540ab148d145ddcfe --trust
```

## Canonical Contributor Agreement

Canonical welcomes contributions to the Charmed MySQL-Router Operator. Please
check out our [contributor agreement](https://ubuntu.com/legal/contributors) if
you're interested in contributing to the solution.
31 changes: 19 additions & 12 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
# Copyright 2023 Canonical Ltd.
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

type: "charm"
type: charm
bases:
- name: ubuntu
channel: "22.04"
architectures: [amd64]
parts:
charm:
override-pull: |
craftctl default
if [[ ! -f requirements.txt ]]
then
echo 'ERROR: Use "tox run -e build-dev" instead of calling "charmcraft pack" directly' >&2
exit 1
fi
override-build: |
rustup default stable
craftctl default
charm-strict-dependencies: true
build-snaps:
- rustup
build-packages:
- build-essential
- libffi-dev
- libssl-dev
- pkg-config
- rustc
- cargo
bases:
- build-on:
- name: "ubuntu"
channel: "22.04"
run-on:
- name: "ubuntu"
channel: "22.04"
8 changes: 5 additions & 3 deletions lib/charms/mongos/v0/mongos_client_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
shards.
"""
import logging
from ops.framework import Object
from ops.charm import CharmBase
from charms.data_platform_libs.v0.data_interfaces import (
DatabaseProvides,
)

from charms.data_platform_libs.v0.data_interfaces import DatabaseProvides
from charms.mongodb.v1.mongos import MongosConfiguration
from ops.charm import CharmBase
from ops.framework import Object

logger = logging.getLogger(__name__)
DATABASE_KEY = "database"
Expand Down
1 change: 1 addition & 0 deletions lib/charms/mongos/v0/set_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ops.framework import Object
from ops.model import StatusBase


# The unique Charmhub library identifier, never change it
LIBID = "0713372afa0841359edbb777273ecdbf"

Expand Down
Loading

0 comments on commit 527df8d

Please sign in to comment.