From a26c76b41e77591c2c550439dfdca2a9a610e62a Mon Sep 17 00:00:00 2001 From: matt-hagemann Date: Fri, 22 Sep 2023 16:06:59 +0200 Subject: [PATCH 01/11] feat(charm): add vm charm --- {operator => k8s_operator}/CONTRIBUTING.md | 0 {operator => k8s_operator}/LICENSE | 0 {operator => k8s_operator}/README.md | 2 +- {operator => k8s_operator}/charmcraft.yaml | 0 .../data_platform_libs/v0/data_interfaces.py | 0 .../lib/charms/traefik_k8s/v2/ingress.py | 0 .../ratings_api/ratings_features_app_pb2.py | 0 .../ratings_features_app_pb2_grpc.py | 0 .../ratings_api/ratings_features_chart_pb2.py | 0 .../ratings_features_chart_pb2_grpc.py | 0 .../ratings_api/ratings_features_user_pb2.py | 0 .../ratings_features_user_pb2_grpc.py | 0 {operator => k8s_operator}/metadata.yaml | 0 {operator => k8s_operator}/pyproject.toml | 0 {operator => k8s_operator}/requirements.txt | 0 {operator => k8s_operator}/src/charm.py | 0 {operator => k8s_operator}/src/database.py | 0 {operator => k8s_operator}/src/ratings.py | 0 .../tests/integration/test_charm.py | 0 .../tests/unit/test_charm.py | 0 .../tests/unit/test_ratings.py | 0 {operator => k8s_operator}/tox.ini | 0 .../20230829085908_ratings_init.down.sql | 10 +- .../20230829085908_ratings_init.up.sql | 11 +- src/main.rs | 3 + vm_operator/CONTRIBUTING.md | 33 + vm_operator/LICENSE | 202 +++ vm_operator/README.md | 23 + vm_operator/actions.yaml | 2 + vm_operator/charmcraft.yaml | 17 + vm_operator/config.yaml | 29 + .../data_platform_libs/v0/data_interfaces.py | 1484 +++++++++++++++++ .../lib/charms/operator_libs_linux/v0/apt.py | 1321 +++++++++++++++ .../charms/operator_libs_linux/v0/systemd.py | 186 +++ .../lib/charms/traefik_k8s/v2/ingress.py | 696 ++++++++ .../ratings_api/ratings_features_app_pb2.py | 30 + .../ratings_features_app_pb2_grpc.py | 66 + .../ratings_api/ratings_features_chart_pb2.py | 36 + .../ratings_features_chart_pb2_grpc.py | 66 + .../ratings_api/ratings_features_user_pb2.py | 41 + .../ratings_features_user_pb2_grpc.py | 199 +++ vm_operator/metadata.yaml | 22 + vm_operator/pyproject.toml | 43 + vm_operator/requirements.txt | 3 + vm_operator/src/charm.py | 228 +++ vm_operator/templates/ratings-service.j2 | 25 + vm_operator/tests/integration/test_charm.py | 142 ++ vm_operator/tests/unit/test_charm.py | 153 ++ vm_operator/tests/unit/test_ratings.py | 57 + vm_operator/tox.ini | 105 ++ 50 files changed, 5224 insertions(+), 11 deletions(-) rename {operator => k8s_operator}/CONTRIBUTING.md (100%) rename {operator => k8s_operator}/LICENSE (100%) rename {operator => k8s_operator}/README.md (91%) rename {operator => k8s_operator}/charmcraft.yaml (100%) rename {operator => k8s_operator}/lib/charms/data_platform_libs/v0/data_interfaces.py (100%) rename {operator => k8s_operator}/lib/charms/traefik_k8s/v2/ingress.py (100%) rename {operator => k8s_operator}/lib/ratings_api/ratings_features_app_pb2.py (100%) rename {operator => k8s_operator}/lib/ratings_api/ratings_features_app_pb2_grpc.py (100%) rename {operator => k8s_operator}/lib/ratings_api/ratings_features_chart_pb2.py (100%) rename {operator => k8s_operator}/lib/ratings_api/ratings_features_chart_pb2_grpc.py (100%) rename {operator => k8s_operator}/lib/ratings_api/ratings_features_user_pb2.py (100%) rename {operator => k8s_operator}/lib/ratings_api/ratings_features_user_pb2_grpc.py (100%) rename {operator => k8s_operator}/metadata.yaml (100%) rename {operator => k8s_operator}/pyproject.toml (100%) rename {operator => k8s_operator}/requirements.txt (100%) rename {operator => k8s_operator}/src/charm.py (100%) rename {operator => k8s_operator}/src/database.py (100%) rename {operator => k8s_operator}/src/ratings.py (100%) rename {operator => k8s_operator}/tests/integration/test_charm.py (100%) rename {operator => k8s_operator}/tests/unit/test_charm.py (100%) rename {operator => k8s_operator}/tests/unit/test_ratings.py (100%) rename {operator => k8s_operator}/tox.ini (100%) create mode 100644 vm_operator/CONTRIBUTING.md create mode 100644 vm_operator/LICENSE create mode 100644 vm_operator/README.md create mode 100644 vm_operator/actions.yaml create mode 100644 vm_operator/charmcraft.yaml create mode 100644 vm_operator/config.yaml create mode 100644 vm_operator/lib/charms/data_platform_libs/v0/data_interfaces.py create mode 100644 vm_operator/lib/charms/operator_libs_linux/v0/apt.py create mode 100644 vm_operator/lib/charms/operator_libs_linux/v0/systemd.py create mode 100644 vm_operator/lib/charms/traefik_k8s/v2/ingress.py create mode 100644 vm_operator/lib/ratings_api/ratings_features_app_pb2.py create mode 100644 vm_operator/lib/ratings_api/ratings_features_app_pb2_grpc.py create mode 100644 vm_operator/lib/ratings_api/ratings_features_chart_pb2.py create mode 100644 vm_operator/lib/ratings_api/ratings_features_chart_pb2_grpc.py create mode 100644 vm_operator/lib/ratings_api/ratings_features_user_pb2.py create mode 100644 vm_operator/lib/ratings_api/ratings_features_user_pb2_grpc.py create mode 100644 vm_operator/metadata.yaml create mode 100644 vm_operator/pyproject.toml create mode 100644 vm_operator/requirements.txt create mode 100755 vm_operator/src/charm.py create mode 100644 vm_operator/templates/ratings-service.j2 create mode 100644 vm_operator/tests/integration/test_charm.py create mode 100644 vm_operator/tests/unit/test_charm.py create mode 100644 vm_operator/tests/unit/test_ratings.py create mode 100644 vm_operator/tox.ini diff --git a/operator/CONTRIBUTING.md b/k8s_operator/CONTRIBUTING.md similarity index 100% rename from operator/CONTRIBUTING.md rename to k8s_operator/CONTRIBUTING.md diff --git a/operator/LICENSE b/k8s_operator/LICENSE similarity index 100% rename from operator/LICENSE rename to k8s_operator/LICENSE diff --git a/operator/README.md b/k8s_operator/README.md similarity index 91% rename from operator/README.md rename to k8s_operator/README.md index 33fa1bf..042471a 100644 --- a/operator/README.md +++ b/k8s_operator/README.md @@ -17,7 +17,7 @@ image="$(yq '.resources."ratings-image"."upstream-source"' metadata.yaml)" juju deploy ./ubuntu-software-ratings_ubuntu-22.04-amd64.charm ratings \ --resource ratings-image="$image" -juju deploy postgresql-k8s postgres --channel latest/edge +juju deploy postgresql --channel edge juju relate ratings postgresql ``` diff --git a/operator/charmcraft.yaml b/k8s_operator/charmcraft.yaml similarity index 100% rename from operator/charmcraft.yaml rename to k8s_operator/charmcraft.yaml diff --git a/operator/lib/charms/data_platform_libs/v0/data_interfaces.py b/k8s_operator/lib/charms/data_platform_libs/v0/data_interfaces.py similarity index 100% rename from operator/lib/charms/data_platform_libs/v0/data_interfaces.py rename to k8s_operator/lib/charms/data_platform_libs/v0/data_interfaces.py diff --git a/operator/lib/charms/traefik_k8s/v2/ingress.py b/k8s_operator/lib/charms/traefik_k8s/v2/ingress.py similarity index 100% rename from operator/lib/charms/traefik_k8s/v2/ingress.py rename to k8s_operator/lib/charms/traefik_k8s/v2/ingress.py diff --git a/operator/lib/ratings_api/ratings_features_app_pb2.py b/k8s_operator/lib/ratings_api/ratings_features_app_pb2.py similarity index 100% rename from operator/lib/ratings_api/ratings_features_app_pb2.py rename to k8s_operator/lib/ratings_api/ratings_features_app_pb2.py diff --git a/operator/lib/ratings_api/ratings_features_app_pb2_grpc.py b/k8s_operator/lib/ratings_api/ratings_features_app_pb2_grpc.py similarity index 100% rename from operator/lib/ratings_api/ratings_features_app_pb2_grpc.py rename to k8s_operator/lib/ratings_api/ratings_features_app_pb2_grpc.py diff --git a/operator/lib/ratings_api/ratings_features_chart_pb2.py b/k8s_operator/lib/ratings_api/ratings_features_chart_pb2.py similarity index 100% rename from operator/lib/ratings_api/ratings_features_chart_pb2.py rename to k8s_operator/lib/ratings_api/ratings_features_chart_pb2.py diff --git a/operator/lib/ratings_api/ratings_features_chart_pb2_grpc.py b/k8s_operator/lib/ratings_api/ratings_features_chart_pb2_grpc.py similarity index 100% rename from operator/lib/ratings_api/ratings_features_chart_pb2_grpc.py rename to k8s_operator/lib/ratings_api/ratings_features_chart_pb2_grpc.py diff --git a/operator/lib/ratings_api/ratings_features_user_pb2.py b/k8s_operator/lib/ratings_api/ratings_features_user_pb2.py similarity index 100% rename from operator/lib/ratings_api/ratings_features_user_pb2.py rename to k8s_operator/lib/ratings_api/ratings_features_user_pb2.py diff --git a/operator/lib/ratings_api/ratings_features_user_pb2_grpc.py b/k8s_operator/lib/ratings_api/ratings_features_user_pb2_grpc.py similarity index 100% rename from operator/lib/ratings_api/ratings_features_user_pb2_grpc.py rename to k8s_operator/lib/ratings_api/ratings_features_user_pb2_grpc.py diff --git a/operator/metadata.yaml b/k8s_operator/metadata.yaml similarity index 100% rename from operator/metadata.yaml rename to k8s_operator/metadata.yaml diff --git a/operator/pyproject.toml b/k8s_operator/pyproject.toml similarity index 100% rename from operator/pyproject.toml rename to k8s_operator/pyproject.toml diff --git a/operator/requirements.txt b/k8s_operator/requirements.txt similarity index 100% rename from operator/requirements.txt rename to k8s_operator/requirements.txt diff --git a/operator/src/charm.py b/k8s_operator/src/charm.py similarity index 100% rename from operator/src/charm.py rename to k8s_operator/src/charm.py diff --git a/operator/src/database.py b/k8s_operator/src/database.py similarity index 100% rename from operator/src/database.py rename to k8s_operator/src/database.py diff --git a/operator/src/ratings.py b/k8s_operator/src/ratings.py similarity index 100% rename from operator/src/ratings.py rename to k8s_operator/src/ratings.py diff --git a/operator/tests/integration/test_charm.py b/k8s_operator/tests/integration/test_charm.py similarity index 100% rename from operator/tests/integration/test_charm.py rename to k8s_operator/tests/integration/test_charm.py diff --git a/operator/tests/unit/test_charm.py b/k8s_operator/tests/unit/test_charm.py similarity index 100% rename from operator/tests/unit/test_charm.py rename to k8s_operator/tests/unit/test_charm.py diff --git a/operator/tests/unit/test_ratings.py b/k8s_operator/tests/unit/test_ratings.py similarity index 100% rename from operator/tests/unit/test_ratings.py rename to k8s_operator/tests/unit/test_ratings.py diff --git a/operator/tox.ini b/k8s_operator/tox.ini similarity index 100% rename from operator/tox.ini rename to k8s_operator/tox.ini diff --git a/sql/migrations/20230829085908_ratings_init.down.sql b/sql/migrations/20230829085908_ratings_init.down.sql index a2ba528..7274c21 100644 --- a/sql/migrations/20230829085908_ratings_init.down.sql +++ b/sql/migrations/20230829085908_ratings_init.down.sql @@ -1,8 +1,8 @@ -REVOKE ALL PRIVILEGES ON TABLE users FROM service; -REVOKE USAGE, SELECT ON SEQUENCE users_id_seq FROM service; -REVOKE ALL PRIVILEGES ON TABLE votes FROM service; -REVOKE USAGE, SELECT ON SEQUENCE votes_id_seq FROM service; -REVOKE CONNECT ON DATABASE ratings FROM service; +REVOKE ALL PRIVILEGES ON TABLE users FROM CURRENT_USER; +REVOKE USAGE, SELECT ON SEQUENCE users_id_seq FROM CURRENT_USER; +REVOKE ALL PRIVILEGES ON TABLE votes FROM CURRENT_USER; +REVOKE USAGE, SELECT ON SEQUENCE votes_id_seq FROM CURRENT_USER; +REVOKE CONNECT ON DATABASE ratings FROM CURRENT_USER; DROP TABLE IF EXISTS votes; DROP TABLE IF EXISTS users; diff --git a/sql/migrations/20230829085908_ratings_init.up.sql b/sql/migrations/20230829085908_ratings_init.up.sql index e780526..2f1f695 100644 --- a/sql/migrations/20230829085908_ratings_init.up.sql +++ b/sql/migrations/20230829085908_ratings_init.up.sql @@ -31,8 +31,9 @@ CREATE TABLE votes ( -- can't vote more than once for the same snap revision. CREATE UNIQUE INDEX idx_votes_unique_user_snap ON votes (user_id_fk, snap_id, snap_revision); -GRANT ALL PRIVILEGES ON TABLE users TO service; -GRANT USAGE, SELECT ON SEQUENCE users_id_seq TO service; -GRANT ALL PRIVILEGES ON TABLE votes TO service; -GRANT USAGE, SELECT ON SEQUENCE votes_id_seq TO service; -GRANT CONNECT ON DATABASE ratings TO service; +-- Grant privileges to the user currently running the script +GRANT ALL PRIVILEGES ON TABLE users TO CURRENT_USER; +GRANT USAGE, SELECT ON SEQUENCE users_id_seq TO CURRENT_USER; +GRANT ALL PRIVILEGES ON TABLE votes TO CURRENT_USER; +GRANT USAGE, SELECT ON SEQUENCE votes_id_seq TO CURRENT_USER; +GRANT CONNECT ON DATABASE ratings TO CURRENT_USER; diff --git a/src/main.rs b/src/main.rs index ba84b6a..b0d6fd5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,9 @@ async fn main() -> Result<(), Box> { tracing::info!("Starting Ubuntu App Rating Service"); + tracing::info!("Config I have: {:?}", config); + tracing::info!("I have been update again, yippie!"); + app::run(config).await?; Ok(()) diff --git a/vm_operator/CONTRIBUTING.md b/vm_operator/CONTRIBUTING.md new file mode 100644 index 0000000..288f021 --- /dev/null +++ b/vm_operator/CONTRIBUTING.md @@ -0,0 +1,33 @@ +# Contributing + +To make contributions to this charm, you'll need a working [development setup](https://juju.is/docs/sdk/dev-setup). + +You can create an environment for development with `tox`: + +```shell +tox devenv -e integration +source venv/bin/activate +``` + +## Testing + +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: + +```shell +tox run -e format # update your code according to linting rules +tox run -e lint # code style +tox run -e unit # unit tests +tox run -e integration # integration tests +tox # runs 'format', 'lint', and 'unit' environments +``` + +## Build the charm + +Build the charm in this git repository using: + +```shell +charmcraft pack +``` + +