Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(charm): add vm charm #7

Merged
merged 11 commits into from
Oct 4, 2023
Merged
31 changes: 2 additions & 29 deletions .github/workflows/build-charm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
run: python3 -m pip install tox
- name: Run linters
run: |
cd operator
cd vm_operator
tox -e lint

unit-test:
Expand All @@ -27,32 +27,5 @@ jobs:
run: python -m pip install tox
- name: Run tests
run: |
cd operator
cd vm_operator
tox -e unit

integration-test:
name: Integration tests (microk8s)
runs-on: ubuntu-22.04
needs:
- lint
- unit-test
steps:
- name: Checkout
uses: actions/checkout@v4
# Do some preemptive setup for the ingress integration test so that our
# bogus dns name resolves properly.
- name: Setup hosts for tests
run: |
echo "10.64.140.43 testing-ratings.foo.bar" | sudo tee -a /etc/hosts
- name: Setup operator environment
uses: charmed-kubernetes/actions-operator@main
with:
provider: microk8s
channel: 1.27-strict/stable
juju-channel: 3.2/stable
microk8s-group: snap_microk8s
microk8s-addons: "hostpath-storage dns metallb:10.64.140.43-10.64.140.43"
- name: Run integration tests
run: |
cd operator
tox -e integration -- --model=testing
22 changes: 0 additions & 22 deletions .github/workflows/build-rock.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/pull-request-charm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Pull Request (Charm)
on:
pull_request:
paths:
- operator/**
- vm_operator/**

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Pull Request
on:
pull_request:
paths-ignore:
- operator/**
- vm_operator/**

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -12,6 +12,3 @@ concurrency:
jobs:
build:
uses: ./.github/workflows/build.yaml

build-rock:
uses: ./.github/workflows/build-rock.yaml
2 changes: 1 addition & 1 deletion .github/workflows/push-charm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- main
paths:
- operator/**
- vm_operator/**

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
33 changes: 0 additions & 33 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,3 @@ concurrency:
jobs:
build:
uses: ./.github/workflows/build.yaml

build-rock:
uses: ./.github/workflows/build-rock.yaml

publish-rock:
name: Publish ROCK to GHCR
runs-on: ubuntu-latest
needs:
- build-rock
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Fetch ROCK artifact
uses: actions/download-artifact@v3
with:
name: ratings-rock

- name: Upload ROCK to ghcr.io
run: |
commit="$(git rev-parse --short HEAD)"

# Upload ROCK to ghcr.io/tim-hm/ratings:main-<commit>
sudo skopeo --insecure-policy copy \
"oci-archive:$(realpath ./ratings_*.rock)" \
"docker://ghcr.io/tim-hm/ratings:main-${commit}" \
--dest-creds "${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}"

# Upload ROCK to ghcr.io/tim-hm/ratings:latest
sudo skopeo --insecure-policy copy \
"oci-archive:$(realpath ./ratings_*.rock)" \
"docker://ghcr.io/tim-hm/ratings:latest" \
--dest-creds "${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}"
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion operator/README.md → k8s_operator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 5 additions & 5 deletions sql/migrations/20230829085908_ratings_init.down.sql
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
11 changes: 6 additions & 5 deletions sql/migrations/20230829085908_ratings_init.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;
5 changes: 4 additions & 1 deletion tests/user_tests/simple_lifecycle_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ async fn delete(data: TestData) -> TestData {
.await;

let Err(sqlx::Error::RowNotFound) = result else {
panic!("The user {} still exists in the database or there was a database error", id);
panic!(
"The user {} still exists in the database or there was a database error",
id
);
};

data
Expand Down
33 changes: 33 additions & 0 deletions vm_operator/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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
```

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