Skip to content
Merged
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 .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
max-line-length = 99
select: E,W,F,C,N
exclude:
venv
.venv
.git
build
dist
Expand Down
144 changes: 80 additions & 64 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,60 @@ jobs:

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install uv
run: pip install uv

- name: Create uv virtualenv
run: uv venv

- name: Install dependencies for testing
run: |
pip install -r requirements-dev.txt
source .venv/bin/activate
uv pip install ".[dev]"

- name: Run tests
run: |
source .venv/bin/activate
./run_tests


build:
name: Build charms
name: Build charm
needs: unit-tests
uses: canonical/data-platform-workflows/.github/workflows/build_charms_with_cache.yaml@v4
with:
charmcraft-snap-channel: 2.x/stable
artifact-name: charm-packed
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install uv
run: pip install uv

- name: Set up LXD
uses: canonical/setup-lxd@90d76101915da56a42a562ba766b1a77019242fd

- name: Add runner to lxd group
run: |
sudo usermod -a -G lxd $USER
newgrp lxd

- name: Install charmcraft
run: sudo snap install charmcraft --classic --channel=3.x/stable

- name: Pack charm
run: sg lxd -c "charmcraft pack"

- name: Upload charm artifact
uses: actions/upload-artifact@v4
with:
name: charm
path: "*.charm"

channel:
name: Select Charmhub channel
Expand All @@ -55,7 +91,7 @@ jobs:
set -eux
case ${{ github.ref_name }} in
3.* | 4.*)
TRACK="${{ github.ref_name }}"
TRACK=$(echo "${{ github.ref_name }}" | awk -F "-" '{print $1}')
DO_RELEASE=true
;;
main)
Expand Down Expand Up @@ -84,20 +120,24 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Download packed charm
id: download
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: ${{ needs.build.outputs.artifact-name }}
name: charm

- name: Upload charm to Charmhub
- name: Upload charms to Charmhub
env:
CHARMCRAFT_AUTH: ${{ secrets.CHARMCRAFT_AUTH }}
run: |
sudo snap install charmcraft --channel 2.x/stable --classic
charmcraft upload ${{ steps.download.outputs.download-path }}/*.charm \
--name $CHARM_NAME \
--release ${{ needs.channel.outputs.test }}
sudo snap install charmcraft --channel 3.x/stable --classic
for FILE in *.charm; do
echo "Uploading: $FILE"
charmcraft upload --name "$CHARM_NAME" --release "${{ needs.channel.outputs.test }}" "$FILE"
done


integration:
Expand All @@ -108,36 +148,23 @@ jobs:
fail-fast: false
matrix:
cloud: ["lxd", "microk8s"]
env:
LOCAL_CHARM_PATH: ${{ github.workspace }}/controller.charm

steps:
- name: Download packed charm
id: download
uses: actions/download-artifact@v3
with:
name: ${{ needs.build.outputs.artifact-name }}

- name: Rename charm file
run: |
mv ${{ steps.download.outputs.download-path }}/*.charm \
$LOCAL_CHARM_PATH

- name: Save charmcraft logs as artifact
if: always() && steps.charmcraft.outcome != 'skipped'
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: charmcraft-upload-logs
path: ~/.local/state/charmcraft/log/
continue-on-error: true

- name: Set up LXD
- name: Setup LXD
if: matrix.cloud == 'lxd'
uses: canonical/setup-lxd@90d76101915da56a42a562ba766b1a77019242fd
uses: canonical/setup-lxd@2fa6235ef2dfd3288e0de09edac03f2ebf922968

- name: Set up MicroK8s
if: matrix.cloud == 'microk8s'
uses: balchua/microk8s-actions@v0.3.1
uses: balchua/microk8s-actions@v0.4.2
with:
channel: "1.25-strict/stable"
addons: '["dns", "hostpath-storage"]'
Expand All @@ -150,52 +177,41 @@ jobs:
if: matrix.cloud == 'lxd'
run: |
juju bootstrap lxd c \
--controller-charm-path=$LOCAL_CHARM_PATH
--controller-charm-channel=${{ needs.channel.outputs.test }}

- name: Bootstrap on MicroK8s
if: matrix.cloud == 'microk8s'
run: |
sg snap_microk8s <<EOF
juju bootstrap microk8s c \
--controller-charm-path=$CHARM_NAME \
--controller-charm-channel=${{ needs.channel.outputs.test }}
EOF

- name: Check charm status
run: |
juju switch controller
juju wait-for application controller --timeout 1m
juju status

# TODO: test integration with dashboard / ha-proxy


release:
name: "Release to edge"
runs-on: ubuntu-latest
needs: [upload, channel, integration]
env:
CHARMCRAFT_AUTH: ${{ secrets.CHARMCRAFT_AUTH }}

steps:
- name: Install Charmcraft
run: |
sudo snap install charmcraft --channel 2.x/stable --classic

- name: Get uploaded revision
id: revision
env:
CHANNEL: ${{ needs.channel.outputs.test }}
start_time="$(date -u +%s)"
until [[ $(juju status --format=json 2>/dev/null | jq -r '.applications.controller["application-status"].current') == "active" ]]; do
echo "Waiting for controller to become active..."
juju status
sleep 10

elapsed=$(date -u +%s)-${start_time}
if [[ ${elapsed} -ge 600 ]]; then
echo "Timed out waiting for controller to become active"
juju status
exit 1
fi
done

- name: Get some info for debugging
if: failure()
run: |
set -x
TRACK=$(echo $CHANNEL | cut -d '/' -f 1)
REVISION=$(charmcraft status $CHARM_NAME --format json |
jq ".[] | select(.track == \"$TRACK\") | .mappings[0].releases[] | select(.channel == \"$CHANNEL\") | .revision")
echo "revision=$REVISION" >> "$GITHUB_OUTPUT"
set +e
juju status
juju debug-log -m controller --replay

- name: Release to edge
if: github.event_name == 'push' && needs.channel.outputs.release != ''
run: |
charmcraft release $CHARM_NAME \
--revision=${{ steps.revision.outputs.revision }} \
--channel=${{ needs.channel.outputs.release }}
# TODO: test integration with dashboard / ha-proxy
13 changes: 8 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# Development guide

You will need to have Python 3 and Charmcraft installed.
You will need to have Python 3, Charmcraft and [uv](https://docs.astral.sh/uv/) installed.
```
sudo snap install charmcraft --classic
sudo snap install astral-uv --classic
```

## Setting up the environment

Create and activate a virtualenv with the development requirements:

virtualenv -p python3 venv
source venv/bin/activate
pip install -r requirements-dev.txt
```
uv venv
source .venv/bin/activate
uv pip install ".[dev]"
```

## Testing

Expand Down Expand Up @@ -80,4 +83,4 @@ You can also do the upload and release in a single step if you'd like:
$ charmcraft upload *.charm --name juju-controller --release latest/stable --release 3.0/stable
Revision [XX] of 'juju-controller' created
Revision [XX] of charm 'juju-controller' released to latest/stable, 3.0/stable
```
```
49 changes: 19 additions & 30 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,22 @@
type: charm

parts:
charm:
charm-python-packages: [setuptools,markdown]
build-packages:
- cargo
bases:
- build-on:
- name: ubuntu
channel: "22.04"
architectures: ["amd64"]
run-on:
- name: ubuntu
channel: "24.04"
architectures:
- amd64
- arm64
- s390x
- ppc64el
- name: ubuntu
channel: "22.04"
architectures:
- amd64
- arm64
- s390x
- ppc64el
- name: ubuntu
channel: "20.04"
architectures:
- amd64
- arm64
- s390x
- ppc64el
plugin: uv
source: .
build-packages: [git]
build-snaps: [astral-uv]

platforms:
ubuntu@20.04:amd64:
ubuntu@20.04:arm64:
ubuntu@20.04:s390x:
ubuntu@20.04:ppc64el:
ubuntu@22.04:amd64:
ubuntu@22.04:arm64:
ubuntu@22.04:s390x:
ubuntu@22.04:ppc64el:
ubuntu@24.04:amd64:
ubuntu@24.04:arm64:
ubuntu@24.04:s390x:
ubuntu@24.04:ppc64el:
15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[project]
name = "juju-controller"
version = "0.1.0"
requires-python = ">=3.8"
dependencies = [
"ops",
"charmhelpers",
"cosl",
]

[project.optional-dependencies]
dev = [
"coverage",
"flake8",
]
4 changes: 0 additions & 4 deletions requirements-dev.txt

This file was deleted.

2 changes: 0 additions & 2 deletions requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion tests/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_metrics_endpoint_relation(self, mock_remove_user, mock_add_user,
"password": 'passwd',
},
"tls_config": {
"ca_file": 'fake',
"ca": 'fake',
"server_name": "juju-apiserver",
},
}],
Expand Down
Loading
Loading