Skip to content

Commit c460398

Browse files
ZvirovyiBON4
andauthored
[DPE-7476] Basic charm structure (#1)
* Repo move * Update LICENSE Co-authored-by: Vladyslav Tarasenko <[email protected]> * Update LICENSE Co-authored-by: Vladyslav Tarasenko <[email protected]> * Update README.md Co-authored-by: Vladyslav Tarasenko <[email protected]> * Update src/common/cassandra_client.py Co-authored-by: Vladyslav Tarasenko <[email protected]> * Update src/common/exceptions.py Co-authored-by: Vladyslav Tarasenko <[email protected]> * Update src/common/literals.py Co-authored-by: Vladyslav Tarasenko <[email protected]> * Update src/common/management_client.py Co-authored-by: Vladyslav Tarasenko <[email protected]> * Update src/common/models.py Co-authored-by: Vladyslav Tarasenko <[email protected]> * Update src/common/workload.py Co-authored-by: Vladyslav Tarasenko <[email protected]> * Update src/core/charm.py Co-authored-by: Vladyslav Tarasenko <[email protected]> * Update src/core/cluster.py Co-authored-by: Vladyslav Tarasenko <[email protected]> * Update src/workload.py Co-authored-by: Vladyslav Tarasenko <[email protected]> * Update src/core/context.py Co-authored-by: Vladyslav Tarasenko <[email protected]> * Update src/events/cassandra.py Co-authored-by: Vladyslav Tarasenko <[email protected]> * Update src/managers/cluster.py Co-authored-by: Vladyslav Tarasenko <[email protected]> * Update src/managers/config.py Co-authored-by: Vladyslav Tarasenko <[email protected]> * Refactor #1 * Refactor #2 * Format. * Fix of #1. * Refactor. * Typing refactor. * Refactor. * Refactor. * Review suggestions. * Use jubilant instead of pytest-operator. * Move config to the core level. Don't use config class in config manager. * Move all charm spec to single charmcraft.yaml file. Update data_models.py lib to v1. * Move statuses.py and workload.py from common to core. * Move classes from literals. Move module-specific constants from literals to their specific module. * Get rid of CassandraCharmBase. * Add charmlibs-pathops. Add paths to workload. * Use charmlibs-pathops in workload. * Use published snap. * Summary & description. * Get rid of pytest-asyncio. Fix integration test. * Use literal instead of manual validation for profile config option. * Get rid of literals in common. * Remove state management from cluster manager. * Typo fix. * Render cassandra.yaml config without read. * Get rid of editing cassandra-env.sh file. * Get rid of editing cassandra-env.sh file. * Review suggestions. * Update snap revision. * Remove init args from CassandraPaths. * Don't use restart layer in cluster manager. * Improve env config logic. Review suggestions. --------- Co-authored-by: Vladyslav Yurchenko <[email protected]>
1 parent 3695aae commit c460398

25 files changed

+9101
-2
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
venv/
2+
build/
3+
*.charm
4+
*.snap
5+
.tox/
6+
.coverage
7+
__pycache__/
8+
*.py[cod]
9+
.idea
10+
.vscode/

CONTRIBUTING.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Contributing
2+
3+
To make contributions to this charm, you'll need a working [development setup](https://juju.is/docs/sdk/dev-setup).
4+
5+
You can create an environment for development with `tox`:
6+
7+
```shell
8+
tox devenv -e integration
9+
source venv/bin/activate
10+
```
11+
12+
## Testing
13+
14+
This project uses `tox` for managing test environments. There are some pre-configured environments
15+
that can be used for linting and formatting code when you're preparing contributions to the charm:
16+
17+
```shell
18+
tox run -e format # update your code according to linting rules
19+
tox run -e lint # code style
20+
tox run -e static # static type checking
21+
tox run -e unit # unit tests
22+
tox run -e integration # integration tests
23+
tox # runs 'format', 'lint', 'static', and 'unit' environments
24+
```
25+
26+
## Build the charm
27+
28+
Build the charm in this git repository using:
29+
30+
```shell
31+
charmcraft pack
32+
```
33+
34+
<!-- You may want to include any contribution/style guidelines in this document>

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
1-
# cassandra-operator
2-
Charmed Operator for Apache Cassandra
1+
# Charmed Apache Cassandra Operator
2+
3+
Apache Cassandra is a free and open-source database management system designed to handle large volumes of data across multiple commodity servers. This charm deploys and operate Apache Cassandra on a VM machine environment.
4+
Apache Cassandra is a free and open-source software project by the Apache Software Foundation.
5+
More info can be found at the [Apache Cassandra project page](https://cassandra.apache.org/_/index.html).
6+
7+
## Other resources
8+
9+
- [Contributing](CONTRIBUTING.md) <!-- or link to other contribution documentation -->
10+
11+
- See the [Juju SDK documentation](https://juju.is/docs/sdk) for more information about developing and improving charms.

charmcraft.yaml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Copyright 2025 Canonical Ltd.
2+
# See LICENSE file for licensing details.
3+
4+
type: charm
5+
platforms:
6+
7+
8+
name: cassandra
9+
summary: |
10+
Charmed Apache Cassandra Operator
11+
description: |
12+
Apache Cassandra is a free and open-source database management system designed to handle large volumes of data across multiple commodity servers. This charm deploys and operate Apache Cassandra on a VM machine environment.
13+
Apache Cassandra is a free and open-source software project by the Apache Software Foundation.
14+
Users can find out more at the [Apache Cassandra project page](https://cassandra.apache.org/_/index.html).
15+
16+
charm-libs:
17+
- lib: operator_libs_linux.snap
18+
version: "2"
19+
- lib: data_platform_libs.data_models
20+
version: "1"
21+
- lib: data_platform_libs.data_interfaces
22+
version: "0"
23+
24+
config:
25+
options:
26+
profile:
27+
# TODO: description
28+
type: string
29+
default: production
30+
cluster_name:
31+
# TODO: description
32+
type: string
33+
default: Test Cluster
34+
35+
peers:
36+
cassandra-peers:
37+
interface: cassandra_peers
38+
39+
parts:
40+
# "poetry-deps" part name is a magic constant
41+
# https://github.com/canonical/craft-parts/pull/901
42+
poetry-deps:
43+
plugin: nil
44+
build-packages:
45+
- curl
46+
override-build: |
47+
# Use environment variable instead of `--break-system-packages` to avoid failing on older
48+
# versions of pip that do not recognize `--break-system-packages`
49+
# `--user` needed (in addition to `--break-system-packages`) for Ubuntu >=24.04
50+
PIP_BREAK_SYSTEM_PACKAGES=true python3 -m pip install --user --upgrade pip==24.3.1 # renovate: charmcraft-pip-latest
51+
52+
# Use uv to install poetry so that a newer version of Python can be installed if needed by poetry
53+
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/uv/releases/download/0.5.15/uv-installer.sh | sh # renovate: charmcraft-uv-latest
54+
# poetry 2.0.0 requires Python >=3.9
55+
if ! "$HOME/.local/bin/uv" python find '>=3.9'
56+
then
57+
# Use first Python version that is >=3.9 and available in an Ubuntu LTS
58+
# (to reduce the number of Python versions we use)
59+
"$HOME/.local/bin/uv" python install 3.10.12 # renovate: charmcraft-python-ubuntu-22.04
60+
fi
61+
"$HOME/.local/bin/uv" tool install --no-python-downloads --python '>=3.9' poetry==2.0.0 --with poetry-plugin-export==1.8.0 # renovate: charmcraft-poetry-latest
62+
63+
ln -sf "$HOME/.local/bin/poetry" /usr/local/bin/poetry
64+
# "charm-poetry" part name is arbitrary; use for consistency
65+
# Avoid using "charm" part name since that has special meaning to charmcraft
66+
charm-poetry:
67+
# By default, the `poetry` plugin creates/stages these directories:
68+
# - lib, src
69+
# (https://github.com/canonical/charmcraft/blob/9ff19c328e23b50cc06f04e8a5ad4835740badf4/charmcraft/parts/plugins/_poetry.py#L76-L78)
70+
# - venv
71+
# (https://github.com/canonical/charmcraft/blob/9ff19c328e23b50cc06f04e8a5ad4835740badf4/charmcraft/parts/plugins/_poetry.py#L95
72+
# https://github.com/canonical/craft-parts/blob/afb0d652eb330b6aaad4f40fbd6e5357d358de47/craft_parts/plugins/base.py#L270)
73+
plugin: poetry
74+
source: .
75+
after:
76+
- poetry-deps
77+
poetry-export-extra-args: ["--only", "main,charm-libs"]
78+
poetry-pip-extra-args: ["--only-binary=cassandra-driver"]
79+
build-packages:
80+
- libffi-dev # Needed to build Python dependencies with Rust from source
81+
- libssl-dev # Needed to build Python dependencies with Rust from source
82+
- pkg-config # Needed to build Python dependencies with Rust from source
83+
- libev-dev
84+
override-build: |
85+
# Workaround for https://github.com/canonical/charmcraft/issues/2068
86+
# rustup used to install rustc and cargo, which are needed to build Python dependencies with Rust from source
87+
if [[ "$CRAFT_PLATFORM" == [email protected]:* || "$CRAFT_PLATFORM" == [email protected]:* ]]
88+
then
89+
snap install rustup --classic
90+
else
91+
apt-get install rustup -y
92+
fi
93+
94+
# If Ubuntu version < 24.04, rustup was installed from snap instead of from the Ubuntu
95+
# archive—which means the rustup version could be updated at any time. Print rustup version
96+
# to build log to make changes to the snap's rustup version easier to track
97+
rustup --version
98+
99+
# rpds-py (Python package) >=0.19.0 requires rustc >=1.76, which is not available in the
100+
# Ubuntu 22.04 archive. Install rustc and cargo using rustup instead of the Ubuntu archive
101+
rustup set profile minimal
102+
rustup default 1.87.0 # renovate: charmcraft-rust-latest
103+
104+
craftctl default
105+
# Include requirements.txt in *.charm artifact for easier debugging
106+
cp requirements.txt "$CRAFT_PART_INSTALL/requirements.txt"
107+
108+
# "files" part name is arbitrary; use for consistency
109+
files:
110+
plugin: dump
111+
source: .
112+
stage:
113+
- LICENSE

0 commit comments

Comments
 (0)